JingsongLi commented on code in PR #8344:
URL: https://github.com/apache/paimon/pull/8344#discussion_r3471765582


##########
paimon-core/src/main/java/org/apache/paimon/table/system/TableIndexesTable.java:
##########
@@ -256,7 +257,8 @@ private InternalRow toRow(
                     indexManifestEntry.indexFile().rowCount(),
                     dvMetas == null
                             ? null
-                            : 
IndexFileMetaSerializer.dvMetasToRowArrayData(dvMetas.values()),
+                            : IndexFileMetaSerializer.metasToRowArrayData(
+                                    dvMetas, DeletionFileKey.Type.FILE_NAME),

Review Comment:
   For row-range keyed DVs this renders the compatibility marker row instead of 
the real row-id ranges, because metasToRowArrayData(..., FILE_NAME) 
intentionally fast-fails old readers. That makes table_indexes.dv_ranges 
misleading for data-evolution tables. Can we expose the row-range DV schema 
here as well, or render the ranges in a separate column, instead of showing the 
legacy marker?



##########
paimon-core/src/main/java/org/apache/paimon/deletionvectors/DataEvolutionApplyDvReader.java:
##########
@@ -0,0 +1,212 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.paimon.deletionvectors;
+
+import org.apache.paimon.data.InternalRow;
+import org.apache.paimon.fs.FileIO;
+import org.apache.paimon.reader.RecordReader;
+import org.apache.paimon.table.SpecialFields;
+import org.apache.paimon.table.source.DeletionFile;
+import org.apache.paimon.types.RowType;
+import org.apache.paimon.utils.ProjectedRow;
+import org.apache.paimon.utils.Range;
+
+import javax.annotation.Nullable;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * The RecordReader to apply deletion vectors for data evolution tables. At 
first, readType will be
+ * enriched by `_ROW_ID`, then the returned id will be filtered by DVs.
+ */
+public class DataEvolutionApplyDvReader implements RecordReader<InternalRow> {
+
+    private final RecordReader<InternalRow> reader;
+    private final List<RowRangeDeletionVector> deletionVectors;
+    @Nullable private final ProjectedRow projectedRow;
+    private final int rowIdIndex;
+
+    private int nextDvIndex;
+    private RowRangeDeletionVector currentDv;
+
+    public DataEvolutionApplyDvReader(RecordReader<InternalRow> reader, Info 
info) {
+        this.reader = reader;
+        this.deletionVectors = new ArrayList<>(info.deletionVectors);
+        this.deletionVectors.sort(Comparator.comparingLong(dv -> 
dv.range.from));
+        this.rowIdIndex = info.rowIdIndex;
+        this.projectedRow = info.projectedRow;
+
+        this.nextDvIndex = 1;
+        this.currentDv = deletionVectors.get(0);
+    }
+
+    @Nullable
+    @Override
+    public RecordIterator<InternalRow> readBatch() throws IOException {
+        RecordIterator<InternalRow> iterator = reader.readBatch();
+        if (iterator == null) {
+            return null;
+        }
+
+        return new RecordIterator<InternalRow>() {
+
+            @Nullable
+            @Override
+            public InternalRow next() throws IOException {
+                while (true) {
+                    InternalRow row = iterator.next();
+                    if (row == null) {
+                        return null;
+                    }
+
+                    if (!isDeleted(row)) {
+                        if (projectedRow != null) {
+                            return projectedRow.replaceRow(row);
+                        }
+                        return row;
+                    }
+                }
+            }
+
+            @Override
+            public void releaseBatch() {
+                iterator.releaseBatch();
+            }
+        };
+    }
+
+    private boolean isDeleted(InternalRow row) {
+        long rowId = row.getLong(rowIdIndex);
+
+        moveToPossibleDv(rowId);
+
+        if (currentDv == null || !currentDv.mayContains(rowId)) {
+            return false;
+        }
+
+        return currentDv.isDeleted(rowId);

Review Comment:
   This reader only evaluates the first row-range DV whose end has not passed 
the current row id. If two row-range keyed DVs overlap, for example [0, 10] and 
[5, 15], rows 5-10 are never checked against the second DV, so deletions 
recorded only there will be returned. I don't see the writer/manifest combiner 
rejecting overlapping RowIdRangeKey values; they only deduplicate exact keys. 
Please either enforce non-overlapping row-range DVs when writing/combining 
metadata, or make this reader evaluate all DVs that may contain the row.



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