Skip to content
9 changes: 8 additions & 1 deletion cpp/src/parquet/encoding.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1196,6 +1196,10 @@ struct ArrowBinaryHelper<ByteArrayType> {
chunk_space_remaining_(::arrow::kBinaryMemoryLimit -
acc_->builder->value_data_length()) {}

// Prepare will reserve the number of entries remaining in the current chunk.
// If estimated_data_length is provided, it will also Reserve the estimated data length,
// and the caller should remember to call `UnsafeAppend` instead of `Append` to avoid
// double counting the data length.
Status Prepare(std::optional<int64_t> estimated_data_length = {}) {
RETURN_NOT_OK(acc_->builder->Reserve(entries_remaining_));
if (estimated_data_length.has_value()) {
Expand All @@ -1205,6 +1209,9 @@ struct ArrowBinaryHelper<ByteArrayType> {
return Status::OK();
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What difference does it make to have a separate method?

@mapleFU mapleFU Nov 24, 2023

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://godbolt.org/z/5bf1K55a5

Found it might not optimized with hot path. Prepare is not in hot path, but PrepareNextInput is.


// If estimated_remaining_data_length is provided, it will also reserve the estimated
// data length, and the caller should remember to call `UnsafeAppend` instead of
// `Append` to avoid double counting the data length.
Status PrepareNextInput(int64_t next_value_length,
std::optional<int64_t> estimated_remaining_data_length = {}) {
if (ARROW_PREDICT_FALSE(!CanFit(next_value_length))) {
Expand Down Expand Up @@ -1983,7 +1990,7 @@ class DictByteArrayDecoderImpl : public DictDecoderImpl<ByteArrayType>,
int values_decoded = 0;

ArrowBinaryHelper<ByteArrayType> helper(out, num_values);
RETURN_NOT_OK(helper.Prepare(len_));
RETURN_NOT_OK(helper.Prepare());
Comment thread
mapleFU marked this conversation as resolved.

auto dict_values = reinterpret_cast<const ByteArray*>(dictionary_->data());

Comment thread
mapleFU marked this conversation as resolved.
Expand Down