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:39:19 UTC

[GitHub] [iceberg] rdblue commented on a change in pull request #1867: Core: Add RollingEqDeleteWriter.

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



##########
File path: data/src/test/java/org/apache/iceberg/io/TestBaseTaskWriter.java
##########
@@ -0,0 +1,255 @@
+/*
+ * 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.File;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Locale;
+import java.util.stream.Collectors;
+import org.apache.iceberg.DataFile;
+import org.apache.iceberg.DeleteFile;
+import org.apache.iceberg.FileFormat;
+import org.apache.iceberg.PartitionSpec;
+import org.apache.iceberg.RowDelta;
+import org.apache.iceberg.TableTestBase;
+import org.apache.iceberg.data.GenericAppenderFactory;
+import org.apache.iceberg.data.GenericRecord;
+import org.apache.iceberg.data.IcebergGenerics;
+import org.apache.iceberg.data.Record;
+import org.apache.iceberg.relocated.com.google.common.collect.Lists;
+import org.apache.iceberg.util.StructLikeSet;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+@RunWith(Parameterized.class)
+public class TestBaseTaskWriter extends TableTestBase {
+  private static final int FORMAT_V2 = 2;
+
+  private final FileFormat format;
+  private final GenericRecord gRecord = GenericRecord.create(SCHEMA);
+
+  private OutputFileFactory fileFactory = null;
+  private FileAppenderFactory<Record> appenderFactory = null;
+
+  @Parameterized.Parameters(name = "FileFormat = {0}")
+  public static Object[][] parameters() {
+    return new Object[][] {
+        {"avro"},
+        {"parquet"}
+    };
+  }
+
+  public TestBaseTaskWriter(String fileFormat) {
+    super(FORMAT_V2);
+    this.format = FileFormat.valueOf(fileFormat.toUpperCase(Locale.ENGLISH));
+  }
+
+  @Before
+  public void setupTable() throws IOException {
+    this.tableDir = temp.newFolder();
+    Assert.assertTrue(tableDir.delete()); // created by table create
+
+    this.metadataDir = new File(tableDir, "metadata");
+
+    this.table = create(SCHEMA, PartitionSpec.unpartitioned());
+    this.fileFactory = new OutputFileFactory(table.spec(), format, table.locationProvider(), table.io(),
+        table.encryption(), 1, 1);
+
+    int firstFieldId = table.schema().findField("id").fieldId();
+    int secondFieldId = table.schema().findField("data").fieldId();
+    this.appenderFactory = new GenericAppenderFactory(table.schema(), table.spec(),
+        new int[] {firstFieldId, secondFieldId}, table.schema(), null);
+
+    table.updateProperties()
+        .defaultFormat(format)
+        .commit();
+  }
+
+  private Record createRecord(Integer id, String data) {
+    return gRecord.copy("id", id, "data", data);
+  }
+
+  @Test
+  public void testWriteZeroRecord() throws IOException {
+    try (TestTaskWriter writer = createTaskWriter(128 * 1024 * 1024)) {
+      writer.close();
+
+      WriteResult result = writer.complete();
+      Assert.assertEquals(0, result.dataFiles().length);
+      Assert.assertEquals(0, result.deleteFiles().length);
+
+      writer.close();
+      result = writer.complete();
+      Assert.assertEquals(0, result.dataFiles().length);
+      Assert.assertEquals(0, result.deleteFiles().length);
+    }
+  }
+
+  @Test
+  public void testAbort() throws IOException {
+    List<Record> records = Lists.newArrayList();
+    for (int i = 0; i < 2000; i++) {
+      records.add(createRecord(i, "aaa"));
+    }
+
+    WriteResult result;
+    try (TestTaskWriter taskWriter = createTaskWriter(4)) {
+      for (Record record : records) {
+        taskWriter.write(record);
+        taskWriter.delete(record);
+      }
+
+      // Close the current opened files.
+      taskWriter.close();
+
+      // Assert the current data file count.
+      List<Path> files = Files.list(Paths.get(tableDir.getPath(), "data"))
+          .filter(p -> !p.toString().endsWith(".crc"))
+          .collect(Collectors.toList());
+      Assert.assertEquals("Should have 4 files but the files are: " + files, 4, files.size());
+
+      // Abort to clean all delete files and data files.
+      taskWriter.abort();
+
+      // Complete again to get all results.
+      result = taskWriter.complete();
+    }
+    Assert.assertEquals(2, result.deleteFiles().length);

Review comment:
       I think I agree with Yan here. The data file count assertion above ensures that there are only 4 files. So when the writer aborts, we can use the same logic to check that there are now 0 files instead of asserting that each file individually doesn't exist (below). That would be better because it doesn't seem correct for `result.dataFiles()` to return anything after an abort.




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