mapleFU commented on code in PR #14293:
URL: https://github.com/apache/arrow/pull/14293#discussion_r1053558528


##########
cpp/src/parquet/encoding.cc:
##########
@@ -2537,6 +2537,100 @@ class DeltaBitPackDecoder : public DecoderImpl, virtual 
public TypedDecoder<DTyp
 // ----------------------------------------------------------------------
 // DELTA_LENGTH_BYTE_ARRAY
 
+// ----------------------------------------------------------------------
+// DeltaLengthByteArrayEncoder
+
+class DeltaLengthByteArrayEncoder : public EncoderImpl,
+                                    virtual public TypedEncoder<ByteArrayType> 
{
+ public:
+  using T = typename ByteArrayType::c_type;
+
+  explicit DeltaLengthByteArrayEncoder(const ColumnDescriptor* descr, 
MemoryPool* pool)
+      : EncoderImpl(descr, Encoding::DELTA_LENGTH_BYTE_ARRAY,
+                    pool = ::arrow::default_memory_pool()),
+        sink_(pool),
+        length_encoder_(nullptr, pool),
+        encoded_size_{0},
+        lengths_{0} {}
+
+  std::shared_ptr<Buffer> FlushValues() override;
+
+  int64_t EstimatedDataEncodedSize() override { return encoded_size_; }
+
+  using TypedEncoder<ByteArrayType>::Put;
+
+  void Put(const ::arrow::Array& values) override;
+
+  void Put(const T* buffer, int num_values) override;
+
+  void PutSpaced(const T* src, int num_values, const uint8_t* valid_bits,
+                 int64_t valid_bits_offset) override;
+
+ protected:
+  ::arrow::BufferBuilder sink_;
+  DeltaBitPackEncoder<Int32Type> length_encoder_;
+  uint32_t encoded_size_;
+  std::vector<int32_t> lengths_;
+};
+
+void DeltaLengthByteArrayEncoder::Put(const ::arrow::Array& values) {
+  auto src = values.data()->GetValues<ByteArray>(1);
+  Put(src, static_cast<int>(values.length()));
+}
+
+void DeltaLengthByteArrayEncoder::Put(const T* src, int num_values) {
+  if (num_values == 0) {
+    return;
+  }
+  lengths_.resize(num_values);

Review Comment:
   > Let's stare back a bit. You don't _need_ a lengths variable at all.
   
   Sorry for do the misleading. I just want to make clear our code style. But I 
think here are two ways:
   
   method1:
   
   ```
   for every bytes:
      (temp variable) length = bytes.length
      Put(&length, 1)
   ```
   
   or  method2
   
   ```
   Copy all lengths to a vector
   Put(vec.data(), vec.size());
   ```
   
   Seems that we prefer the method2 here?
   
   And when should we buffer the vector values, like `deltas_`? And when should 
we just create a vector? Seems there would be a `sizeof(variable) * BatchSize` 
of memory allocation.
   
   By the way, I found there are both `ArrowPoolVector` (with arrow allocator) 
and `std::vector` (with std allocator), when should we use them? @pitrou 



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