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/04 04:40:35 UTC

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

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



##########
File path: core/src/main/java/org/apache/iceberg/io/SortedPosDeleteWriter.java
##########
@@ -0,0 +1,190 @@
+/*
+ * 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.Arrays;
+import java.util.Comparator;
+import java.util.List;
+import java.util.Map;
+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.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 Map<CharSequenceWrapper, List<PosValue<T>>> posDeletes = Maps.newHashMap();
+  private final List<DeleteFile> completedFiles = Lists.newArrayList();
+  private final Set<CharSequence> referencedDataFiles = CharSequenceSet.empty();
+  private final PosValueComparator<T> posValueComparator = new PosValueComparator<>();
+  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.compute(CharSequenceWrapper.wrap(path), (k, v) -> {

Review comment:
       We could not use `wrapper.set` here  because we will put this item into `map` and if not then other paths also use `wrapper.set` to compare `CharSequence` then the key of map will be messed up.  It's safe to create a new `CharSequenceWrapper` here.   




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