This is an automated email from the ASF dual-hosted git repository.
JingsongLi pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/paimon-rust.git
The following commit(s) were added to refs/heads/main by this push:
new 17cf9bb1 fix(datafusion): do not push a partition COUNT down under an
incremental window (#1418)
17cf9bb1 is described below
commit 17cf9bb1875aca6f21d54ca79508985c7cf91e0c
Author: jackylee <[email protected]>
AuthorDate: Tue Nov 17 10:41:12 2026 +0800
fix(datafusion): do not push a partition COUNT down under an incremental
window (#1418)
---
.../datafusion/src/partition_count_pushdown.rs | 9 +++-
.../datafusion/tests/partition_count_pushdown.rs | 62 ++++++++++++++++++++++
crates/paimon/src/spec/core_options.rs | 6 ++-
3 files changed, 74 insertions(+), 3 deletions(-)
diff --git a/crates/integrations/datafusion/src/partition_count_pushdown.rs
b/crates/integrations/datafusion/src/partition_count_pushdown.rs
index 3a1f90f6..828ab5c7 100644
--- a/crates/integrations/datafusion/src/partition_count_pushdown.rs
+++ b/crates/integrations/datafusion/src/partition_count_pushdown.rs
@@ -134,9 +134,14 @@ fn rewrite_aggregate(aggregate: &Aggregate) ->
DFResult<Option<LogicalPlan>> {
let table = paimon.table();
let table_schema = table.schema();
// Manifest row counts of a primary-key table are physical: several
versions
- // of a key count separately until they are merged at read time.
- if CoreOptions::new(table_schema.options()).is_format_table()
+ // of a key count separately until they are merged at read time. A table
that
+ // sets an incremental window reads that window's changes rather than the
+ // table state the manifests describe, and an invalid window must still
+ // surface when the table is read.
+ let core_options = CoreOptions::new(table_schema.options());
+ if core_options.is_format_table()
|| !table_schema.primary_keys().is_empty()
+ || !matches!(core_options.incremental_timestamp_window(), Ok(None))
{
return Ok(None);
}
diff --git a/crates/integrations/datafusion/tests/partition_count_pushdown.rs
b/crates/integrations/datafusion/tests/partition_count_pushdown.rs
index 0684a6bd..6974b19a 100644
--- a/crates/integrations/datafusion/tests/partition_count_pushdown.rs
+++ b/crates/integrations/datafusion/tests/partition_count_pushdown.rs
@@ -986,3 +986,65 @@ async fn
test_unknown_cardinality_falls_back_before_data_manifests() {
assert_eq!(rows(&ctx, aliased).await, vec![row("unknown", 1)]);
assert_eq!(warnings().len(), 2);
}
+
+/// A table that stores or is given `incremental-between-timestamp` reads the
+/// changes of the window, not its partitions' manifest totals, so a count
over it
+/// must read the same rows the scan returns.
+#[tokio::test]
+async fn
test_count_of_an_incremental_window_counts_the_rows_the_window_reads() {
+ let (_tmp, catalog, ctx) = setup().await;
+ exec(
+ &ctx,
+ "CREATE TABLE paimon.test_db.w (id INT NOT NULL, dt STRING)
PARTITIONED BY (dt)",
+ )
+ .await;
+ exec(
+ &ctx,
+ "INSERT INTO paimon.test_db.w VALUES (1, 'a'), (2, 'a')",
+ )
+ .await;
+ let table = catalog
+ .get_table(&Identifier::new("test_db", "w"))
+ .await
+ .unwrap();
+ let snapshots = SnapshotManager::new(table.file_io().clone(),
table.location().to_string());
+ let before = snapshots.get_latest_snapshot().await.unwrap().unwrap();
+ tokio::time::sleep(std::time::Duration::from_millis(20)).await;
+ exec(&ctx, "INSERT INTO paimon.test_db.w VALUES (3, 'b')").await;
+ let after = snapshots.get_latest_snapshot().await.unwrap().unwrap();
+ assert!(after.time_millis() > before.time_millis());
+ let window = format!("{},{}", before.time_millis(), after.time_millis());
+
+ let grouped = "SELECT dt, COUNT(*) FROM paimon.test_db.w GROUP BY dt";
+ let total = "SELECT COUNT(*) FROM paimon.test_db.w";
+ // Without a window the manifests answer both counts.
+ assert!(!scans_table(&ctx, grouped).await);
+ assert_eq!(rows(&ctx, grouped).await, vec![row("a", 2), row("b", 1)]);
+ assert_eq!(rows(&ctx, total).await, vec![row("", 3)]);
+
+ // Set for the session.
+ exec(
+ &ctx,
+ &format!("SET 'paimon.incremental-between-timestamp' = '{window}'"),
+ )
+ .await;
+ assert!(scans_table(&ctx, grouped).await);
+ assert_eq!(rows(&ctx, grouped).await, vec![row("b", 1)]);
+ assert_eq!(rows(&ctx, total).await, vec![row("", 1)]);
+ exec(&ctx, "RESET 'paimon.incremental-between-timestamp'").await;
+ assert!(!scans_table(&ctx, grouped).await);
+ assert_eq!(rows(&ctx, total).await, vec![row("", 3)]);
+
+ // Stored in the table's options.
+ exec(
+ &ctx,
+ &format!(
+ "ALTER TABLE paimon.test_db.w SET TBLPROPERTIES \
+ ('incremental-between-timestamp' = '{window}')"
+ ),
+ )
+ .await;
+ assert!(scans_table(&ctx, grouped).await);
+ assert_eq!(rows(&ctx, grouped).await, vec![row("b", 1)]);
+ assert_eq!(rows(&ctx, total).await, vec![row("", 1)]);
+}
diff --git a/crates/paimon/src/spec/core_options.rs
b/crates/paimon/src/spec/core_options.rs
index ee8f42c7..f59c1d7f 100644
--- a/crates/paimon/src/spec/core_options.rs
+++ b/crates/paimon/src/spec/core_options.rs
@@ -652,7 +652,11 @@ impl<'a> CoreOptions<'a> {
/// The numeric timestamp window supported by PyPaimon. Snapshot resolution
/// and ordering checks belong to the batch scanner, as in Java.
- pub(crate) fn incremental_timestamp_window(&self) ->
crate::Result<Option<(i64, i64)>> {
+ ///
+ /// A table that sets it reads the changes of the window, not its current
+ /// state, so engines must not answer a read of such a table from table
+ /// metadata alone.
+ pub fn incremental_timestamp_window(&self) -> crate::Result<Option<(i64,
i64)>> {
let Some(raw) = self.options.get(INCREMENTAL_BETWEEN_TIMESTAMP_OPTION)
else {
return Ok(None);
};