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 14:02:17 UTC

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

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



##########
File path: core/src/main/java/org/apache/iceberg/deletes/Deletes.java
##########
@@ -0,0 +1,163 @@
+/*
+ * 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.Set;
+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.base.Preconditions;
+import org.apache.iceberg.relocated.com.google.common.collect.ImmutableList;
+import org.apache.iceberg.relocated.com.google.common.collect.Iterators;
+import org.apache.iceberg.relocated.com.google.common.collect.Lists;
+import org.apache.iceberg.relocated.com.google.common.collect.Sets;
+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;
+import org.apache.iceberg.util.StructLikeWrapper;
+
+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 ->

Review comment:
       How large do we expect the `deleteFiles` list to be? Wondering if adding to a sorted container while iterating would be more efficient. Suppose it will only matter if we expect the iterable to be extremely large




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