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/12/06 00:09:17 UTC

[GitHub] [iceberg] rdblue commented on a change in pull request #1858: Core: Add SortedPosDeleteWriter

rdblue commented on a change in pull request #1858:
URL: https://github.com/apache/iceberg/pull/1858#discussion_r536918599



##########
File path: core/src/main/java/org/apache/iceberg/io/SortedPosDeleteWriter.java
##########
@@ -0,0 +1,172 @@
+/*
+ * 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.io;
+
+import java.io.Closeable;
+import java.io.IOException;
+import java.io.UncheckedIOException;
+import java.util.Comparator;
+import java.util.List;
+import java.util.Set;
+import org.apache.iceberg.DeleteFile;
+import org.apache.iceberg.FileFormat;
+import org.apache.iceberg.PartitionKey;
+import org.apache.iceberg.deletes.PositionDeleteWriter;
+import org.apache.iceberg.encryption.EncryptedOutputFile;
+import org.apache.iceberg.relocated.com.google.common.collect.Lists;
+import org.apache.iceberg.relocated.com.google.common.collect.Maps;
+import org.apache.iceberg.relocated.com.google.common.collect.Multimap;
+import org.apache.iceberg.relocated.com.google.common.collect.Multimaps;
+import org.apache.iceberg.types.Comparators;
+import org.apache.iceberg.util.CharSequenceSet;
+import org.apache.iceberg.util.CharSequenceWrapper;
+
+class SortedPosDeleteWriter<T> implements Closeable {
+  private static final long DEFAULT_RECORDS_NUM_THRESHOLD = 100_000L;
+
+  private final Multimap<CharSequenceWrapper, PosValue<T>> posDeletes =
+      Multimaps.newMultimap(Maps.newHashMap(), Lists::newArrayList);
+  private final List<DeleteFile> completedFiles = Lists.newArrayList();
+  private final Set<CharSequence> referencedDataFiles = CharSequenceSet.empty();
+  private final CharSequenceWrapper wrapper = CharSequenceWrapper.wrap(null);
+
+  private final FileAppenderFactory<T> appenderFactory;
+  private final OutputFileFactory fileFactory;
+  private final FileFormat format;
+  private final PartitionKey partition;
+  private final long recordsNumThreshold;
+
+  private int records = 0;
+
+  SortedPosDeleteWriter(FileAppenderFactory<T> appenderFactory,
+                        OutputFileFactory fileFactory,
+                        FileFormat format,
+                        PartitionKey partition,
+                        long recordsNumThreshold) {
+    this.appenderFactory = appenderFactory;
+    this.fileFactory = fileFactory;
+    this.format = format;
+    this.partition = partition;
+    this.recordsNumThreshold = recordsNumThreshold;
+  }
+
+  SortedPosDeleteWriter(FileAppenderFactory<T> appenderFactory,
+                        OutputFileFactory fileFactory,
+                        FileFormat format,
+                        PartitionKey partition) {
+    this(appenderFactory, fileFactory, format, partition, DEFAULT_RECORDS_NUM_THRESHOLD);
+  }
+
+  public void delete(CharSequence path, long pos) {
+    delete(path, pos, null);
+  }
+
+  public void delete(CharSequence path, long pos, T row) {
+    posDeletes.put(CharSequenceWrapper.wrap(path), PosValue.of(pos, row));

Review comment:
       Using a multimap requires this to create a new `CharSequenceWrapper` for each delete, even though we expect a very small set of keys. I think it would be better to use a regular map so that a new wrapper is created for only the first delete in each file:
   
   ```java
     List<PosValue<T>> values = posDeletes.get(wrapper.set(path));
     if (values != null) {
       values.add(PosValue.of(pos, row));
     } else {
       posDeletes.add(Lists.newArrayList(PosValue.of(pos, 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.

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