rok commented on code in PR #14341:
URL: https://github.com/apache/arrow/pull/14341#discussion_r1300188563
##########
cpp/src/parquet/encoding.cc:
##########
@@ -1238,40 +1240,54 @@ int PlainBooleanDecoder::Decode(bool* buffer, int
max_values) {
return max_values;
}
+template <typename DType>
struct ArrowBinaryHelper {
- explicit ArrowBinaryHelper(typename
EncodingTraits<ByteArrayType>::Accumulator* out) {
- this->out = out;
- this->builder = out->builder.get();
- this->chunk_space_remaining =
- ::arrow::kBinaryMemoryLimit - this->builder->value_data_length();
+ explicit ArrowBinaryHelper(typename EncodingTraits<DType>::Accumulator* acc)
{
+ if constexpr (std::is_same_v<DType, ByteArrayType>) {
+ builder = acc->builder.get();
+ chunks = &acc->chunks;
+ } else {
+ builder = acc;
+ }
+ if (ARROW_PREDICT_FALSE(SubtractWithOverflow(::arrow::kBinaryMemoryLimit,
+ builder->value_data_length(),
+ &chunk_space_remaining))) {
+ throw ParquetException("excess expansion in ArrowBinaryHelper<DType>");
+ }
}
Status PushChunk() {
std::shared_ptr<::arrow::Array> result;
RETURN_NOT_OK(builder->Finish(&result));
- out->chunks.push_back(result);
+ chunks->push_back(result);
chunk_space_remaining = ::arrow::kBinaryMemoryLimit;
return Status::OK();
}
bool CanFit(int64_t length) const { return length <= chunk_space_remaining; }
void UnsafeAppend(const uint8_t* data, int32_t length) {
+ DCHECK(CanFit(length));
chunk_space_remaining -= length;
builder->UnsafeAppend(data, length);
}
void UnsafeAppendNull() { builder->UnsafeAppendNull(); }
Status Append(const uint8_t* data, int32_t length) {
+ DCHECK(CanFit(length));
chunk_space_remaining -= length;
- return builder->Append(data, length);
+ if constexpr (std::is_same_v<DType, FLBAType>) {
+ return builder->Append(data);
+ } else {
+ return builder->Append(data, length);
+ }
}
Status AppendNull() { return builder->AppendNull(); }
- typename EncodingTraits<ByteArrayType>::Accumulator* out;
- ::arrow::BinaryBuilder* builder;
+ typename EncodingTraits<DType>::BuilderType* builder;
+ std::vector<std::shared_ptr<::arrow::Array>>* chunks;
Review Comment:
How about we raise here until the fix?
--
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]