Skip to content

Commit 979056c

Browse files
committed
adding test
1 parent 764af66 commit 979056c

File tree

2 files changed

+116
-0
lines changed

2 files changed

+116
-0
lines changed

datafusion/core/tests/physical_optimizer/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,4 @@ mod projection_pushdown;
2828
mod replace_with_order_preserving_variants;
2929
mod sanity_checker;
3030
mod test_utils;
31+
mod partition_statistics;
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
#[cfg(test)]
19+
mod test {
20+
use std::sync::Arc;
21+
use datafusion::datasource::listing::{ListingOptions, ListingTable, ListingTableConfig};
22+
use datafusion::execution::SessionStateBuilder;
23+
use datafusion::prelude::SessionContext;
24+
use datafusion_catalog::TableProvider;
25+
use datafusion_common::config::ConfigOptions;
26+
use datafusion_datasource::ListingTableUrl;
27+
use datafusion_datasource::source::DataSourceExec;
28+
use datafusion_datasource_parquet::ParquetFormat;
29+
use datafusion_execution::config::SessionConfig;
30+
use datafusion_execution::runtime_env::RuntimeEnvBuilder;
31+
use datafusion_physical_plan::ExecutionPlan;
32+
33+
async fn generate_listing_table_with_statistics() -> Arc<dyn ExecutionPlan> {
34+
let testdata = datafusion::test_util::parquet_test_data();
35+
let filename = format!("{}/{}", testdata, "alltypes_tiny_pages.parquet");
36+
let table_path = ListingTableUrl::parse(filename).unwrap();
37+
let opt = ListingOptions::new(Arc::new(ParquetFormat::default())).with_collect_stat(true);
38+
let rt = RuntimeEnvBuilder::new()
39+
.build_arc()
40+
.expect("could not build runtime environment");
41+
42+
let state = SessionContext::new_with_config_rt(SessionConfig::default(), rt).state();
43+
let schema = opt
44+
.infer_schema(
45+
&SessionStateBuilder::new().with_default_features().build(),
46+
&table_path,
47+
)
48+
.await
49+
.unwrap();
50+
let config = ListingTableConfig::new(table_path.clone())
51+
.with_listing_options(opt.clone())
52+
.with_schema(schema);
53+
let table = ListingTable::try_new(config).unwrap();
54+
let res= table.scan(&state, None, &[], None).await.unwrap();
55+
dbg!(&res.statistics().unwrap());
56+
dbg!(&res.statistics_by_partition().unwrap());
57+
let mut config = ConfigOptions::new();
58+
config.set("datafusion.optimizer.repartition_file_min_size", "10").unwrap();
59+
let res = res.repartitioned(5, &config).unwrap().unwrap();
60+
dbg!(&res.statistics_by_partition().unwrap());
61+
res
62+
}
63+
64+
#[tokio::test]
65+
async fn test_statistics_by_partition_of_data_source() -> datafusion_common::Result<()> {
66+
generate_listing_table_with_statistics().await;
67+
Ok(())
68+
}
69+
70+
#[test]
71+
fn test_statistics_by_partition_of_projection() -> datafusion_common::Result<()> {
72+
Ok(())
73+
}
74+
75+
#[test]
76+
fn test_statistics_by_partition_of_sort() -> datafusion_common::Result<()> {
77+
Ok(())
78+
}
79+
80+
#[test]
81+
fn test_statistics_by_partition_of_filter() -> datafusion_common::Result<()> {
82+
Ok(())
83+
}
84+
85+
#[test]
86+
fn test_statistics_by_partition_of_aggregate() -> datafusion_common::Result<()> {
87+
Ok(())
88+
}
89+
90+
#[test]
91+
fn test_statistic_by_partition_of_cross_join() -> datafusion_common::Result<()> {
92+
Ok(())
93+
}
94+
95+
#[test]
96+
fn test_statistic_by_partition_of_union() -> datafusion_common::Result<()> {
97+
Ok(())
98+
}
99+
100+
#[test]
101+
fn test_statistic_by_partition_of_smp() -> datafusion_common::Result<()> {
102+
Ok(())
103+
}
104+
105+
#[test]
106+
fn test_statistic_by_partition_of_limit() -> datafusion_common::Result<()> {
107+
Ok(())
108+
}
109+
110+
#[test]
111+
fn test_statistic_by_partition_of_coalesce() -> datafusion_common::Result<()> {
112+
Ok(())
113+
}
114+
115+
}

0 commit comments

Comments
 (0)