jerry-024 commented on code in PR #249:
URL: https://github.com/apache/paimon-rust/pull/249#discussion_r3090625099


##########
crates/paimon/src/table/table_read.rs:
##########
@@ -76,17 +77,37 @@ impl<'a> TableRead<'a> {
         let deletion_vectors_enabled = core_options.deletion_vectors_enabled();
         let data_evolution = core_options.data_evolution_enabled();
 
+        // PK table without DV: route by merge engine.
+        // Exhaustive match ensures new MergeEngine variants trigger a compile 
error.
         if has_primary_keys && !deletion_vectors_enabled {
-            return Err(Error::Unsupported {
-                message: format!(
-                    "Reading primary-key tables without deletion vectors is 
not yet supported. Primary keys: {:?}",
-                    self.table.schema.primary_keys()
-                ),
-            });
+            match core_options.merge_engine()? {
+                crate::spec::MergeEngine::Deduplicate => {
+                    let reader = KeyValueFileReader::new(
+                        self.table.file_io.clone(),
+                        KeyValueReadConfig {
+                            schema_manager: 
self.table.schema_manager().clone(),
+                            table_schema_id: self.table.schema().id(),
+                            table_fields: self.table.schema.fields().to_vec(),
+                            read_type: self.read_type().to_vec(),
+                            predicates: self.data_predicates.clone(),
+                            primary_keys: 
self.table.schema.primary_keys().to_vec(),
+                            sequence_fields: core_options
+                                .sequence_fields()
+                                .iter()
+                                .map(|s| s.to_string())
+                                .collect(),
+                        },
+                    );
+                    return reader.read(data_splits);
+                }
+                crate::spec::MergeEngine::FirstRow => {
+                    // Fall through to DataFileReader — scan already skips 
level-0

Review Comment:
   `MergeEngine::FirstRow` still falls back to `DataFileReader` here, so the 
new support only works because `TableScan` hides level-0 files. That means 
fresh first-row writes remain invisible until compaction, which makes the 
latest snapshot incomplete rather than actually implementing first-row read 
semantics. If we want to stay behavior-compatible with the Java API, I think 
this constraint should be made explicit and tested. In Java, the analogous 
behavior is scoped to `DataTableBatchScan` as a batch-scan policy; it is not a 
general first-row merge reader implementation.



##########
crates/paimon/src/table/table_scan.rs:
##########
@@ -461,6 +461,21 @@ impl<'a> TableScan<'a> {
         let deletion_vectors_enabled = core_options.deletion_vectors_enabled();
         let data_evolution_enabled = core_options.data_evolution_enabled();
 
+        let has_primary_keys = !self.table.schema().primary_keys().is_empty();
+
+        // Skip level-0 files for PK tables when:
+        // - DV mode: level-0 files are unmerged, DV handles dedup at higher 
levels
+        // - FirstRow engine without DV: reads go through DataFileReader (no 
merge),
+        //   so only compacted (level > 0) files are safe to read directly
+        let skip_level_zero = if has_primary_keys {

Review Comment:
   This looks broader than the Java implementation. In Java, level-0 skipping 
is kept inside `DataTableBatchScan`, while non-read paths still use the full 
file set: overwrite scanning goes through `CommitScanner.readOverwriteChanges`, 
and writer restore computes max sequence from all restored files in 
`AbstractFileStoreWrite.createWriterContainer`. Here `skip_level_zero` is 
pushed into the shared manifest-planning path, so overwrite / truncate and 
`TableWrite::scan_partition_sequence_numbers` also stop seeing live level-0 
files. That changes behavior relative to the Java API and can lead to missed 
deletes or sequence-number bootstrap from an incomplete state for first-row / 
DV tables.



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