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



##########
File path: data/src/test/java/org/apache/iceberg/io/TestTaskDeltaWriter.java
##########
@@ -0,0 +1,417 @@
+/*
+ * 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.util.Arrays;
+import java.util.List;
+import java.util.Locale;
+import java.util.function.Function;
+import org.apache.iceberg.DataFile;
+import org.apache.iceberg.DeleteFile;
+import org.apache.iceberg.FileContent;
+import org.apache.iceberg.FileFormat;
+import org.apache.iceberg.Files;
+import org.apache.iceberg.PartitionKey;
+import org.apache.iceberg.PartitionSpec;
+import org.apache.iceberg.RowDelta;
+import org.apache.iceberg.Schema;
+import org.apache.iceberg.StructLike;
+import org.apache.iceberg.TableTestBase;
+import org.apache.iceberg.avro.Avro;
+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.data.avro.DataReader;
+import org.apache.iceberg.data.parquet.GenericParquetReaders;
+import org.apache.iceberg.parquet.Parquet;
+import org.apache.iceberg.relocated.com.google.common.collect.ImmutableList;
+import org.apache.iceberg.relocated.com.google.common.collect.Lists;
+import org.apache.iceberg.util.ArrayUtil;
+import org.apache.iceberg.util.StructLikeSet;
+import org.apache.iceberg.util.StructProjection;
+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 TestTaskDeltaWriter extends TableTestBase {
+  private static final int FORMAT_V2 = 2;
+  private static final long TARGET_FILE_SIZE = 128 * 1024 * 1024L;
+
+  private final FileFormat format;
+  private final GenericRecord gRecord = GenericRecord.create(SCHEMA);
+  private final GenericRecord posRecord = 
GenericRecord.create(DeleteSchemaUtil.pathPosSchema());
+
+  private OutputFileFactory fileFactory = null;
+  private int idFieldId;
+  private int dataFieldId;
+
+  @Parameterized.Parameters(name = "FileFormat = {0}")
+  public static Object[][] parameters() {
+    return new Object[][] {
+        {"avro"},
+        {"parquet"}
+    };
+  }
+
+  public TestTaskDeltaWriter(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);
+
+    this.idFieldId = table.schema().findField("id").fieldId();
+    this.dataFieldId = table.schema().findField("data").fieldId();
+
+    table.updateProperties()
+        .defaultFormat(format)
+        .commit();
+  }
+
+  private Record createRecord(Integer id, String data) {
+    return gRecord.copy("id", id, "data", data);
+  }
+
+  @Test
+  public void testPureInsert() throws IOException {
+    List<Integer> eqDeleteFieldIds = Lists.newArrayList(idFieldId, 
dataFieldId);
+    Schema eqDeleteSchema = table.schema();
+
+    GenericTaskDeltaWriter deltaWriter = createTaskWriter(eqDeleteFieldIds, 
eqDeleteSchema);
+    List<Record> expected = Lists.newArrayList();
+    for (int i = 0; i < 20; i++) {
+      Record record = createRecord(i, String.format("val-%d", i));
+      expected.add(record);
+
+      deltaWriter.write(record);
+    }
+
+    WriteResult result = deltaWriter.complete();
+    Assert.assertEquals("Should only have a data file.", 1, 
result.dataFiles().length);
+    Assert.assertEquals("Should have no delete file", 0, 
result.deleteFiles().length);
+    commitTransaction(result);
+    Assert.assertEquals("Should have expected records", 
expectedRowSet(expected), actualRowSet("*"));
+
+    deltaWriter = createTaskWriter(eqDeleteFieldIds, eqDeleteSchema);
+    for (int i = 20; i < 30; i++) {
+      Record record = createRecord(i, String.format("val-%d", i));
+      expected.add(record);
+
+      deltaWriter.write(record);
+    }
+    result = deltaWriter.complete();
+    Assert.assertEquals("Should only have a data file.", 1, 
result.dataFiles().length);
+    Assert.assertEquals("Should have no delete file", 0, 
result.deleteFiles().length);
+    commitTransaction(deltaWriter.complete());

Review comment:
       `commitTransaction(result)`?




----------------------------------------------------------------
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:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to