You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@paimon.apache.org by "leaves12138 (via GitHub)" <gi...@apache.org> on 2024/08/22 06:35:39 UTC

[PR] [core] Add batch record write interface for table. [paimon]

leaves12138 opened a new pull request, #4034:
URL: https://github.com/apache/paimon/pull/4034

   <!-- Please specify the module before the PR name: [core] ... or [flink] ... -->
   
   ### Purpose
   
   Other compute engine (which process batch mainly) may need to add a batch record in one time. Not per row processing
   
   
   <!-- What is the purpose of the change -->
   
   ### Tests
   
   <!-- List UT and IT cases to verify this change -->
   
   ### API and Format
   
   <!-- Does this change affect API or storage format -->
   
   ### Documentation
   
   <!-- Does this change introduce a new feature -->
   


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

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


Re: [PR] [core] Add batch record write interface for table. [paimon]

Posted by "JingsongLi (via GitHub)" <gi...@apache.org>.
JingsongLi commented on code in PR #4034:
URL: https://github.com/apache/paimon/pull/4034#discussion_r1726736364


##########
paimon-core/src/main/java/org/apache/paimon/table/sink/TableWriteImpl.java:
##########
@@ -174,6 +184,19 @@ public SinkRecord writeAndReturn(InternalRow row, int bucket) throws Exception {
         return record;
     }
 
+    @Nullable
+    public SinkRecord writeAndReturn(InternalRow row, BinaryRow partition, int bucket)

Review Comment:
   remove this method



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

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


Re: [PR] [core] Add batch record write interface for table. [paimon]

Posted by "JingsongLi (via GitHub)" <gi...@apache.org>.
JingsongLi commented on code in PR #4034:
URL: https://github.com/apache/paimon/pull/4034#discussion_r1726735219


##########
paimon-core/src/main/java/org/apache/paimon/operation/FileStoreWrite.java:
##########
@@ -104,6 +105,17 @@ default FileStoreWrite<T> withMemoryPool(MemorySegmentPool memoryPool) {
      */
     void write(BinaryRow partition, int bucket, T data) throws Exception;
 
+    /**
+     * Write the batch data to the store according to the partition and bucket.
+     *
+     * @param partition the partition of the data
+     * @param bucket the bucket id of the data
+     * @param data the given data
+     * @return whether success to write batch
+     * @throws Exception the thrown exception when writing the record
+     */
+    boolean writeBatch(BinaryRow partition, int bucket, BatchRecords data) throws Exception;

Review Comment:
   we don't need to return boolean.



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

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


Re: [PR] [core] Add batch record write interface for table. [paimon]

Posted by "JingsongLi (via GitHub)" <gi...@apache.org>.
JingsongLi commented on code in PR #4034:
URL: https://github.com/apache/paimon/pull/4034#discussion_r1726734395


##########
paimon-core/src/main/java/org/apache/paimon/operation/AbstractFileStoreWrite.java:
##########
@@ -143,6 +144,12 @@ public void write(BinaryRow partition, int bucket, T data) throws Exception {
         }
     }
 
+    @Override
+    public boolean writeBatch(BinaryRow partition, int bucket, BatchRecords data) throws Exception {
+        WriterContainer<T> container = getWriterWrapper(partition, bucket);
+        return container.writer.writeBatch(data);

Review Comment:
   Introduce a `BatchRecordWriter`.



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

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


Re: [PR] [core] Add batch record write interface for table. [paimon]

Posted by "JingsongLi (via GitHub)" <gi...@apache.org>.
JingsongLi commented on code in PR #4034:
URL: https://github.com/apache/paimon/pull/4034#discussion_r1726732699


##########
paimon-core/src/main/java/org/apache/paimon/io/SingleFileWriter.java:
##########
@@ -94,6 +95,21 @@ public void write(T record) throws IOException {
         writeImpl(record);
     }
 
+    public void writeBatch(BatchRecords batchRecords) throws IOException {
+        if (closed) {
+            throw new RuntimeException("Writer has already closed!");
+        }
+
+        if (writer instanceof BatchFormatWriter) {
+            ((BatchFormatWriter) writer).writeBatch(batchRecords);
+        } else {
+            for (InternalRow row : batchRecords) {
+                writer.addElement(row);

Review Comment:
   catch `Throwable` too?



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

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


Re: [PR] [core] Add batch record write interface for table. [paimon]

Posted by "JingsongLi (via GitHub)" <gi...@apache.org>.
JingsongLi commented on code in PR #4034:
URL: https://github.com/apache/paimon/pull/4034#discussion_r1726739002


##########
paimon-core/src/main/java/org/apache/paimon/operation/AbstractFileStoreWrite.java:
##########
@@ -143,6 +144,12 @@ public void write(BinaryRow partition, int bucket, T data) throws Exception {
         }
     }
 

Review Comment:
   create a method `supportsBatchWrite(BinaryRow partition, int bucket)`.



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

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


Re: [PR] [core] Add batch record write interface for table. [paimon]

Posted by "JingsongLi (via GitHub)" <gi...@apache.org>.
JingsongLi commented on code in PR #4034:
URL: https://github.com/apache/paimon/pull/4034#discussion_r1728594059


##########
paimon-core/src/main/java/org/apache/paimon/operation/BatchWriter.java:
##########
@@ -0,0 +1,36 @@
+/*
+ * 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.paimon.operation;
+
+import org.apache.paimon.data.BinaryRow;
+import org.apache.paimon.io.BatchRecords;
+
+/** Whether the writer could write batch. */
+public interface BatchWriter {

Review Comment:
   `BatchFileStoreWrite`



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

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


Re: [PR] [core] Add batch record write interface for table. [paimon]

Posted by "JingsongLi (via GitHub)" <gi...@apache.org>.
JingsongLi commented on code in PR #4034:
URL: https://github.com/apache/paimon/pull/4034#discussion_r1726455227


##########
paimon-common/src/main/java/org/apache/paimon/io/BatchRecords.java:
##########
@@ -0,0 +1,27 @@
+/*
+ * 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.paimon.io;
+
+/** Interface of Batch records. */
+public interface BatchRecords {

Review Comment:
   it is better to be an `Iterable<InternalRow>`



##########
paimon-core/src/main/java/org/apache/paimon/utils/RecordWriter.java:
##########
@@ -35,6 +36,11 @@ public interface RecordWriter<T> {
     /** Add a key-value element to the writer. */
     void write(T record) throws Exception;
 
+    /** Add a batch elemens to the writer. */
+    default void writeBatch(BatchRecords record) throws Exception {
+        throw new UnsupportedOperationException("Not supported");

Review Comment:
   should not throw exception



##########
paimon-common/src/main/java/org/apache/paimon/format/FormatWriter.java:
##########
@@ -47,6 +48,10 @@ public interface FormatWriter {
      */
     void flush() throws IOException;
 
+    default void writeBatch(BatchRecords batchRecords) throws IOException {
+        throw new UnsupportedOperationException("Not supported.");

Review Comment:
   create an interface: `BatchFormatWriter`.



##########
paimon-core/src/main/java/org/apache/paimon/append/AppendOnlyWriter.java:
##########
@@ -172,6 +173,14 @@ public void write(InternalRow rowData) throws Exception {
         }
     }
 
+    @Override
+    public void writeBatch(BatchRecords batchRecords) throws Exception {
+        if (sinkWriter instanceof BufferedSinkWriter) {
+            throw new RuntimeException("Not support BufferedSinkWriter.");

Review Comment:
   never throw exception



##########
paimon-core/src/main/java/org/apache/paimon/table/sink/BatchTableWrite.java:
##########
@@ -36,4 +38,7 @@ public interface BatchTableWrite extends TableWrite {
      * @see BatchTableCommit#commit
      */
     List<CommitMessage> prepareCommit() throws Exception;
+
+    /** Write a batch records directly, not per row. */
+    void writeBatch(BinaryRow partition, int bucket, BatchRecords batch) throws Exception;

Review Comment:
   can be in `TableWrite`.



##########
paimon-core/src/main/java/org/apache/paimon/io/SingleFileWriter.java:
##########
@@ -94,6 +94,15 @@ public void write(T record) throws IOException {
         writeImpl(record);
     }
 
+    public void writeBatch(BatchRecords batchRecords) throws IOException {
+        if (closed) {
+            throw new RuntimeException("Writer has already closed!");
+        }
+
+        writer.writeBatch(batchRecords);

Review Comment:
   why no try catch?



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

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


Re: [PR] [core] Add batch record write interface for table. [paimon]

Posted by "JingsongLi (via GitHub)" <gi...@apache.org>.
JingsongLi commented on code in PR #4034:
URL: https://github.com/apache/paimon/pull/4034#discussion_r1726721949


##########
paimon-common/src/main/java/org/apache/paimon/format/FormatWriterFactory.java:
##########
@@ -33,5 +33,5 @@ public interface FormatWriterFactory {
      * @throws IOException Thrown if the writer cannot be opened, or if the output stream throws an
      *     exception.
      */
-    FormatWriter create(PositionOutputStream out, String compression) throws IOException;
+    BatchFormatWriter create(PositionOutputStream out, String compression) throws IOException;

Review Comment:
   return `FormatWriter`.



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

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


Re: [PR] [core] Add batch record write interface for table. [paimon]

Posted by "JingsongLi (via GitHub)" <gi...@apache.org>.
JingsongLi commented on code in PR #4034:
URL: https://github.com/apache/paimon/pull/4034#discussion_r1728594059


##########
paimon-core/src/main/java/org/apache/paimon/operation/BatchWriter.java:
##########
@@ -0,0 +1,36 @@
+/*
+ * 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.paimon.operation;
+
+import org.apache.paimon.data.BinaryRow;
+import org.apache.paimon.io.BatchRecords;
+
+/** Whether the writer could write batch. */
+public interface BatchWriter {

Review Comment:
   `BatchFileStoreWrite extends FileStoreWrite<Internal>`



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

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


Re: [PR] [core] Add batch record write interface for table. [paimon]

Posted by "JingsongLi (via GitHub)" <gi...@apache.org>.
JingsongLi commented on code in PR #4034:
URL: https://github.com/apache/paimon/pull/4034#discussion_r1726731291


##########
paimon-core/src/main/java/org/apache/paimon/append/AppendOnlyWriter.java:
##########
@@ -172,6 +173,18 @@ public void write(InternalRow rowData) throws Exception {
         }
     }
 
+    @Override
+    public boolean writeBatch(BatchRecords batchRecords) throws Exception {
+        if (sinkWriter instanceof BufferedSinkWriter) {
+            for (InternalRow row : batchRecords) {
+                sinkWriter.write(row);

Review Comment:
   Use `write(row)` instead of sinkWriter.



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

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


Re: [PR] [core] Add batch record write interface for table. [paimon]

Posted by "leaves12138 (via GitHub)" <gi...@apache.org>.
leaves12138 merged PR #4034:
URL: https://github.com/apache/paimon/pull/4034


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

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