Repository navigation
feat: report exact row counts for eager scans with no predicates or deletes #137
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Richard-Durkee
wants to merge
1
commit into
apache:main
Choose a base branch
from
Richard-Durkee:exact-eager-row-counts
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+140
−10
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,9 +17,13 @@ | |
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use std::sync::Arc; | ||
|
|
||
| use datafusion::error::Result; | ||
| use iceberg_datafusion::{IcebergDataFusionConfig, IcebergTableProviderFactory}; | ||
| use iceberg_datafusion_test_tools::{IcebergTestHarness, create_taxi_table}; | ||
| use iceberg_datafusion_test_tools::{ | ||
| IcebergTestHarness, ReadCountingStorageFactory, create_taxi_table, | ||
| }; | ||
|
|
||
| #[tokio::test] | ||
| async fn reports_the_snapshot_row_count_to_datafusion() -> Result<()> { | ||
|
|
@@ -78,4 +82,51 @@ mod tests { | |
| "); | ||
| Ok(()) | ||
| } | ||
|
|
||
| #[tokio::test] | ||
| async fn eager_count_star_is_answered_without_reading_data_files() -> Result<()> { | ||
| let storage = ReadCountingStorageFactory::default(); | ||
| let harness = IcebergTestHarness::builder() | ||
| .with_iceberg_table_factory( | ||
| IcebergTableProviderFactory::new_with_storage_factory(Arc::new( | ||
| storage.clone(), | ||
| )), | ||
| ) | ||
| .with_table(create_taxi_table().await?) | ||
| .with_session_extension(|mut state| { | ||
| state | ||
| .config() | ||
| .get_or_insert_default() | ||
| .options_mut() | ||
| .extensions | ||
| .insert(IcebergDataFusionConfig::default()); | ||
| state | ||
| }) | ||
| .with_config_option("iceberg.execution.eager_file_planning", true) | ||
| .with_config_option("datafusion.execution.target_partitions", 2) | ||
| .build() | ||
| .await?; | ||
|
|
||
| // Taxi has seven daily files of 25,000 rows and no deletes. | ||
| let (plan, _) = harness.query("SELECT count(*) FROM taxi").await?; | ||
| insta::assert_snapshot!(plan, @" | ||
| ProjectionExec: expr=[175000 as count(*)] | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we add a test for the inexact case that shows the full plan as well? |
||
| PlaceholderRowExec | ||
| "); | ||
| assert_eq!(storage.take_reads(), 0); | ||
|
|
||
| // A pushed-down predicate may drop rows, so the files are still read. | ||
| let (_, rows) = harness | ||
| .query("SELECT count(*) FROM taxi WHERE pickup_date = DATE '2024-01-10'") | ||
| .await?; | ||
| insta::assert_snapshot!(rows, @" | ||
| +----------+ | ||
| | count(*) | | ||
| +----------+ | ||
| | 25000 | | ||
| +----------+ | ||
| "); | ||
| assert_ne!(storage.take_reads(), 0); | ||
| Ok(()) | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I checked if we could potentially use delete metadata do cover more cases, but it'd go beyond what other engines do. Makes sense to stick with this.
COUNT(*), Spark evaluates the aggregate from Iceberg file metrics and returns a local result. If any planned task has an attached delete, it declines the pushdown for the whole aggregate. That includes both v2 position deletes and v3 deletion vectors. Spark scan builder · Java delete indexCOUNT(*)needs no data columns, so Trino can synthesize pages from the manifest’s row count. If a split has v2 position deletes or a v3 DV, it takes the regular reader path and applies the deletes. That decision is per split, so eligible clean files can still take the shortcut in the same query. Trino page source