You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@iceberg.apache.org by GitBox <gi...@apache.org> on 2021/03/11 07:28:14 UTC

[GitHub] [iceberg] chenjunjiedada opened a new pull request #2320: Core: add delete row reader

chenjunjiedada opened a new pull request #2320:
URL: https://github.com/apache/iceberg/pull/2320


   This adds a row reader to read matched delete row for spark side. The next is to implement the reader in other engines.


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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


[GitHub] [iceberg] chenjunjiedada commented on a change in pull request #2320: Core: add delete row reader

Posted by GitBox <gi...@apache.org>.
chenjunjiedada commented on a change in pull request #2320:
URL: https://github.com/apache/iceberg/pull/2320#discussion_r592941019



##########
File path: spark/src/main/java/org/apache/iceberg/spark/source/DeleteRowReader.java
##########
@@ -0,0 +1,83 @@
+/*
+ * 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.iceberg.spark.source;
+
+import java.util.Map;
+import org.apache.iceberg.CombinedScanTask;
+import org.apache.iceberg.DataFile;
+import org.apache.iceberg.FileScanTask;
+import org.apache.iceberg.Schema;
+import org.apache.iceberg.StructLike;
+import org.apache.iceberg.data.DeleteFilter;
+import org.apache.iceberg.encryption.EncryptionManager;
+import org.apache.iceberg.io.CloseableIterator;
+import org.apache.iceberg.io.FileIO;
+import org.apache.iceberg.io.InputFile;
+import org.apache.iceberg.spark.SparkSchemaUtil;
+import org.apache.iceberg.util.PartitionUtil;
+import org.apache.spark.rdd.InputFileBlockHolder;
+import org.apache.spark.sql.catalyst.InternalRow;
+
+public class DeleteRowReader extends RowDataReader {
+  private final Schema tableSchema;
+  private final Schema expectedSchema;
+
+  public DeleteRowReader(CombinedScanTask task, Schema schema, Schema expectedSchema, String nameMapping,
+                         FileIO io, EncryptionManager encryptionManager, boolean caseSensitive) {
+    super(task, schema, schema, nameMapping, io, encryptionManager,
+        caseSensitive);
+    this.tableSchema = schema;
+    this.expectedSchema = expectedSchema;
+  }
+
+  @Override
+  CloseableIterator<InternalRow> open(FileScanTask task) {
+    SparkDeleteMatcher matches = new SparkDeleteMatcher(task, tableSchema, expectedSchema);
+
+    // schema or rows returned by readers
+    Schema requiredSchema = matches.requiredSchema();
+    Map<Integer, ?> idToConstant = PartitionUtil.constantsMap(task, RowDataReader::convertConstant);
+    DataFile file = task.file();
+
+    // update the current file for Spark's filename() function
+    InputFileBlockHolder.set(file.path().toString(), task.start(), task.length());
+
+    return matches.matchEqDeletes(open(task, requiredSchema, idToConstant)).iterator();
+  }
+
+  protected class SparkDeleteMatcher extends DeleteFilter<InternalRow> {

Review comment:
       Correct.




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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


[GitHub] [iceberg] rdblue commented on a change in pull request #2320: Core: add delete row reader

Posted by GitBox <gi...@apache.org>.
rdblue commented on a change in pull request #2320:
URL: https://github.com/apache/iceberg/pull/2320#discussion_r599992004



##########
File path: data/src/main/java/org/apache/iceberg/data/DeleteFilter.java
##########
@@ -137,11 +139,43 @@ protected long pos(T record) {
           CloseableIterable.transform(CloseableIterable.concat(deleteRecords), Record::copy),
           deleteSchema.asStruct());
 
-      filteredRecords = Deletes.filter(filteredRecords,
-          record -> projectRow.wrap(asStructLike(record)), deleteSet);
+      Predicate<T> isInDeleteSet = record -> deleteSet.contains(projectRow.wrap(asStructLike(record)));
+      isInDeleteSets.add(isInDeleteSet);

Review comment:
       Why doesn't this return a single predicate, `isDeleted`? Both `findEqualityDeleteRows` and `applyEqDeletes` end up producing a Predicate that determines whether a row is deleted. The only difference is that `deletedRows` and `remainingRows` are negations of each other. But those methods could just as easily use `isDeleted` and negate in `shouldKeep`.




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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


[GitHub] [iceberg] openinx commented on pull request #2320: Core: add delete row reader

Posted by GitBox <gi...@apache.org>.
openinx commented on pull request #2320:
URL: https://github.com/apache/iceberg/pull/2320#issuecomment-797852850


   Got this merged,  Thanks @chenjunjiedada for contributing ! 


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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


[GitHub] [iceberg] chenjunjiedada commented on a change in pull request #2320: Core: add delete row reader

Posted by GitBox <gi...@apache.org>.
chenjunjiedada commented on a change in pull request #2320:
URL: https://github.com/apache/iceberg/pull/2320#discussion_r592946315



##########
File path: spark/src/test/java/org/apache/iceberg/spark/source/TestSparkReaderDeletes.java
##########
@@ -159,4 +168,72 @@ public void testEqualityDeleteWithFilter() throws IOException {
 
     Assert.assertEquals("Table should contain no rows", 0, actual.size());
   }
+
+  @Test
+  public void testReadDeleteRow() throws IOException {

Review comment:
       Make sense to me. I plan to add an abstract function to read delete rows and that should be implemented in the engine specific test classes. While the engine specific read logic is not ready, I think we can refactor when those are ready.




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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


[GitHub] [iceberg] openinx commented on a change in pull request #2320: Core: add delete row reader

Posted by GitBox <gi...@apache.org>.
openinx commented on a change in pull request #2320:
URL: https://github.com/apache/iceberg/pull/2320#discussion_r592180361



##########
File path: data/src/main/java/org/apache/iceberg/data/DeleteFilter.java
##########
@@ -110,6 +113,41 @@ protected long pos(T record) {
     return applyEqDeletes(applyPosDeletes(records));
   }
 
+  public CloseableIterable<T> matchEqDeletes(CloseableIterable<T> records) {
+    if (eqDeletes.isEmpty()) {
+      return records;
+    }
+
+    Multimap<Set<Integer>, DeleteFile> filesByDeleteIds = Multimaps.newMultimap(Maps.newHashMap(), Lists::newArrayList);
+    for (DeleteFile delete : eqDeletes) {
+      filesByDeleteIds.put(Sets.newHashSet(delete.equalityFieldIds()), delete);
+    }
+
+    List<Predicate<T>> deleteSetFilters = Lists.newArrayList();
+    for (Map.Entry<Set<Integer>, Collection<DeleteFile>> entry : filesByDeleteIds.asMap().entrySet()) {
+      Set<Integer> ids = entry.getKey();
+      Iterable<DeleteFile> deletes = entry.getValue();
+
+      Schema deleteSchema = TypeUtil.select(requiredSchema, ids);
+
+      // a projection to select and reorder fields of the file schema to match the delete rows
+      StructProjection projectRow = StructProjection.create(requiredSchema, deleteSchema);
+
+      Iterable<CloseableIterable<Record>> deleteRecords = Iterables.transform(deletes,
+          delete -> openDeletes(delete, deleteSchema));
+      StructLikeSet deleteSet = Deletes.toEqualitySet(
+          // copy the delete records because they will be held in a set
+          CloseableIterable.transform(CloseableIterable.concat(deleteRecords), Record::copy),
+          deleteSchema.asStruct());
+
+      Predicate<T> predicate = record -> deleteSet.contains(projectRow.wrap(asStructLike(record)));
+      deleteSetFilters.add(predicate);
+    }

Review comment:
       If we plan to apply the above patch ,  the `EqualitySetDeleteFilter` could also be removed.




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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


[GitHub] [iceberg] openinx commented on a change in pull request #2320: Core: add delete row reader

Posted by GitBox <gi...@apache.org>.
openinx commented on a change in pull request #2320:
URL: https://github.com/apache/iceberg/pull/2320#discussion_r592177385



##########
File path: data/src/main/java/org/apache/iceberg/data/DeleteFilter.java
##########
@@ -110,6 +113,41 @@ protected long pos(T record) {
     return applyEqDeletes(applyPosDeletes(records));
   }
 
+  public CloseableIterable<T> matchEqDeletes(CloseableIterable<T> records) {
+    if (eqDeletes.isEmpty()) {
+      return records;
+    }
+
+    Multimap<Set<Integer>, DeleteFile> filesByDeleteIds = Multimaps.newMultimap(Maps.newHashMap(), Lists::newArrayList);
+    for (DeleteFile delete : eqDeletes) {
+      filesByDeleteIds.put(Sets.newHashSet(delete.equalityFieldIds()), delete);
+    }
+
+    List<Predicate<T>> deleteSetFilters = Lists.newArrayList();
+    for (Map.Entry<Set<Integer>, Collection<DeleteFile>> entry : filesByDeleteIds.asMap().entrySet()) {
+      Set<Integer> ids = entry.getKey();
+      Iterable<DeleteFile> deletes = entry.getValue();
+
+      Schema deleteSchema = TypeUtil.select(requiredSchema, ids);
+
+      // a projection to select and reorder fields of the file schema to match the delete rows
+      StructProjection projectRow = StructProjection.create(requiredSchema, deleteSchema);
+
+      Iterable<CloseableIterable<Record>> deleteRecords = Iterables.transform(deletes,
+          delete -> openDeletes(delete, deleteSchema));
+      StructLikeSet deleteSet = Deletes.toEqualitySet(
+          // copy the delete records because they will be held in a set
+          CloseableIterable.transform(CloseableIterable.concat(deleteRecords), Record::copy),
+          deleteSchema.asStruct());
+
+      Predicate<T> predicate = record -> deleteSet.contains(projectRow.wrap(asStructLike(record)));
+      deleteSetFilters.add(predicate);
+    }

Review comment:
       I saw almost all of the code are the same between the `matchEqDeletes` and `applyEqDeletes`,  actually the similar code are generating the `Predicate` that whether a row is in one of the equality deletion set.  So I think we could get them into one method to generate those `Predicates` .   The `matchEqDeletes` is actually finding out all the rows that has been deleted by equality deletes,  we could use the  `inDeleteSet1 OR inDeleteSet2 OR inDeleteSet3` to find out the expected rows;  the `appyEqDeletes` is actually finding out all the rows that should be visible users after applying equality deletions,  we could use the `NOT inDeleteSet1 AND NOT inDeleteSet2 AND NOT inDeleteSet3` to find out the visible rows.  I tried to make patch for this: 
   
   ```diff
   From cbdc488d96d1ee3e51f019898db27c73846c46bb Mon Sep 17 00:00:00 2001
   From: huzheng <op...@gmail.com>
   Date: Thu, 11 Mar 2021 16:55:20 +0800
   Subject: [PATCH] Reuse the codes
   
   ---
    .../apache/iceberg/util/ChainedFilter.java    | 42 ----------
    .../org/apache/iceberg/data/DeleteFilter.java | 77 ++++++++++---------
    .../iceberg/spark/source/DeleteRowReader.java |  2 +-
    3 files changed, 40 insertions(+), 81 deletions(-)
    delete mode 100644 core/src/main/java/org/apache/iceberg/util/ChainedFilter.java
   
   diff --git a/core/src/main/java/org/apache/iceberg/util/ChainedFilter.java b/core/src/main/java/org/apache/iceberg/util/ChainedFilter.java
   deleted file mode 100644
   index a2a26c366..000000000
   --- a/core/src/main/java/org/apache/iceberg/util/ChainedFilter.java
   +++ /dev/null
   @@ -1,42 +0,0 @@
   -/*
   - * 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.iceberg.util;
   -
   -import java.util.List;
   -import java.util.function.Predicate;
   -
   -public class ChainedFilter<T> extends Filter<T> {
   -  private final List<Predicate<T>> filters;
   -
   -  public ChainedFilter(List<Predicate<T>> filters) {
   -    this.filters = filters;
   -  }
   -
   -  @Override
   -  protected boolean shouldKeep(T item) {
   -    for (Predicate<T> filter : filters) {
   -      if (filter.test(item)) {
   -        return true;
   -      }
   -    }
   -
   -    return false;
   -  }
   -}
   diff --git a/data/src/main/java/org/apache/iceberg/data/DeleteFilter.java b/data/src/main/java/org/apache/iceberg/data/DeleteFilter.java
   index 285195cb6..201fb20ee 100644
   --- a/data/src/main/java/org/apache/iceberg/data/DeleteFilter.java
   +++ b/data/src/main/java/org/apache/iceberg/data/DeleteFilter.java
   @@ -49,7 +49,6 @@ import org.apache.iceberg.relocated.com.google.common.collect.Multimaps;
    import org.apache.iceberg.relocated.com.google.common.collect.Sets;
    import org.apache.iceberg.types.TypeUtil;
    import org.apache.iceberg.types.Types;
   -import org.apache.iceberg.util.ChainedFilter;
    import org.apache.iceberg.util.Filter;
    import org.apache.iceberg.util.StructLikeSet;
    import org.apache.iceberg.util.StructProjection;
   @@ -113,44 +112,30 @@ public abstract class DeleteFilter<T> {
        return applyEqDeletes(applyPosDeletes(records));
      }
    
   -  public CloseableIterable<T> matchEqDeletes(CloseableIterable<T> records) {
   -    if (eqDeletes.isEmpty()) {
   -      return records;
   -    }
   -
   -    Multimap<Set<Integer>, DeleteFile> filesByDeleteIds = Multimaps.newMultimap(Maps.newHashMap(), Lists::newArrayList);
   -    for (DeleteFile delete : eqDeletes) {
   -      filesByDeleteIds.put(Sets.newHashSet(delete.equalityFieldIds()), delete);
   -    }
   -
   -    List<Predicate<T>> deleteSetFilters = Lists.newArrayList();
   -    for (Map.Entry<Set<Integer>, Collection<DeleteFile>> entry : filesByDeleteIds.asMap().entrySet()) {
   -      Set<Integer> ids = entry.getKey();
   -      Iterable<DeleteFile> deletes = entry.getValue();
   -
   -      Schema deleteSchema = TypeUtil.select(requiredSchema, ids);
   -
   -      // a projection to select and reorder fields of the file schema to match the delete rows
   -      StructProjection projectRow = StructProjection.create(requiredSchema, deleteSchema);
   +  public CloseableIterable<T> findEqualityDeleteRows(CloseableIterable<T> records) {
   +    // Predicate to test whether a row has been deleted by equality deletions.
   +    Predicate<T> deletedRows = applyEqDeletes().stream()
   +        .reduce(Predicate::or)
   +        .orElse(t -> false);
    
   -      Iterable<CloseableIterable<Record>> deleteRecords = Iterables.transform(deletes,
   -          delete -> openDeletes(delete, deleteSchema));
   -      StructLikeSet deleteSet = Deletes.toEqualitySet(
   -          // copy the delete records because they will be held in a set
   -          CloseableIterable.transform(CloseableIterable.concat(deleteRecords), Record::copy),
   -          deleteSchema.asStruct());
   -
   -      Predicate<T> predicate = record -> deleteSet.contains(projectRow.wrap(asStructLike(record)));
   -      deleteSetFilters.add(predicate);
   -    }
   +    Filter<T> deletedRowsFilter = new Filter<T>() {
   +      @Override
   +      protected boolean shouldKeep(T item) {
   +        return deletedRows.test(item);
   +      }
   +    };
    
   -    Filter<T> findDeleteRows = new ChainedFilter<>(deleteSetFilters);
   -    return findDeleteRows.filter(records);
   +    return deletedRowsFilter.filter(records);
      }
    
   -  private CloseableIterable<T> applyEqDeletes(CloseableIterable<T> records) {
   +  /**
   +   * Returns a list of {@link Predicate}s, and each {@link Predicate} indicate whether a row is in an equality delete
   +   * set.
   +   */
   +  private List<Predicate<T>> applyEqDeletes() {
   +    List<Predicate<T>> isInDeleteSets = Lists.newArrayList();
        if (eqDeletes.isEmpty()) {
   -      return records;
   +      return isInDeleteSets;
        }
    
        Multimap<Set<Integer>, DeleteFile> filesByDeleteIds = Multimaps.newMultimap(Maps.newHashMap(), Lists::newArrayList);
   @@ -158,7 +143,6 @@ public abstract class DeleteFilter<T> {
          filesByDeleteIds.put(Sets.newHashSet(delete.equalityFieldIds()), delete);
        }
    
   -    CloseableIterable<T> filteredRecords = records;
        for (Map.Entry<Set<Integer>, Collection<DeleteFile>> entry : filesByDeleteIds.asMap().entrySet()) {
          Set<Integer> ids = entry.getKey();
          Iterable<DeleteFile> deletes = entry.getValue();
   @@ -175,11 +159,28 @@ public abstract class DeleteFilter<T> {
              CloseableIterable.transform(CloseableIterable.concat(deleteRecords), Record::copy),
              deleteSchema.asStruct());
    
   -      filteredRecords = Deletes.filter(filteredRecords,
   -          record -> projectRow.wrap(asStructLike(record)), deleteSet);
   +      Predicate<T> isInDeleteSet = record -> deleteSet.contains(projectRow.wrap(asStructLike(record)));
   +      isInDeleteSets.add(isInDeleteSet);
        }
    
   -    return filteredRecords;
   +    return isInDeleteSets;
   +  }
   +
   +  private CloseableIterable<T> applyEqDeletes(CloseableIterable<T> records) {
   +    // Predicate to test whether a row should be visible to user after applying equality deletions.
   +    Predicate<T> remainingRows = applyEqDeletes().stream()
   +        .map(Predicate::negate)
   +        .reduce(Predicate::and)
   +        .orElse(t -> true);
   +
   +    Filter<T> remainingRowsFilter = new Filter<T>() {
   +      @Override
   +      protected boolean shouldKeep(T item) {
   +        return remainingRows.test(item);
   +      }
   +    };
   +
   +    return remainingRowsFilter.filter(records);
      }
    
      private CloseableIterable<T> applyPosDeletes(CloseableIterable<T> records) {
   diff --git a/spark/src/main/java/org/apache/iceberg/spark/source/DeleteRowReader.java b/spark/src/main/java/org/apache/iceberg/spark/source/DeleteRowReader.java
   index d8dc55266..5c4311a33 100644
   --- a/spark/src/main/java/org/apache/iceberg/spark/source/DeleteRowReader.java
   +++ b/spark/src/main/java/org/apache/iceberg/spark/source/DeleteRowReader.java
   @@ -59,7 +59,7 @@ public class DeleteRowReader extends RowDataReader {
        // update the current file for Spark's filename() function
        InputFileBlockHolder.set(file.path().toString(), task.start(), task.length());
    
   -    return matches.matchEqDeletes(open(task, requiredSchema, idToConstant)).iterator();
   +    return matches.findEqualityDeleteRows(open(task, requiredSchema, idToConstant)).iterator();
      }
    
      protected class SparkDeleteMatcher extends DeleteFilter<InternalRow> {
   -- 
   2.20.1 (Apple Git-117)
   ```




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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


[GitHub] [iceberg] openinx commented on a change in pull request #2320: Core: add delete row reader

Posted by GitBox <gi...@apache.org>.
openinx commented on a change in pull request #2320:
URL: https://github.com/apache/iceberg/pull/2320#discussion_r592181986



##########
File path: core/src/main/java/org/apache/iceberg/util/ChainedFilter.java
##########
@@ -0,0 +1,42 @@
+/*
+ * 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.iceberg.util;
+
+import java.util.List;
+import java.util.function.Predicate;
+
+public class ChainedFilter<T> extends Filter<T> {
+  private final List<Predicate<T>> filters;
+
+  public ChainedFilter(List<Predicate<T>> filters) {
+    this.filters = filters;
+  }
+
+  @Override
+  protected boolean shouldKeep(T item) {
+    for (Predicate<T> filter : filters) {
+      if (filter.test(item)) {

Review comment:
       I'm hesitating to introduce this `ChainedFilter` now  because it is actually concatting the sub-Predicates with `OR` logic,  which means it's only suitable for a specific case. 




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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


[GitHub] [iceberg] rdblue commented on a change in pull request #2320: Core: add delete row reader

Posted by GitBox <gi...@apache.org>.
rdblue commented on a change in pull request #2320:
URL: https://github.com/apache/iceberg/pull/2320#discussion_r599990685



##########
File path: data/src/main/java/org/apache/iceberg/data/DeleteFilter.java
##########
@@ -110,17 +112,17 @@ protected long pos(T record) {
     return applyEqDeletes(applyPosDeletes(records));
   }
 
-  private CloseableIterable<T> applyEqDeletes(CloseableIterable<T> records) {
+  private List<Predicate<T>> applyEqDeletes() {

Review comment:
       Looks like this wasn't renamed. It doesn't apply equality deletes, so I'd rather use a more descriptive name, like `buildEqDeletePredicates`.




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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


[GitHub] [iceberg] rdblue commented on pull request #2320: Core: add delete row reader

Posted by GitBox <gi...@apache.org>.
rdblue commented on pull request #2320:
URL: https://github.com/apache/iceberg/pull/2320#issuecomment-805305805


   @chenjunjiedada and @openinx, thanks for making progress on this! I wanted to catch up on what's happening in this area so I went ahead and did a round of review as well. I think there are a few minor things to improve in a follow-up.
   
   I'm also wondering about why this is only focused on equality deletes. Why not return all deleted rows? Is that because we only want equality deletes where this is used?


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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


[GitHub] [iceberg] rdblue commented on a change in pull request #2320: Core: add delete row reader

Posted by GitBox <gi...@apache.org>.
rdblue commented on a change in pull request #2320:
URL: https://github.com/apache/iceberg/pull/2320#discussion_r599988193



##########
File path: data/src/main/java/org/apache/iceberg/data/DeleteFilter.java
##########
@@ -137,11 +139,43 @@ protected long pos(T record) {
           CloseableIterable.transform(CloseableIterable.concat(deleteRecords), Record::copy),
           deleteSchema.asStruct());
 
-      filteredRecords = Deletes.filter(filteredRecords,
-          record -> projectRow.wrap(asStructLike(record)), deleteSet);
+      Predicate<T> isInDeleteSet = record -> deleteSet.contains(projectRow.wrap(asStructLike(record)));
+      isInDeleteSets.add(isInDeleteSet);
     }
 
-    return filteredRecords;
+    return isInDeleteSets;
+  }
+
+  public CloseableIterable<T> findEqualityDeleteRows(CloseableIterable<T> records) {

Review comment:
       Does this method need to be public? I'm surprised that it is given that `applyEqDeletes` is not.
   
   I also think it would be good to have a better name for it, if it does need to be public. This is really just applying a filter, so I think something like `keepDeletedRows` would be more descriptive.




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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


[GitHub] [iceberg] chenjunjiedada commented on pull request #2320: Core: add delete row reader

Posted by GitBox <gi...@apache.org>.
chenjunjiedada commented on pull request #2320:
URL: https://github.com/apache/iceberg/pull/2320#issuecomment-805414851


   Thanks @rdblue! I will update your comment in the following PR.
   
   The reason for reading deleted rows only from equality deletes is that we want to handle equality delete and position delete separately since the filtering logic and cost are different between equality delete and position delete. So that we could choose proper rewrite actions when streaming the CDC data. I'm also working on position deletes rewrite action to clustering the position deletes inside the partition, which would include a position delete row reader. Does this make sense to you?
   
   These two actions are minor compactions and @openinx have a PR that remove all delete rows which I think is major compaction. 


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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


[GitHub] [iceberg] rdblue commented on a change in pull request #2320: Core: add delete row reader

Posted by GitBox <gi...@apache.org>.
rdblue commented on a change in pull request #2320:
URL: https://github.com/apache/iceberg/pull/2320#discussion_r599992402



##########
File path: data/src/main/java/org/apache/iceberg/data/DeleteFilter.java
##########
@@ -137,11 +139,43 @@ protected long pos(T record) {
           CloseableIterable.transform(CloseableIterable.concat(deleteRecords), Record::copy),
           deleteSchema.asStruct());
 
-      filteredRecords = Deletes.filter(filteredRecords,
-          record -> projectRow.wrap(asStructLike(record)), deleteSet);
+      Predicate<T> isInDeleteSet = record -> deleteSet.contains(projectRow.wrap(asStructLike(record)));
+      isInDeleteSets.add(isInDeleteSet);
     }
 
-    return filteredRecords;
+    return isInDeleteSets;
+  }
+
+  public CloseableIterable<T> findEqualityDeleteRows(CloseableIterable<T> records) {
+    // Predicate to test whether a row has been deleted by equality deletions.
+    Predicate<T> deletedRows = applyEqDeletes().stream()
+        .reduce(Predicate::or)
+        .orElse(t -> false);
+
+    Filter<T> deletedRowsFilter = new Filter<T>() {
+      @Override
+      protected boolean shouldKeep(T item) {
+        return deletedRows.test(item);
+      }
+    };
+    return deletedRowsFilter.filter(records);
+  }
+
+  private CloseableIterable<T> applyEqDeletes(CloseableIterable<T> records) {
+    // Predicate to test whether a row should be visible to user after applying equality deletions.
+    Predicate<T> remainingRows = applyEqDeletes().stream()

Review comment:
       If there are no delete predicates, then this should return the original iterable.




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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


[GitHub] [iceberg] openinx commented on a change in pull request #2320: Core: add delete row reader

Posted by GitBox <gi...@apache.org>.
openinx commented on a change in pull request #2320:
URL: https://github.com/apache/iceberg/pull/2320#discussion_r592186514



##########
File path: spark/src/main/java/org/apache/iceberg/spark/source/DeleteRowReader.java
##########
@@ -0,0 +1,83 @@
+/*
+ * 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.iceberg.spark.source;
+
+import java.util.Map;
+import org.apache.iceberg.CombinedScanTask;
+import org.apache.iceberg.DataFile;
+import org.apache.iceberg.FileScanTask;
+import org.apache.iceberg.Schema;
+import org.apache.iceberg.StructLike;
+import org.apache.iceberg.data.DeleteFilter;
+import org.apache.iceberg.encryption.EncryptionManager;
+import org.apache.iceberg.io.CloseableIterator;
+import org.apache.iceberg.io.FileIO;
+import org.apache.iceberg.io.InputFile;
+import org.apache.iceberg.spark.SparkSchemaUtil;
+import org.apache.iceberg.util.PartitionUtil;
+import org.apache.spark.rdd.InputFileBlockHolder;
+import org.apache.spark.sql.catalyst.InternalRow;
+
+public class DeleteRowReader extends RowDataReader {
+  private final Schema tableSchema;
+  private final Schema expectedSchema;
+
+  public DeleteRowReader(CombinedScanTask task, Schema schema, Schema expectedSchema, String nameMapping,
+                         FileIO io, EncryptionManager encryptionManager, boolean caseSensitive) {
+    super(task, schema, schema, nameMapping, io, encryptionManager,
+        caseSensitive);
+    this.tableSchema = schema;
+    this.expectedSchema = expectedSchema;
+  }
+
+  @Override
+  CloseableIterator<InternalRow> open(FileScanTask task) {
+    SparkDeleteMatcher matches = new SparkDeleteMatcher(task, tableSchema, expectedSchema);
+
+    // schema or rows returned by readers
+    Schema requiredSchema = matches.requiredSchema();
+    Map<Integer, ?> idToConstant = PartitionUtil.constantsMap(task, RowDataReader::convertConstant);
+    DataFile file = task.file();
+
+    // update the current file for Spark's filename() function
+    InputFileBlockHolder.set(file.path().toString(), task.start(), task.length());
+
+    return matches.matchEqDeletes(open(task, requiredSchema, idToConstant)).iterator();
+  }
+
+  protected class SparkDeleteMatcher extends DeleteFilter<InternalRow> {

Review comment:
       We actually could share the same `DeleteFilter` for spark engine ?  Don't have to introduce the same `SparkDeleteFilter` for both `RowDataReader` and `DeleteRowReader`




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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


[GitHub] [iceberg] rdblue commented on a change in pull request #2320: Core: add delete row reader

Posted by GitBox <gi...@apache.org>.
rdblue commented on a change in pull request #2320:
URL: https://github.com/apache/iceberg/pull/2320#discussion_r599994857



##########
File path: data/src/test/java/org/apache/iceberg/data/DeleteReadTests.java
##########
@@ -328,4 +328,13 @@ private StructLikeSet rowSetWithoutIds(int... idsToRemove) {
         .forEach(set::add);
     return set;
   }
+
+  protected StructLikeSet rowSetWitIds(int... idsToRetain) {

Review comment:
       Typo: should be `rowSetWithIds`




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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


[GitHub] [iceberg] openinx commented on a change in pull request #2320: Core: add delete row reader

Posted by GitBox <gi...@apache.org>.
openinx commented on a change in pull request #2320:
URL: https://github.com/apache/iceberg/pull/2320#discussion_r592193876



##########
File path: spark/src/test/java/org/apache/iceberg/spark/source/TestSparkReaderDeletes.java
##########
@@ -159,4 +168,72 @@ public void testEqualityDeleteWithFilter() throws IOException {
 
     Assert.assertEquals("Table should contain no rows", 0, actual.size());
   }
+
+  @Test
+  public void testReadDeleteRow() throws IOException {
+    String tableName = "testDeleteRowRead";

Review comment:
       I think we need an unit test to cover the case that have multiple version of equality delete schema to verify that the Predicates concatted by OR is working as expected.




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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


[GitHub] [iceberg] openinx commented on a change in pull request #2320: Core: add delete row reader

Posted by GitBox <gi...@apache.org>.
openinx commented on a change in pull request #2320:
URL: https://github.com/apache/iceberg/pull/2320#discussion_r592184670



##########
File path: spark/src/main/java/org/apache/iceberg/spark/source/DeleteRowReader.java
##########
@@ -0,0 +1,83 @@
+/*
+ * 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.iceberg.spark.source;
+
+import java.util.Map;
+import org.apache.iceberg.CombinedScanTask;
+import org.apache.iceberg.DataFile;
+import org.apache.iceberg.FileScanTask;
+import org.apache.iceberg.Schema;
+import org.apache.iceberg.StructLike;
+import org.apache.iceberg.data.DeleteFilter;
+import org.apache.iceberg.encryption.EncryptionManager;
+import org.apache.iceberg.io.CloseableIterator;
+import org.apache.iceberg.io.FileIO;
+import org.apache.iceberg.io.InputFile;
+import org.apache.iceberg.spark.SparkSchemaUtil;
+import org.apache.iceberg.util.PartitionUtil;
+import org.apache.spark.rdd.InputFileBlockHolder;
+import org.apache.spark.sql.catalyst.InternalRow;
+
+public class DeleteRowReader extends RowDataReader {
+  private final Schema tableSchema;
+  private final Schema expectedSchema;
+
+  public DeleteRowReader(CombinedScanTask task, Schema schema, Schema expectedSchema, String nameMapping,
+                         FileIO io, EncryptionManager encryptionManager, boolean caseSensitive) {
+    super(task, schema, schema, nameMapping, io, encryptionManager,
+        caseSensitive);

Review comment:
       Nit:  don't have to start a newline.




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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


[GitHub] [iceberg] chenjunjiedada commented on a change in pull request #2320: Core: add delete row reader

Posted by GitBox <gi...@apache.org>.
chenjunjiedada commented on a change in pull request #2320:
URL: https://github.com/apache/iceberg/pull/2320#discussion_r592940864



##########
File path: data/src/main/java/org/apache/iceberg/data/DeleteFilter.java
##########
@@ -110,6 +113,41 @@ protected long pos(T record) {
     return applyEqDeletes(applyPosDeletes(records));
   }
 
+  public CloseableIterable<T> matchEqDeletes(CloseableIterable<T> records) {
+    if (eqDeletes.isEmpty()) {
+      return records;
+    }
+
+    Multimap<Set<Integer>, DeleteFile> filesByDeleteIds = Multimaps.newMultimap(Maps.newHashMap(), Lists::newArrayList);
+    for (DeleteFile delete : eqDeletes) {
+      filesByDeleteIds.put(Sets.newHashSet(delete.equalityFieldIds()), delete);
+    }
+
+    List<Predicate<T>> deleteSetFilters = Lists.newArrayList();
+    for (Map.Entry<Set<Integer>, Collection<DeleteFile>> entry : filesByDeleteIds.asMap().entrySet()) {
+      Set<Integer> ids = entry.getKey();
+      Iterable<DeleteFile> deletes = entry.getValue();
+
+      Schema deleteSchema = TypeUtil.select(requiredSchema, ids);
+
+      // a projection to select and reorder fields of the file schema to match the delete rows
+      StructProjection projectRow = StructProjection.create(requiredSchema, deleteSchema);
+
+      Iterable<CloseableIterable<Record>> deleteRecords = Iterables.transform(deletes,
+          delete -> openDeletes(delete, deleteSchema));
+      StructLikeSet deleteSet = Deletes.toEqualitySet(
+          // copy the delete records because they will be held in a set
+          CloseableIterable.transform(CloseableIterable.concat(deleteRecords), Record::copy),
+          deleteSchema.asStruct());
+
+      Predicate<T> predicate = record -> deleteSet.contains(projectRow.wrap(asStructLike(record)));
+      deleteSetFilters.add(predicate);
+    }

Review comment:
       The patch looks great! I applied it.




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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


[GitHub] [iceberg] chenjunjiedada commented on a change in pull request #2320: Core: add delete row reader

Posted by GitBox <gi...@apache.org>.
chenjunjiedada commented on a change in pull request #2320:
URL: https://github.com/apache/iceberg/pull/2320#discussion_r592191700



##########
File path: spark/src/main/java/org/apache/iceberg/spark/source/DeleteRowReader.java
##########
@@ -0,0 +1,83 @@
+/*
+ * 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.iceberg.spark.source;
+
+import java.util.Map;
+import org.apache.iceberg.CombinedScanTask;
+import org.apache.iceberg.DataFile;
+import org.apache.iceberg.FileScanTask;
+import org.apache.iceberg.Schema;
+import org.apache.iceberg.StructLike;
+import org.apache.iceberg.data.DeleteFilter;
+import org.apache.iceberg.encryption.EncryptionManager;
+import org.apache.iceberg.io.CloseableIterator;
+import org.apache.iceberg.io.FileIO;
+import org.apache.iceberg.io.InputFile;
+import org.apache.iceberg.spark.SparkSchemaUtil;
+import org.apache.iceberg.util.PartitionUtil;
+import org.apache.spark.rdd.InputFileBlockHolder;
+import org.apache.spark.sql.catalyst.InternalRow;
+
+public class DeleteRowReader extends RowDataReader {

Review comment:
       Agreed.




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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


[GitHub] [iceberg] rdblue commented on a change in pull request #2320: Core: add delete row reader

Posted by GitBox <gi...@apache.org>.
rdblue commented on a change in pull request #2320:
URL: https://github.com/apache/iceberg/pull/2320#discussion_r599992514



##########
File path: data/src/main/java/org/apache/iceberg/data/DeleteFilter.java
##########
@@ -137,11 +139,43 @@ protected long pos(T record) {
           CloseableIterable.transform(CloseableIterable.concat(deleteRecords), Record::copy),
           deleteSchema.asStruct());
 
-      filteredRecords = Deletes.filter(filteredRecords,
-          record -> projectRow.wrap(asStructLike(record)), deleteSet);
+      Predicate<T> isInDeleteSet = record -> deleteSet.contains(projectRow.wrap(asStructLike(record)));
+      isInDeleteSets.add(isInDeleteSet);
     }
 
-    return filteredRecords;
+    return isInDeleteSets;
+  }
+
+  public CloseableIterable<T> findEqualityDeleteRows(CloseableIterable<T> records) {
+    // Predicate to test whether a row has been deleted by equality deletions.
+    Predicate<T> deletedRows = applyEqDeletes().stream()
+        .reduce(Predicate::or)
+        .orElse(t -> false);
+
+    Filter<T> deletedRowsFilter = new Filter<T>() {
+      @Override
+      protected boolean shouldKeep(T item) {
+        return deletedRows.test(item);
+      }
+    };
+    return deletedRowsFilter.filter(records);

Review comment:
       If there are no delete predicates, this should return `CloseableIterable.empty`.




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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


[GitHub] [iceberg] openinx commented on a change in pull request #2320: Core: add delete row reader

Posted by GitBox <gi...@apache.org>.
openinx commented on a change in pull request #2320:
URL: https://github.com/apache/iceberg/pull/2320#discussion_r592200925



##########
File path: spark/src/test/java/org/apache/iceberg/spark/source/TestSparkReaderDeletes.java
##########
@@ -159,4 +168,72 @@ public void testEqualityDeleteWithFilter() throws IOException {
 
     Assert.assertEquals("Table should contain no rows", 0, actual.size());
   }
+
+  @Test
+  public void testReadDeleteRow() throws IOException {

Review comment:
       Another point, I think we'd better to move those newly added unit tests to the abstracted `DeleteReadTests` as possible as we can.  Then we don't have to introduce this test again for other engines.




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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


[GitHub] [iceberg] openinx merged pull request #2320: Core: add delete row reader

Posted by GitBox <gi...@apache.org>.
openinx merged pull request #2320:
URL: https://github.com/apache/iceberg/pull/2320


   


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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


[GitHub] [iceberg] openinx commented on a change in pull request #2320: Core: add delete row reader

Posted by GitBox <gi...@apache.org>.
openinx commented on a change in pull request #2320:
URL: https://github.com/apache/iceberg/pull/2320#discussion_r592953890



##########
File path: spark/src/main/java/org/apache/iceberg/spark/source/EqualityDeleteRowReader.java
##########
@@ -0,0 +1,59 @@
+/*
+ * 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.iceberg.spark.source;
+
+import java.util.Map;
+import org.apache.iceberg.CombinedScanTask;
+import org.apache.iceberg.DataFile;
+import org.apache.iceberg.FileScanTask;
+import org.apache.iceberg.Schema;
+import org.apache.iceberg.encryption.EncryptionManager;
+import org.apache.iceberg.io.CloseableIterator;
+import org.apache.iceberg.io.FileIO;
+import org.apache.iceberg.util.PartitionUtil;
+import org.apache.spark.rdd.InputFileBlockHolder;
+import org.apache.spark.sql.catalyst.InternalRow;
+
+public class EqualityDeleteRowReader extends RowDataReader {
+  private final Schema tableSchema;
+  private final Schema expectedSchema;
+
+  public EqualityDeleteRowReader(CombinedScanTask task, Schema schema, Schema expectedSchema, String nameMapping,
+                                 FileIO io, EncryptionManager encryptionManager, boolean caseSensitive) {
+    super(task, schema, schema, nameMapping, io, encryptionManager, caseSensitive);
+    this.tableSchema = schema;

Review comment:
       Nit:   this `tableSchema` is actually defined in its parent class `RowDataReader`, right ?   we usually introduce a `protected tableSchema()` method in `RowDataReader` to access the schema , rather than defining an extra private member in sub-class.




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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


[GitHub] [iceberg] chenjunjiedada commented on pull request #2320: Core: add delete row reader

Posted by GitBox <gi...@apache.org>.
chenjunjiedada commented on pull request #2320:
URL: https://github.com/apache/iceberg/pull/2320#issuecomment-805826984


   @rdblue , Most of the comments are addressed in https://github.com/apache/iceberg/pull/2372.


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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


[GitHub] [iceberg] openinx commented on a change in pull request #2320: Core: add delete row reader

Posted by GitBox <gi...@apache.org>.
openinx commented on a change in pull request #2320:
URL: https://github.com/apache/iceberg/pull/2320#discussion_r592184232



##########
File path: spark/src/main/java/org/apache/iceberg/spark/source/DeleteRowReader.java
##########
@@ -0,0 +1,83 @@
+/*
+ * 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.iceberg.spark.source;
+
+import java.util.Map;
+import org.apache.iceberg.CombinedScanTask;
+import org.apache.iceberg.DataFile;
+import org.apache.iceberg.FileScanTask;
+import org.apache.iceberg.Schema;
+import org.apache.iceberg.StructLike;
+import org.apache.iceberg.data.DeleteFilter;
+import org.apache.iceberg.encryption.EncryptionManager;
+import org.apache.iceberg.io.CloseableIterator;
+import org.apache.iceberg.io.FileIO;
+import org.apache.iceberg.io.InputFile;
+import org.apache.iceberg.spark.SparkSchemaUtil;
+import org.apache.iceberg.util.PartitionUtil;
+import org.apache.spark.rdd.InputFileBlockHolder;
+import org.apache.spark.sql.catalyst.InternalRow;
+
+public class DeleteRowReader extends RowDataReader {

Review comment:
       To be more precise,  this reader will find all rows that has been deleted by equality deletions.  How about using the `EqualityDeleteRowReader` as the class name ?




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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org