@@ -32,6 +32,7 @@ use datafusion_catalog::TableProvider;
32
32
use datafusion_common:: { config_err, DataFusionError , Result } ;
33
33
use datafusion_datasource:: file_scan_config:: { FileScanConfig , FileScanConfigBuilder } ;
34
34
use datafusion_datasource:: schema_adapter:: DefaultSchemaAdapterFactory ;
35
+ use datafusion_execution:: config:: SessionConfig ;
35
36
use datafusion_expr:: dml:: InsertOp ;
36
37
use datafusion_expr:: { Expr , TableProviderFilterPushDown } ;
37
38
use datafusion_expr:: { SortExpr , TableType } ;
@@ -195,7 +196,8 @@ impl ListingTableConfig {
195
196
196
197
let listing_options = ListingOptions :: new ( file_format)
197
198
. with_file_extension ( listing_file_extension)
198
- . with_target_partitions ( state. config ( ) . target_partitions ( ) ) ;
199
+ . with_target_partitions ( state. config ( ) . target_partitions ( ) )
200
+ . with_collect_stat ( state. config ( ) . collect_statistics ( ) ) ;
199
201
200
202
Ok ( Self {
201
203
table_paths : self . table_paths ,
@@ -313,18 +315,29 @@ impl ListingOptions {
313
315
/// - use default file extension filter
314
316
/// - no input partition to discover
315
317
/// - one target partition
316
- /// - stat collection
318
+ /// - do not collect statistics
317
319
pub fn new ( format : Arc < dyn FileFormat > ) -> Self {
318
320
Self {
319
321
file_extension : format. get_ext ( ) ,
320
322
format,
321
323
table_partition_cols : vec ! [ ] ,
322
- collect_stat : true ,
324
+ collect_stat : false ,
323
325
target_partitions : 1 ,
324
326
file_sort_order : vec ! [ ] ,
325
327
}
326
328
}
327
329
330
+ /// Set options from [`SessionConfig`] and returns self.
331
+ ///
332
+ /// Currently this sets `target_partitions` and `collect_stat`
333
+ /// but if more options are added in the future that need to be coordinated
334
+ /// they will be synchronized thorugh this method.
335
+ pub fn with_session_config_options ( mut self , config : & SessionConfig ) -> Self {
336
+ self = self . with_target_partitions ( config. target_partitions ( ) ) ;
337
+ self = self . with_collect_stat ( config. collect_statistics ( ) ) ;
338
+ self
339
+ }
340
+
328
341
/// Set file extension on [`ListingOptions`] and returns self.
329
342
///
330
343
/// # Example
@@ -1282,7 +1295,9 @@ mod tests {
1282
1295
1283
1296
#[ tokio:: test]
1284
1297
async fn read_single_file ( ) -> Result < ( ) > {
1285
- let ctx = SessionContext :: new ( ) ;
1298
+ let ctx = SessionContext :: new_with_config (
1299
+ SessionConfig :: new ( ) . with_collect_statistics ( true ) ,
1300
+ ) ;
1286
1301
1287
1302
let table = load_table ( & ctx, "alltypes_plain.parquet" ) . await ?;
1288
1303
let projection = None ;
@@ -1309,7 +1324,7 @@ mod tests {
1309
1324
1310
1325
#[ cfg( feature = "parquet" ) ]
1311
1326
#[ tokio:: test]
1312
- async fn load_table_stats_by_default ( ) -> Result < ( ) > {
1327
+ async fn do_not_load_table_stats_by_default ( ) -> Result < ( ) > {
1313
1328
use crate :: datasource:: file_format:: parquet:: ParquetFormat ;
1314
1329
1315
1330
let testdata = crate :: test_util:: parquet_test_data ( ) ;
@@ -1321,6 +1336,22 @@ mod tests {
1321
1336
1322
1337
let opt = ListingOptions :: new ( Arc :: new ( ParquetFormat :: default ( ) ) ) ;
1323
1338
let schema = opt. infer_schema ( & state, & table_path) . await ?;
1339
+ let config = ListingTableConfig :: new ( table_path. clone ( ) )
1340
+ . with_listing_options ( opt)
1341
+ . with_schema ( schema) ;
1342
+ let table = ListingTable :: try_new ( config) ?;
1343
+
1344
+ let exec = table. scan ( & state, None , & [ ] , None ) . await ?;
1345
+ assert_eq ! ( exec. partition_statistics( None ) ?. num_rows, Precision :: Absent ) ;
1346
+ // TODO correct byte size: https://github.com/apache/datafusion/issues/14936
1347
+ assert_eq ! (
1348
+ exec. partition_statistics( None ) ?. total_byte_size,
1349
+ Precision :: Absent
1350
+ ) ;
1351
+
1352
+ let opt = ListingOptions :: new ( Arc :: new ( ParquetFormat :: default ( ) ) )
1353
+ . with_collect_stat ( true ) ;
1354
+ let schema = opt. infer_schema ( & state, & table_path) . await ?;
1324
1355
let config = ListingTableConfig :: new ( table_path)
1325
1356
. with_listing_options ( opt)
1326
1357
. with_schema ( schema) ;
0 commit comments