JingsongLi commented on code in PR #1164:
URL: https://github.com/apache/paimon-rust/pull/1164#discussion_r4386106715
##########
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:
[P2] Do not treat the stored engine as writer provenance
A persisted deduplicate schema can still own legacy files written with
aggregation. Before #839, public `Table::copy_with_options` allowed
`merge-engine=aggregation` plus `fields.value.aggregate-function=sum` without
changing the schema ID; `TableWrite` passed that overridden engine and original
ID to a writer whose aggregation flush retained every same-key version. This
check reads only the stored deduplicate engine and enables the shortcut for
those files. I reproduced the legitimate historical layout through public
commit/scan/read APIs: one two-file non-raw split contains (1,seq0,10),
(1,seq1,11) and disjoint key 2. This head emits both key-1 rows; exact base
370428b0 returns only (1,11). The aggregation control correctly returns (1,21).
Please retain duplicate collapsing for legacy files lacking a durable
uniqueness guarantee; schema options alone cannot establish which dynamic write
options produced them. Cover the historical write-side override as well as the
existing read-
side override cases.
--
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]