You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@iceberg.apache.org by "ztaylor797 (via GitHub)" <gi...@apache.org> on 2023/03/10 19:32:04 UTC

[GitHub] [iceberg] ztaylor797 commented on a diff in pull request #6571: Data: java api add GenericTaskWriter and add write demo to Doc.

ztaylor797 commented on code in PR #6571:
URL: https://github.com/apache/iceberg/pull/6571#discussion_r1132799425


##########
data/src/test/java/org/apache/iceberg/data/TestGenericTaskWriter.java:
##########
@@ -0,0 +1,151 @@
+/*
+ * 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.data;
+
+import java.io.File;
+import java.io.IOException;
+import java.time.OffsetDateTime;
+import java.util.Collections;
+import java.util.List;
+import org.apache.hadoop.conf.Configuration;
+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.Table;
+import org.apache.iceberg.catalog.Catalog;
+import org.apache.iceberg.catalog.TableIdentifier;
+import org.apache.iceberg.hadoop.HadoopCatalog;
+import org.apache.iceberg.io.OutputFileFactory;
+import org.apache.iceberg.relocated.com.google.common.collect.Lists;
+import org.apache.iceberg.types.Types;
+import org.apache.iceberg.util.StructLikeSet;
+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 TestGenericTaskWriter {
+  @Rule public final TemporaryFolder temp = new TemporaryFolder();
+
+  private final Schema schema =
+      new Schema(
+          Types.NestedField.required(1, "level", Types.StringType.get()),
+          Types.NestedField.required(2, "event_time", Types.TimestampType.withZone()),
+          Types.NestedField.required(3, "message", Types.StringType.get()),
+          Types.NestedField.optional(
+              4, "call_stack", Types.ListType.ofRequired(5, Types.StringType.get())));
+
+  private final PartitionSpec spec =
+      PartitionSpec.builderFor(schema).hour("event_time").identity("level").build();
+
+  private Table table;
+  private List<Record> testRecords = Lists.newArrayList();
+  private final String testFileFormat;
+
+  @Parameterized.Parameters(name = "FileFormat = {0}")
+  public static Object[][] parameters() {
+    return new Object[][] {{"avro"}, {"orc"}, {"parquet"}};
+  }
+
+  public TestGenericTaskWriter(String fileFormat) throws IOException {
+    this.testFileFormat = fileFormat;
+  }
+
+  @Before
+  public void createTable() throws IOException {
+    File testWareHouse = temp.newFolder();
+    if (testWareHouse.exists()) {
+      Assert.assertTrue(testWareHouse.delete());
+    }
+
+    Catalog catalog = new HadoopCatalog(new Configuration(), testWareHouse.getPath());
+    this.table =
+        catalog.createTable(
+            TableIdentifier.of("logging", "logs"),
+            schema,
+            spec,
+            Collections.singletonMap("write.format.default", testFileFormat));
+  }
+
+  // test write and java API write data code demo
+  private void writeRecords() throws IOException {
+    GenericAppenderFactory appenderFactory =
+        new GenericAppenderFactory(table.schema(), table.spec());
+
+    FileFormat fileFormat =
+        FileFormat.valueOf(
+            table.properties().getOrDefault("write.format.default", "parquet").toUpperCase());
+
+    int partitionId = 1;

Review Comment:
   @youngxinler What is the expected behavior here with partitionId being hard-coded?
   
   I have tried to implement your code here in my own project, but it results in the partitions reporting as undefined instead of properly fanning out, at least when querying from Trino.



-- 
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: issues-unsubscribe@iceberg.apache.org

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