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


##########
docs/java-api.md:
##########
@@ -147,6 +147,53 @@ t.newAppend().appendFile(data).commit();
 t.commitTransaction();
 ```
 
+### WriteData
+
+The java api can write data into iceberg table.
+
+First write data to the data file, then submit the data file, the data you 
write will take effect in the table.
+
+For example, add 1000 pieces of data to the table.
+
+```java
+GenericAppenderFactory appenderFactory = new 
GenericAppenderFactory(table.schema(), table.spec());
+
+int partitionId = 1, taskId = 1;
+OutputFileFactory outputFileFactory = OutputFileFactory.builderFor(table, 
partitionId, taskId).format(FileFormat.PARQUET).build();
+final PartitionKey partitionKey = new PartitionKey(table.spec(), 
table.spec().schema());
+final InternalRecordWrapper recordWrapper = new 
InternalRecordWrapper(table.schema().asStruct());
+
+// partitionedFanoutWriter will auto partitioned record and create the 
partitioned writer
+PartitionedFanoutWriter<Record> partitionedFanoutWriter = new 
PartitionedFanoutWriter<Record>(table.spec(), FileFormat.PARQUET, 
appenderFactory, outputFileFactory, table.io(), TARGET_FILE_SIZE_IN_BYTES) {
+    @Override
+    protected PartitionKey partition(Record record) {
+        partitionKey.partition(recordWrapper.wrap(record));
+        return partitionKey;
+    }
+};
+
+GenericRecord genericRecord = GenericRecord.create(table.schema());
+
+// assume write 1000 records
+for (int i = 0; i < 1000; i++) {
+    GenericRecord record = genericRecord.copy();
+    record.setField("level",  i % 6 == 0 ? "error" : "info");

Review Comment:
   > we might want to specify the schema of the records you insert before the 
code block so people can understand it more easily
   
   The table structure has been described in the code comments



-- 
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-unsubscr...@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org
For additional commands, e-mail: issues-h...@iceberg.apache.org

Reply via email to