alexanderbianchi commented on code in PR #137:
URL: 
https://github.com/apache/datafusion-iceberg/pull/137#discussion_r4660664249


##########
crates/datafusion/src/read/file_scan_task_provider/eager.rs:
##########
@@ -129,9 +133,20 @@ impl FileScanTaskProvider for EagerFileScanTaskProvider {
     }
 }
 
+/// Whether `task` reads a whole file with no row predicate and no deletes, so 
it
+/// returns exactly its record count.
+fn returns_every_record(task: &FileScanTask) -> bool {

Review Comment:
   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.
   
   - **Spark + Iceberg Java:** For an eligible `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](https://github.com/apache/iceberg/blob/main/spark/v4.1/spark/src/main/java/org/apache/iceberg/spark/source/SparkScanBuilder.java#L146-L176)
 · [Java delete 
index](https://github.com/apache/iceberg/blob/main/core/src/main/java/org/apache/iceberg/DeleteFileIndex.java#L151-L166)
   - **Trino:** It keeps the aggregate in the plan. For a whole-file split with 
no residual filter or deletes, `COUNT(*)` 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](https://github.com/trinodb/trino/blob/master/plugin/trino-iceberg/src/main/java/io/trino/plugin/iceberg/IcebergPageSourceProvider.java#L397-L492)



##########
crates/datafusion/tests/statistics.rs:
##########
@@ -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(*)]

Review Comment:
   Could we add a test for the inexact case that shows the full plan as well? 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to