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 cfe07207 [core] Read single-run sections of partial-update tables 
without sort merge (#1377)
cfe07207 is described below

commit cfe07207557a9b63ed389520a5879cb655a02815
Author: JeonDaehong <[email protected]>
AuthorDate: Mon Nov 16 15:01:28 2026 +0900

    [core] Read single-run sections of partial-update tables without sort merge 
(#1377)
---
 crates/paimon/src/table/kv_file_reader.rs      | 33 ++++++++--
 crates/paimon/tests/pk_single_run_read_test.rs | 90 ++++++++++++++++++++++++++
 2 files changed, 119 insertions(+), 4 deletions(-)

diff --git a/crates/paimon/src/table/kv_file_reader.rs 
b/crates/paimon/src/table/kv_file_reader.rs
index 73b47031..ce59ed26 100644
--- a/crates/paimon/src/table/kv_file_reader.rs
+++ b/crates/paimon/src/table/kv_file_reader.rs
@@ -910,8 +910,9 @@ impl KeyValueFileReader {
                     let mut file_streams: Vec<ArrowRecordBatchStream> = 
Vec::new();
                     // One sorted run should not repeat a key, so under these
                     // engines every key is a lone version and needs no merge.
-                    // Aggregation returns a lone version as is too, unless the
-                    // lookup changelog producer makes it reduce singletons.
+                    // Aggregation and partial-update return a lone version as
+                    // is too, unless the lookup changelog producer makes them
+                    // reduce singletons.
                     // Retract rows are still dropped per batch below: older 
Rust
                     // writers recorded `delete_row_count = 0` for files 
holding
                     // them.
@@ -920,10 +921,9 @@ impl KeyValueFileReader {
                         && input_stream_count == 1
                         && match config.merge_engine {
                             MergeEngine::Deduplicate | MergeEngine::FirstRow 
=> true,
-                            MergeEngine::Aggregation => {
+                            MergeEngine::Aggregation | 
MergeEngine::PartialUpdate => {
                                 !reduces_singletons(&config.table_options)
                             }
-                            _ => false,
                         };
                     let reject_retracts = config.merge_engine == 
MergeEngine::FirstRow
                         && 
!CoreOptions::new(&config.table_options).ignore_delete();
@@ -3082,6 +3082,7 @@ mod tests {
                 Some(vec![1, 2]),
             ),
             (vec![("merge-engine", "aggregation")], Some(vec![1, 2])),
+            (vec![("merge-engine", "partial-update")], Some(vec![1, 2])),
         ] {
             let table_path = "memory:/kv_legacy_retract";
             let table = pk_table(&file_io, table_path, &options);
@@ -3300,6 +3301,30 @@ mod tests {
         assert_eq!(int_column(&batches, "value"), vec![21, 20]);
     }
 
+    #[tokio::test]
+    async fn single_run_read_merges_repeated_keys_under_partial_update() {
+        // A file from before #839 can repeat a key under partial-update.
+        let file_io = test_file_io();
+        let table_path = "memory:/kv_repeated_keys_partial_update";
+        let table = pk_table(&file_io, table_path, &[("merge-engine", 
"partial-update")]);
+        write_schema_file(&table, table.schema()).await;
+        let a =
+            write_kv_versions(&file_io, table_path, "a.parquet", &[(1, 0, 10), 
(1, 1, 11)]).await;
+        let b = write_kv_versions(&file_io, table_path, "b.parquet", &[(2, 2, 
20)]).await;
+        let split = DataSplitBuilder::new()
+            .with_snapshot(1)
+            .with_partition(BinaryRow::new(0))
+            .with_bucket(0)
+            .with_bucket_path(format!("{table_path}/bucket-0"))
+            .with_total_buckets(1)
+            .with_data_files(vec![a, b])
+            .build()
+            .unwrap();
+        let batches = read_kv_split(&table, split).await;
+        assert_eq!(int_column(&batches, "id"), vec![1, 2]);
+        assert_eq!(int_column(&batches, "value"), vec![11, 20]);
+    }
+
     #[tokio::test]
     async fn single_run_read_merges_repeated_keys_under_the_stored_engine() {
         // Before #839, copy_with_options could switch the writer to 
aggregation
diff --git a/crates/paimon/tests/pk_single_run_read_test.rs 
b/crates/paimon/tests/pk_single_run_read_test.rs
index f813c67b..ae1d9305 100644
--- a/crates/paimon/tests/pk_single_run_read_test.rs
+++ b/crates/paimon/tests/pk_single_run_read_test.rs
@@ -165,3 +165,93 @@ async fn 
aggregation_reads_disjoint_files_without_merge_and_overlaps_still_merge
         .collect();
     assert_eq!(read(&table, &["id", "v"], None).await, expected);
 }
+
+async fn write_nullable(table: &Table, columns: &[(&str, Vec<Option<i32>>)]) {
+    write_batch(
+        table,
+        &RecordBatch::try_from_iter(columns.iter().map(|(name, values)| {
+            (
+                *name,
+                Arc::new(Int32Array::from(values.clone())) as ArrayRef,
+            )
+        }))
+        .unwrap(),
+    )
+    .await;
+}
+
+#[tokio::test]
+async fn 
partial_update_reads_disjoint_files_without_merge_and_overlaps_still_merge() {
+    let table = pk_table_with(
+        "memory:/pk_single_run_read_partial_update",
+        &[("merge-engine", "partial-update")],
+    )
+    .await;
+    write(&table, 0..100, 1000).await;
+    write(&table, 100..200, 1000).await;
+    let expected: Vec<Vec<i32>> = (0..200).map(|id| vec![id, id + 
1000]).collect();
+    assert_eq!(read(&table, &["id", "v"], None).await, expected);
+
+    // An overlapping file with a null `v` makes a two-run section, which still
+    // merges and keeps the earlier `v`; a non-null `v` replaces it.
+    write_nullable(
+        &table,
+        &[
+            ("id", (150..160).map(Some).collect()),
+            (
+                "v",
+                (150..160)
+                    .map(|id| (id >= 155).then_some(id + 2000))
+                    .collect(),
+            ),
+        ],
+    )
+    .await;
+    let expected: Vec<Vec<i32>> = (0..200)
+        .map(|id| vec![id, id + if (155..160).contains(&id) { 2000 } else { 
1000 }])
+        .collect();
+    assert_eq!(read(&table, &["id", "v"], None).await, expected);
+}
+
+#[tokio::test]
+async fn 
partial_update_sequence_group_reads_single_runs_without_its_sequence_field() {
+    // `g` orders `v`, so a read of `id, v` also reads `g` and drops it again.
+    let path = "memory:/pk_single_run_read_sequence_group";
+    let schema = Schema::builder()
+        .column("id", DataType::Int(IntType::new()))
+        .column("v", DataType::Int(IntType::new()))
+        .column("g", DataType::Int(IntType::new()))
+        .primary_key(["id"])
+        .option("bucket", "1")
+        .option("merge-engine", "partial-update")
+        .option("fields.g.sequence-group", "v")
+        .build()
+        .unwrap();
+    let (io, table) = memory_table(path, TableSchema::new(0, &schema));
+    setup_dirs(&io, path).await;
+    persist_table_schema(&io, path, table.schema()).await;
+    let rows = |ids: std::ops::Range<i32>, v: i32, g: i32| {
+        [
+            ("id", ids.clone().map(Some).collect::<Vec<_>>()),
+            ("v", ids.clone().map(|id| Some(id + v)).collect()),
+            ("g", ids.map(|_| Some(g)).collect()),
+        ]
+    };
+    write_nullable(&table, &rows(0..100, 1000, 5)).await;
+    write_nullable(&table, &rows(100..200, 1000, 5)).await;
+    let expected: Vec<Vec<i32>> = (0..200).map(|id| vec![id, id + 
1000]).collect();
+    assert_eq!(read(&table, &["id", "v"], None).await, expected);
+    assert_eq!(
+        read(&table, &["v", "g"], None).await,
+        (0..200).map(|id| vec![id + 1000, 5]).collect::<Vec<_>>()
+    );
+
+    // Overlapping files still merge: an older `g` leaves `v` alone, a newer 
one
+    // replaces it.
+    write_nullable(&table, &rows(150..155, 2000, 4)).await;
+    write_nullable(&table, &rows(155..160, 3000, 6)).await;
+    let expected: Vec<Vec<i32>> = (0..200)
+        .map(|id| vec![id, id + if (155..160).contains(&id) { 3000 } else { 
1000 }])
+        .collect();
+    assert_eq!(read(&table, &["id", "v"], None).await, expected);
+}

Reply via email to