Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 25 additions & 11 deletions cpp/src/parquet/encoder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -151,15 +151,28 @@ class PlainEncoder : public EncoderImpl, virtual public TypedEncoder<DType> {

void PutSpaced(const T* src, int num_values, const uint8_t* valid_bits,
int64_t valid_bits_offset) override {
if (valid_bits != NULLPTR) {
PARQUET_ASSIGN_OR_THROW(auto buffer, ::arrow::AllocateBuffer(num_values * sizeof(T),
this->memory_pool()));
T* data = buffer->template mutable_data_as<T>();
int num_valid_values = ::arrow::util::internal::SpacedCompress<T>(
src, num_values, valid_bits, valid_bits_offset, data);
Put(data, num_valid_values);
if (valid_bits == nullptr || num_values == 0) {
return Put(src, num_values);
}
if constexpr (::arrow::internal::IsOneOf<T, ByteArray, FLBA>::value) {
// Binary input contains descriptors; Put encodes the bytes they reference.
::arrow::internal::VisitSetBitRunsVoid(valid_bits, valid_bits_offset, num_values,
[&](int64_t start, int64_t length) {
Put(src + start, static_cast<int>(length));
});
} else {
Put(src, num_values);
// Compact directly into the page, reserving only space for present values.
const int64_t count =
::arrow::internal::CountSetBits(valid_bits, valid_bits_offset, num_values);
if (count == 0) {
return;
}
const int64_t bytes = count * static_cast<int64_t>(sizeof(T));
PARQUET_THROW_NOT_OK(sink_.Reserve(bytes));
T* out = reinterpret_cast<T*>(sink_.mutable_data() + sink_.length());
::arrow::util::internal::SpacedCompress(src, num_values, valid_bits,
valid_bits_offset, out);
sink_.UnsafeAdvance(bytes);
}
}

Expand Down Expand Up @@ -327,13 +340,14 @@ inline void PlainEncoder<FLBAType>::Put(const ::arrow::Array& values) {

template <>
inline void PlainEncoder<FLBAType>::Put(const FixedLenByteArray* src, int num_values) {
if (descr_->type_length() == 0) {
const int64_t byte_width = descr_->type_length();
if (byte_width == 0) {
return;
}
PARQUET_THROW_NOT_OK(sink_.Reserve(num_values * byte_width));
for (int i = 0; i < num_values; ++i) {
// Write the result to the output stream
DCHECK(src[i].ptr != nullptr) << "Value ptr cannot be NULL";
PARQUET_THROW_NOT_OK(sink_.Append(src[i].ptr, descr_->type_length()));
sink_.UnsafeAppend(src[i].ptr, byte_width);
}
}

Expand Down
Loading