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 2020/08/06 19:41:23 UTC

[GitHub] [iceberg] aokolnychyi commented on a change in pull request #1301: Add position delete filter and utils

aokolnychyi commented on a change in pull request #1301:
URL: https://github.com/apache/iceberg/pull/1301#discussion_r466621353



##########
File path: core/src/main/java/org/apache/iceberg/deletes/Deletes.java
##########
@@ -0,0 +1,159 @@
+/*
+ * 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.deletes;
+
+import java.io.IOException;
+import java.io.UncheckedIOException;
+import java.util.Comparator;
+import java.util.List;
+import java.util.function.Function;
+import org.apache.iceberg.Accessor;
+import org.apache.iceberg.Schema;
+import org.apache.iceberg.StructLike;
+import org.apache.iceberg.io.CloseableGroup;
+import org.apache.iceberg.io.CloseableIterable;
+import org.apache.iceberg.io.CloseableIterator;
+import org.apache.iceberg.relocated.com.google.common.collect.ImmutableList;
+import org.apache.iceberg.relocated.com.google.common.collect.Lists;
+import org.apache.iceberg.types.Comparators;
+import org.apache.iceberg.types.Types;
+import org.apache.iceberg.util.Filter;
+import org.apache.iceberg.util.FilterIterator;
+import org.apache.iceberg.util.SortedMerge;
+
+public class Deletes {
+  private static final Schema POSITION_DELETE_SCHEMA = new Schema(
+      Types.NestedField.required(1, "filename", Types.StringType.get(), "Data file location of the deleted row"),

Review comment:
       Why `filename` and not `file_path` like we use for `DataFile`?

##########
File path: core/src/main/java/org/apache/iceberg/deletes/Deletes.java
##########
@@ -0,0 +1,159 @@
+/*
+ * 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.deletes;
+
+import java.io.IOException;
+import java.io.UncheckedIOException;
+import java.util.Comparator;
+import java.util.List;
+import java.util.function.Function;
+import org.apache.iceberg.Accessor;
+import org.apache.iceberg.Schema;
+import org.apache.iceberg.StructLike;
+import org.apache.iceberg.io.CloseableGroup;
+import org.apache.iceberg.io.CloseableIterable;
+import org.apache.iceberg.io.CloseableIterator;
+import org.apache.iceberg.relocated.com.google.common.collect.ImmutableList;
+import org.apache.iceberg.relocated.com.google.common.collect.Lists;
+import org.apache.iceberg.types.Comparators;
+import org.apache.iceberg.types.Types;
+import org.apache.iceberg.util.Filter;
+import org.apache.iceberg.util.FilterIterator;
+import org.apache.iceberg.util.SortedMerge;
+
+public class Deletes {
+  private static final Schema POSITION_DELETE_SCHEMA = new Schema(
+      Types.NestedField.required(1, "filename", Types.StringType.get(), "Data file location of the deleted row"),
+      Types.NestedField.required(2, "pos", Types.LongType.get(), "Row position in the data file of the deleted row")
+  );
+
+  private static final Accessor<StructLike> FILENAME_ACCESSOR = POSITION_DELETE_SCHEMA.accessorForField(1);
+  private static final Accessor<StructLike> POSITION_ACCESSOR = POSITION_DELETE_SCHEMA.accessorForField(2);
+
+  private Deletes() {
+  }
+
+  public static <T> CloseableIterable<T> positionFilter(CloseableIterable<T> rows, Function<T, Long> rowToPosition,
+                                                        CloseableIterable<Long> posDeletes) {
+    return new PositionDeleteFilter<>(rows, rowToPosition, posDeletes);
+  }
+
+  public static CloseableIterable<Long> deletePositions(String dataLocation, CloseableIterable<StructLike> posDeletes) {
+    return deletePositions(dataLocation, ImmutableList.of(posDeletes));
+  }
+
+  public static CloseableIterable<Long> deletePositions(String dataLocation,
+                                                        List<CloseableIterable<StructLike>> deleteFiles) {
+    DataFileFilter locationFilter = new DataFileFilter(dataLocation);
+    List<CloseableIterable<Long>> positions = Lists.transform(deleteFiles, deletes ->
+        CloseableIterable.transform(locationFilter.filter(deletes), row -> (Long) POSITION_ACCESSOR.get(row)));
+
+    return new SortedMerge<>(Long::compare, positions);
+  }
+
+  private static class PositionDeleteFilter<T> extends CloseableGroup implements CloseableIterable<T> {

Review comment:
       Does this mean we will filter out positions after we read data and project meta columns? Do we plan to push this down to readers in the future? How will it work with vectorized execution?




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