wecharyu commented on code in PR #48468:
URL: https://github.com/apache/arrow/pull/48468#discussion_r2699352361
##########
cpp/src/parquet/arrow/writer.cc:
##########
@@ -480,17 +481,24 @@ class FileWriterImpl : public FileWriter {
return Status::OK();
};
+ const int64_t max_row_group_length =
this->properties().max_row_group_length();
+ const int64_t max_row_group_bytes =
this->properties().max_row_group_bytes();
+
int64_t offset = 0;
while (offset < batch.num_rows()) {
- const int64_t batch_size =
- std::min(max_row_group_length - row_group_writer_->num_rows(),
- batch.num_rows() - offset);
- RETURN_NOT_OK(WriteBatch(offset, batch_size));
- offset += batch_size;
-
- // Flush current row group writer and create a new writer if it is full.
- if (row_group_writer_->num_rows() >= max_row_group_length &&
- offset < batch.num_rows()) {
+ int64_t batch_size = std::min(max_row_group_length -
row_group_writer_->num_rows(),
+ batch.num_rows() - offset);
+ if (auto avg_row_size = EstimateCompressedBytesPerRow()) {
+ int64_t buffered_bytes =
row_group_writer_->EstimatedTotalCompressedBytes();
+ batch_size = std::min(
+ batch_size, static_cast<int64_t>((max_row_group_bytes -
buffered_bytes) /
+ avg_row_size.value()));
+ }
+ if (batch_size > 0) {
+ RETURN_NOT_OK(WriteBatch(offset, batch_size));
+ offset += batch_size;
+ } else if (offset < batch.num_rows()) {
+ // Current row group is full, write remaining rows in a new group.
Review Comment:
We does not check row group size after write batch, current write logic is
like:
1. check rows and bytes to determine current batch_size
2. if batch_size > 0, write these rows to current row group, it's guaranteed
not exceeds the row group limits
3. if batch_size = 0 and still has rows to write, new a row group
4. next loop to 1
In this way we don't need check size after written, it's guaranteed in step
1; and we'll not leave an possible empty row group in the final batch, it
guaranteed in step 3.
--
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]