pvary commented on code in PR #4904:
URL: https://github.com/apache/iceberg/pull/4904#discussion_r925864835


##########
flink/v1.15/flink/src/test/java/org/apache/iceberg/flink/sink/v2/TestStreamWriter.java:
##########
@@ -0,0 +1,338 @@
+/*
+ * 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.flink.sink.v2;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+import org.apache.flink.api.connector.sink2.SinkWriter;
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.metrics.testutils.MetricListener;
+import org.apache.flink.table.api.DataTypes;
+import org.apache.flink.table.api.TableSchema;
+import org.apache.flink.table.data.GenericRowData;
+import org.apache.flink.table.data.RowData;
+import org.apache.flink.table.types.logical.RowType;
+import org.apache.iceberg.AppendFiles;
+import org.apache.iceberg.DataFile;
+import org.apache.iceberg.FileFormat;
+import org.apache.iceberg.PartitionSpec;
+import org.apache.iceberg.Schema;
+import org.apache.iceberg.SerializableTable;
+import org.apache.iceberg.Table;
+import org.apache.iceberg.TableProperties;
+import org.apache.iceberg.data.GenericRecord;
+import org.apache.iceberg.data.Record;
+import org.apache.iceberg.flink.FlinkWriteConf;
+import org.apache.iceberg.flink.FlinkWriteOptions;
+import org.apache.iceberg.flink.SimpleDataUtil;
+import org.apache.iceberg.flink.sink.RowDataTaskWriterFactory;
+import org.apache.iceberg.hadoop.HadoopTables;
+import org.apache.iceberg.io.WriteResult;
+import org.apache.iceberg.relocated.com.google.common.collect.ImmutableMap;
+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.Types;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+@RunWith(Parameterized.class)
+public class TestStreamWriter {
+  @Rule
+  public TemporaryFolder tempFolder = new TemporaryFolder();
+  private MetricListener metricListener;
+  private Table table;
+
+  private final FileFormat format;
+  private final boolean partitioned;
+
+  @Parameterized.Parameters(name = "format = {0}, partitioned = {1}")
+  public static Object[][] parameters() {
+    return new Object[][] {
+        {"avro", true},
+        {"avro", false},
+        {"orc", true},
+        {"orc", false},
+        {"parquet", true},
+        {"parquet", false}
+    };
+  }
+
+  public TestStreamWriter(String format, boolean partitioned) {
+    this.format = FileFormat.valueOf(format.toUpperCase(Locale.ENGLISH));
+    this.partitioned = partitioned;
+  }
+
+  @Before
+  public void before() throws IOException {
+    metricListener = new MetricListener();
+    File folder = tempFolder.newFolder();
+    // Construct the iceberg table.
+    Map<String, String> props = 
ImmutableMap.of(TableProperties.DEFAULT_FILE_FORMAT, format.name());
+    table = SimpleDataUtil.createTable(folder.getAbsolutePath(), props, 
partitioned);
+  }
+
+  @Test
+  public void testPreCommit() throws Exception {
+    StreamWriter streamWriter = createIcebergStreamWriter();
+    streamWriter.write(SimpleDataUtil.createRowData(1, "hello"), new 
ContextImpl());
+    streamWriter.write(SimpleDataUtil.createRowData(2, "hello"), new 
ContextImpl());
+    streamWriter.write(SimpleDataUtil.createRowData(3, "hello"), new 
ContextImpl());
+    streamWriter.write(SimpleDataUtil.createRowData(4, "hello"), new 
ContextImpl());
+    streamWriter.write(SimpleDataUtil.createRowData(5, "hello"), new 
ContextImpl());
+
+    Collection<FilesCommittable> filesCommittables = 
streamWriter.prepareCommit();
+    Assert.assertEquals(filesCommittables.size(), 1);
+  }
+
+  @Test
+  public void testWritingTable() throws Exception {
+    StreamWriter streamWriter = createIcebergStreamWriter();
+    // The first checkpoint
+    streamWriter.write(SimpleDataUtil.createRowData(1, "hello"), new 
ContextImpl());
+    streamWriter.write(SimpleDataUtil.createRowData(2, "world"), new 
ContextImpl());
+    streamWriter.write(SimpleDataUtil.createRowData(3, "hello"), new 
ContextImpl());
+
+    Collection<FilesCommittable> filesCommittables = 
streamWriter.prepareCommit();
+    Assert.assertEquals(filesCommittables.size(), 1);
+
+    AppendFiles appendFiles = table.newAppend();
+
+    WriteResult result = null;
+    for (FilesCommittable filesCommittable : filesCommittables) {
+      result = filesCommittable.committable();
+    }
+    long expectedDataFiles = partitioned ? 2 : 1;

Review Comment:
   nit: newline?



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

To unsubscribe, e-mail: [email protected]

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