Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions crates/core/common/src/catalog/physical/snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use amp_parquet::reader;
use datafusion::{
arrow::datatypes::SchemaRef,
catalog::{Session, memory::DataSourceExec},
common::{DFSchema, project_schema, stats::Precision},
common::{DFSchema, ScalarValue, project_schema, stats::Precision},
datasource::{
TableProvider, TableType, create_ordering,
listing::{ListingTableUrl, PartitionedFile},
Expand Down Expand Up @@ -342,9 +342,24 @@ impl TableProvider for QueryableSnapshot {

let target_partitions = state.config_options().execution.target_partitions;
let table_schema = self.physical_table.schema();
let (file_groups, statistics) = self
let (file_groups, mut statistics) = self
.resolve_file_groups(&segments, target_partitions, table_schema.clone())
.await?;

// Override _block_num column statistics with exact min/max from synced_range.
// This enables the AggregateStatistics optimizer to resolve MIN/MAX(_block_num)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems wrong, the start and end range of the synced segment are not necessarily represented as column values. E.g. the segment could have zero rows.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in #2047

// as constants without scanning parquet files.
if let Some(range) = &self.synced_range
&& let Ok(idx) =
table_schema.index_of(datasets_common::block_num::RESERVED_BLOCK_NUM_COLUMN_NAME)
{
statistics.column_statistics[idx].null_count = Precision::Exact(0);
statistics.column_statistics[idx].min_value =
Precision::Exact(ScalarValue::UInt64(Some(range.start())));
statistics.column_statistics[idx].max_value =
Precision::Exact(ScalarValue::UInt64(Some(range.end())));
}

if statistics.num_rows == Precision::Absent {
tracing::warn!("Table has no row count statistics. Queries may be inefficient.");
}
Expand Down
Loading