MCPcopy Create free account
hub / github.com/apache/datafusion / get_statistics_with_limit

Function get_statistics_with_limit

datafusion/datasource/src/statistics.rs:371–451  ·  view source on GitHub ↗
(
    all_files: impl Stream<Item = Result<(PartitionedFile, Arc<Statistics>)>>,
    file_schema: SchemaRef,
    limit: Option<usize>,
    collect_stats: bool,
)

Source from the content-addressed store, hash-verified

369)]
370#[cfg_attr(not(test), expect(unused))]
371pub async fn get_statistics_with_limit(
372 all_files: impl Stream<Item = Result<(PartitionedFile, Arc<Statistics>)>>,
373 file_schema: SchemaRef,
374 limit: Option<usize>,
375 collect_stats: bool,
376) -> Result<(FileGroup, Statistics)> {
377 let mut result_files = FileGroup::default();
378 // These statistics can be calculated as long as at least one file provides
379 // useful information. If none of the files provides any information, then
380 // they will end up having `Precision::Absent` values. Throughout calculations,
381 // missing values will be imputed as:
382 // - zero for summations, and
383 // - neutral element for extreme points.
384 let size = file_schema.fields().len();
385 let mut summary_statistics = Statistics {
386 num_rows: Precision::Absent,
387 total_byte_size: Precision::Absent,
388 column_statistics: vec![ColumnStatistics::default(); size],
389 };
390 // Keep limit pruning separate from the returned summary so `collect_stats=false`
391 // can still stop early using known file row counts.
392 let mut limit_num_rows = Precision::<usize>::Absent;
393
394 // Fusing the stream allows us to call next safely even once it is finished.
395 let mut all_files = Box::pin(all_files.fuse());
396
397 if let Some(first_file) = all_files.next().await {
398 let (mut file, file_stats) = first_file?;
399 file.statistics = Some(Arc::clone(&file_stats));
400 result_files.push(file);
401
402 seed_first_file_statistics(
403 &mut limit_num_rows,
404 &mut summary_statistics,
405 &file_stats,
406 collect_stats,
407 );
408
409 // If the number of rows exceeds the limit, we can stop processing
410 // files. This only applies when we know the number of rows. It also
411 // currently ignores tables that have no statistics regarding the
412 // number of rows.
413 let conservative_num_rows = match limit_num_rows {
414 Precision::Exact(nr) => nr,
415 _ => usize::MIN,
416 };
417 if conservative_num_rows <= limit.unwrap_or(usize::MAX) {
418 while let Some(current) = all_files.next().await {
419 let (mut file, file_stats) = current?;
420 file.statistics = Some(Arc::clone(&file_stats));
421 result_files.push(file);
422 merge_file_statistics(
423 &mut limit_num_rows,
424 &mut summary_statistics,
425 &file_stats,
426 collect_stats,
427 );
428

Calls 8

merge_file_statisticsFunction · 0.85
to_inexactMethod · 0.80
lenMethod · 0.45
fieldsMethod · 0.45
nextMethod · 0.45
pushMethod · 0.45
get_valueMethod · 0.45

Used in the wild real call sites across dependent graphs

searching dependent graphs…