pitrou commented on code in PR #14293: URL: https://github.com/apache/arrow/pull/14293#discussion_r1053561535
########## 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: Yes... but now I realize that putting values one by one to the `length_encoder_` might be quite suboptimal. The best compromise might be to use a small stack-allocated buffer, e.g. (untested): ```c++ void DeltaLengthByteArrayEncoder::Put(const T* src, int num_values) { [...] constexpr int kBatchSize = 256; std::array<int32_t, kBatchSize> lengths; for (int idx = 0; idx < num_values; idx += kBatchSize) { const int batch_size = std::min(kBatchSize, num_values - idx); for (int j = 0; j < batch_size; ++j) { const int32_t len = src[idx].len; encoded_size_ += len; lengths[j] = len; } length_encoder_.Put(lengths.data(), batch_size); } [...] ``` -- 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: github-unsubscr...@arrow.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org