JingsongLi commented on code in PR #1350:
URL: https://github.com/apache/incubator-paimon/pull/1350#discussion_r1227759182
##########
paimon-common/src/main/java/org/apache/paimon/format/FormatWriter.java:
##########
@@ -60,4 +60,27 @@ public interface FormatWriter {
* @throws IOException Thrown if the finalization fails.
*/
void finish() throws IOException;
+
+ /**
+ * Returns the number of bytes that were currently written by this writer.
+ *
+ * <p>NOTE: This is an estimated value.
+ *
+ * @return the number of written bytes
+ * @throws IOException Thrown if calculating the length fails.
+ */
+ long length() throws IOException;
+
+ /**
+ * Check if the writer has reached the <code>targetSize</code>.
+ *
+ * @param suggestedCheck Whether it needs to be checked, but subclasses
can also decide whether
+ * to check it themselves.
+ * @param targetSize The size of the target.
+ * @return true if the target size was reached, otherwise false.
+ * @throws IOException Thrown if calculating the length fails.
+ */
+ default boolean reachTargetSize(boolean suggestedCheck, long targetSize)
throws IOException {
Review Comment:
It is good to not introduce a default method which is invoked by per record.
I remember the default method's performance wasn't that good.
##########
paimon-common/src/main/java/org/apache/paimon/format/FormatWriter.java:
##########
@@ -60,4 +60,27 @@ public interface FormatWriter {
* @throws IOException Thrown if the finalization fails.
*/
void finish() throws IOException;
+
+ /**
+ * Returns the number of bytes that were currently written by this writer.
+ *
+ * <p>NOTE: This is an estimated value.
+ *
+ * @return the number of written bytes
+ * @throws IOException Thrown if calculating the length fails.
+ */
+ long length() throws IOException;
Review Comment:
We don't need to introduce this method.
##########
paimon-core/src/main/java/org/apache/paimon/io/SingleFileWriter.java:
##########
@@ -114,12 +114,16 @@ public long recordCount() {
return recordCount;
}
+ public boolean reachTargetSize(boolean suggestedCheck, long targetSize)
throws IOException {
+ return writer.reachTargetSize(suggestedCheck, targetSize);
+ }
+
@Override
public long length() throws IOException {
Review Comment:
Maybe we can remove this method.
Only rolling will invoke this method.
##########
paimon-format/src/main/java/org/apache/paimon/format/orc/writer/OrcBulkWriter.java:
##########
@@ -67,4 +80,35 @@ public void finish() throws IOException {
flush();
writer.close();
}
+
+ @Override
+ public long length() throws IOException {
+ long estimateMemory = treeWriter.estimateMemory();
+ long fileLength = underlyingStream.getPos();
+
+ // This value is estimated, not actual.
+ return (long) Math.ceil(fileLength + estimateMemory * 0.2);
Review Comment:
We don't need to read `stripes` now?
--
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]