Copilot commented on code in PR #50710:
URL: https://github.com/apache/arrow/pull/50710#discussion_r3674442070
##########
cpp/src/parquet/decoder.cc:
##########
@@ -1295,12 +1294,80 @@ class DictByteArrayDecoderImpl : public
DictDecoderImpl<ByteArrayType> {
int64_t valid_bits_offset,
typename EncodingTraits<ByteArrayType>::Accumulator*
out,
int* out_num_values) {
+ const auto* dict_values = dictionary_->data_as<ByteArray>();
+ const int values_to_decode = num_values - null_count;
+
+ switch (out->builder->type()->id()) {
+ case ::arrow::Type::BINARY:
+ case ::arrow::Type::STRING:
+ case ::arrow::Type::LARGE_BINARY:
+ case ::arrow::Type::LARGE_STRING: {
+ if (values_to_decode > 0) {
+ RETURN_NOT_OK(indices_scratch_space_->TypedResize<int32_t>(
+ values_to_decode, /*shrink_to_fit=*/false));
+ }
+ auto* decoded_indices =
indices_scratch_space_->mutable_data_as<int32_t>();
+ const int num_indices = idx_decoder_.GetBatch(decoded_indices,
values_to_decode);
+ if (ARROW_PREDICT_FALSE(num_indices != values_to_decode)) {
+ return Status::Invalid("Invalid number of indices: ", num_indices);
+ }
Review Comment:
The error message when the index stream decodes fewer indices than expected
is missing the expected count and doesn’t clearly indicate
truncation/corruption. Including both expected/actual makes failures much
easier to diagnose (and aligns with the new regression test intent).
##########
cpp/src/parquet/decoder.cc:
##########
@@ -1295,12 +1294,80 @@ class DictByteArrayDecoderImpl : public
DictDecoderImpl<ByteArrayType> {
int64_t valid_bits_offset,
typename EncodingTraits<ByteArrayType>::Accumulator*
out,
int* out_num_values) {
+ const auto* dict_values = dictionary_->data_as<ByteArray>();
+ const int values_to_decode = num_values - null_count;
+
+ switch (out->builder->type()->id()) {
+ case ::arrow::Type::BINARY:
+ case ::arrow::Type::STRING:
+ case ::arrow::Type::LARGE_BINARY:
+ case ::arrow::Type::LARGE_STRING: {
+ if (values_to_decode > 0) {
+ RETURN_NOT_OK(indices_scratch_space_->TypedResize<int32_t>(
+ values_to_decode, /*shrink_to_fit=*/false));
+ }
+ auto* decoded_indices =
indices_scratch_space_->mutable_data_as<int32_t>();
+ const int num_indices = idx_decoder_.GetBatch(decoded_indices,
values_to_decode);
+ if (ARROW_PREDICT_FALSE(num_indices != values_to_decode)) {
+ return Status::Invalid("Invalid number of indices: ", num_indices);
+ }
+
+ int64_t data_length = 0;
+ for (int i = 0; i < values_to_decode; ++i) {
+ const auto index = decoded_indices[i];
+ RETURN_NOT_OK(IndexInBounds(index));
+ if (ARROW_PREDICT_FALSE(AddWithOverflow(
+ data_length, static_cast<int64_t>(dict_values[index].len),
+ &data_length))) {
+ return Status::Invalid(
+ "excess expansion while decoding dictionary-encoded
BYTE_ARRAY");
+ }
+ }
+
+ auto append_predecoded = [&](auto* helper) {
+ int values_decoded = 0;
+ int pos_indices = 0;
+ int64_t remaining_data_length = data_length;
+
+ RETURN_NOT_OK(VisitBitRuns(
+ valid_bits, valid_bits_offset, num_values,
+ [&](int64_t position, int64_t length, bool valid) {
+ if (valid) {
+ for (int64_t i = 0; i < length; ++i) {
+ const auto& val =
dict_values[decoded_indices[pos_indices++]];
+ RETURN_NOT_OK(helper->AppendValue(
+ val.ptr, static_cast<int32_t>(val.len),
remaining_data_length));
+ remaining_data_length -= val.len;
+ }
+ values_decoded += static_cast<int>(length);
+ } else {
+ for (int64_t i = 0; i < length; ++i) {
+ helper->UnsafeAppendNull();
+ }
+ }
Review Comment:
Null runs are appended one value at a time with UnsafeAppendNull(), which
adds avoidable overhead for large null runs (notably in the new 10%/50% null
benchmarks). Use the helper’s bulk AppendNulls() instead.
--
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]