rok commented on code in PR #14341:
URL: https://github.com/apache/arrow/pull/14341#discussion_r1269606757


##########
cpp/src/parquet/encoding.cc:
##########
@@ -1238,43 +1240,62 @@ int PlainBooleanDecoder::Decode(bool* buffer, int 
max_values) {
   return max_values;
 }
 
-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();
+template <typename DType, typename Enable = void>
+struct ArrowBinaryHelper;
+
+template <typename DType>
+struct ArrowBinaryHelper<DType, std::enable_if_t<std::is_same_v<DType, 
ByteArrayType> ||
+                                                     std::is_same_v<DType, 
FLBAType>,
+                                                 void>> {
+  explicit ArrowBinaryHelper(typename EncodingTraits<DType>::Accumulator* acc) 
{
+    builder = acc->builder.get();
+    chunks = &acc->chunks;
+    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(std::move(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) {
-    chunk_space_remaining -= length;
-    return builder->Append(data, length);
-  }
+  virtual Status Append(const uint8_t* data, int32_t length);

Review Comment:
   Removed `virtual`.



-- 
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]

Reply via email to