Skip to content
Open
Show file tree
Hide file tree
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
15 changes: 9 additions & 6 deletions cpp/src/parquet/encoder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1385,8 +1385,7 @@ class DeltaLengthByteArrayEncoder : public EncoderImpl,
virtual public TypedEncoder<ByteArrayType> {
public:
explicit DeltaLengthByteArrayEncoder(const ColumnDescriptor* descr, MemoryPool* pool)
: EncoderImpl(descr, Encoding::DELTA_LENGTH_BYTE_ARRAY,
pool = ::arrow::default_memory_pool()),
: EncoderImpl(descr, Encoding::DELTA_LENGTH_BYTE_ARRAY, pool),
sink_(pool),
length_encoder_(nullptr, pool) {}

Expand Down Expand Up @@ -1469,11 +1468,15 @@ void DeltaLengthByteArrayEncoder::Put(const T* src, int num_values) {
if (sink_.length() + total_increment_size > std::numeric_limits<int32_t>::max()) {
throw ParquetException("excess expansion in DELTA_LENGTH_BYTE_ARRAY");
}
PARQUET_THROW_NOT_OK(sink_.Reserve(total_increment_size));
for (int idx = 0; idx < num_values; idx++) {
sink_.UnsafeAppend(src[idx].ptr, src[idx].len);
if (total_increment_size > 0) {
PARQUET_THROW_NOT_OK(sink_.Reserve(total_increment_size));
for (int idx = 0; idx < num_values; idx++) {
if (src[idx].len > 0) {
sink_.UnsafeAppend(src[idx].ptr, src[idx].len);
}
}
unencoded_byte_array_data_bytes_ += total_increment_size;
}
unencoded_byte_array_data_bytes_ += total_increment_size;
}

void DeltaLengthByteArrayEncoder::PutSpaced(const T* src, int num_values,
Expand Down
28 changes: 28 additions & 0 deletions cpp/src/parquet/encoding_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2480,6 +2480,34 @@ TEST(DeltaLengthByteArrayEncodingAdHoc, ArrowDirectPut) {
}
}

TEST(DeltaLengthByteArrayEncodingAdHoc, ZeroLengthNullPtr) {
auto descr = ExampleDescr<ByteArrayType>();
auto encoder = MakeTypedEncoder<ByteArrayType>(Encoding::DELTA_LENGTH_BYTE_ARRAY,
/*use_dictionary=*/false, descr.get());

std::vector<ByteArray> mixed = {
ByteArray(0, nullptr),
ByteArray("abc"),
ByteArray(0, nullptr),
};
encoder->Put(mixed.data(), static_cast<int>(mixed.size()));
EXPECT_EQ(3, encoder->ReportUnencodedDataBytes());
auto buf = encoder->FlushValues();
EXPECT_EQ(DeltaEncode({0, 3, 0})->ToString() + "abc", buf->ToString());

std::vector<ByteArray> all_zero_null(4, ByteArray(0, nullptr));
encoder->Put(all_zero_null.data(), static_cast<int>(all_zero_null.size()));
EXPECT_EQ(0, encoder->ReportUnencodedDataBytes());
auto zero_buf = encoder->FlushValues();
EXPECT_EQ(DeltaEncode({0, 0, 0, 0})->ToString(), zero_buf->ToString());

const uint8_t valid_bits = 0b00001010; // indices 1 and 3 valid (both 0-len nullptr)
encoder->PutSpaced(all_zero_null.data(), 4, &valid_bits, /*valid_bits_offset=*/0);
EXPECT_EQ(0, encoder->ReportUnencodedDataBytes());
auto spaced_buf = encoder->FlushValues();
EXPECT_EQ(DeltaEncode(std::vector<int32_t>{0, 0})->ToString(), spaced_buf->ToString());
}

// ----------------------------------------------------------------------
// DELTA_BYTE_ARRAY encode/decode tests.

Expand Down
Loading