JeonDaehong commented on code in PR #1164:
URL: https://github.com/apache/paimon-rust/pull/1164#discussion_r4400393634


##########
crates/paimon/src/table/kv_file_reader.rs:
##########
@@ -711,6 +761,56 @@ impl KeyValueFileReader {
                             .map(|budget| Arc::new(budget.without_prefetch()))
                     };
                     let mut file_streams: Vec<ArrowRecordBatchStream> = 
Vec::new();
+                    // One sorted run never repeats a key, so under these 
engines
+                    // every key is a lone version and needs no merge. Retract
+                    // rows are still dropped per batch below: older Rust 
writers
+                    // recorded `delete_row_count = 0` for files holding them.
+                    let mut skip_merge = skip_single_runs
+                        && input_stream_count == 1
+                        && matches!(
+                            config.merge_engine,
+                            MergeEngine::Deduplicate | MergeEngine::FirstRow
+                        );
+                    // A file written under another engine may hold several
+                    // versions of a key (the aggregation writer kept them 
before
+                    // #839), and ALTER can switch the engine afterwards.
+                    if skip_merge {
+                        'files: for run in &merge_group {
+                            for file in &run.files {
+                                // Always check the stored schema: dynamic 
options and
+                                // time travel can change the read schema's 
engine
+                                // without changing its ID. Merging is always 
correct,
+                                // so a missing schema file under the read 
schema's ID
+                                // only costs the skip.
+                                let schema = match config
+                                    .schema_manager
+                                    .schema(file.file.schema_id)
+                                    .await
+                                {
+                                    Ok(schema) => schema,
+                                    Err(crate::Error::IoUnexpected { source, 
.. })
+                                        if source.kind() == 
opendal::ErrorKind::NotFound
+                                            && file.file.schema_id == 
table_schema_id =>
+                                    {
+                                        skip_merge = false;
+                                        break 'files;
+                                    }
+                                    Err(err) => Err(err)?,
+                                };
+                                let engine =

Review Comment:
   right, neither schema can say which engine wrote a file, so I dropped the 
schema lookup. the unmerged path now holds one batch back and compares adjacent 
keys, and at the first repeated key it hands that batch and the rest of the run 
to the sort merge (af7ae3c). that covers the write-side override you described 
as well as the read-side cases.
   
   tests: a deduplicate schema whose file repeats a key, and a key repeated 
across a batch boundary after earlier rows already went out (one-row batches). 
with the check turned off all five single_run_read_merges tests fail. the check 
is cheap: 2M rows in four disjoint files read in 18 ms vs 102 ms on main (4 
rounds alternating, ranges don't overlap).
   



-- 
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]

Reply via email to