Skip to content

Commit

Permalink
[Update] Fix comment
Browse files Browse the repository at this point in the history
  • Loading branch information
mapleFU committed Aug 2, 2023
1 parent 961e255 commit 85749de
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 34 deletions.
3 changes: 2 additions & 1 deletion cpp/src/parquet/encoding.cc
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,8 @@ class PlainEncoder<BooleanType> : public EncoderImpl, virtual public BooleanEnco
throw ParquetException("direct put to boolean from " + values.type()->ToString() +
" not supported");
}
// Put arrow array cannot mix with PlainEncoder<BooleanType>::PutImpl.
// Cannot Put arrow array when PlainEncoder<BooleanType>::PutImpl has remaining writes
// in `bit_writer_`.
DCHECK_EQ(0, bit_writer_.bytes_written());

const auto& data = checked_cast<const ::arrow::BooleanArray&>(values);
Expand Down
50 changes: 17 additions & 33 deletions cpp/src/parquet/encoding_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -642,54 +642,38 @@ class EncodingAdHocTyped : public ::testing::Test {

static std::shared_ptr<::arrow::DataType> arrow_type();

void Plain(int seed) {
auto values = GetValues(seed);
void Plain(int seed, int round = 1) {
auto random_array = GetValues(seed);
auto encoder = MakeTypedEncoder<ParquetType>(
Encoding::PLAIN, /*use_dictionary=*/false, column_descr());
auto decoder = MakeTypedDecoder<ParquetType>(Encoding::PLAIN, column_descr());

ASSERT_NO_THROW(encoder->Put(*values));
auto buf = encoder->FlushValues();

int num_values = static_cast<int>(values->length() - values->null_count());
decoder->SetData(num_values, buf->data(), static_cast<int>(buf->size()));

BuilderType acc(arrow_type(), ::arrow::default_memory_pool());
ASSERT_EQ(num_values,
decoder->DecodeArrow(static_cast<int>(values->length()),
static_cast<int>(values->null_count()),
values->null_bitmap_data(), values->offset(), &acc));

std::shared_ptr<::arrow::Array> result;
ASSERT_OK(acc.Finish(&result));
ASSERT_EQ(50, result->length());
::arrow::AssertArraysEqual(*values, *result, /*verbose=*/true);
}

void PlainTwice(int seed) {
auto values_single = GetValues(seed);
auto encoder = MakeTypedEncoder<ParquetType>(
Encoding::PLAIN, /*use_dictionary=*/false, column_descr());
auto decoder = MakeTypedDecoder<ParquetType>(Encoding::PLAIN, column_descr());

ASSERT_NO_THROW(encoder->Put(*values_single));
ASSERT_NO_THROW(encoder->Put(*values_single));
for (int i = 0; i < round; ++i) {
ASSERT_NO_THROW(encoder->Put(*random_array));
}
std::shared_ptr<::arrow::Array> values;
if (round == 1) {
values = random_array;
} else {
::arrow::ArrayVector arrays;
arrays.resize(round, random_array);
EXPECT_OK_AND_ASSIGN(values,
::arrow::Concatenate(arrays, ::arrow::default_memory_pool()));
}
auto buf = encoder->FlushValues();

EXPECT_OK_AND_ASSIGN(auto values,
::arrow::Concatenate({values_single, values_single}));
decoder->SetData(static_cast<int>(values->length()), buf->data(),
static_cast<int>(buf->size()));

BuilderType acc(arrow_type(), ::arrow::default_memory_pool());
ASSERT_EQ(values->length() - values->null_count(),
ASSERT_EQ(static_cast<int>(values->length() - values->null_count()),
decoder->DecodeArrow(static_cast<int>(values->length()),
static_cast<int>(values->null_count()),
values->null_bitmap_data(), values->offset(), &acc));

std::shared_ptr<::arrow::Array> result;
ASSERT_OK(acc.Finish(&result));
ASSERT_EQ(100, result->length());
ASSERT_EQ(values->length(), result->length());
::arrow::AssertArraysEqual(*values, *result, /*verbose=*/true);
}

Expand Down Expand Up @@ -912,7 +896,7 @@ TYPED_TEST(EncodingAdHocTyped, PlainArrowDirectPut) {

TYPED_TEST(EncodingAdHocTyped, PlainArrowDirectPut2) {
for (auto seed : {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}) {
this->PlainTwice(seed);
this->Plain(seed, /*round=*/5);
}
}

Expand Down

0 comments on commit 85749de

Please sign in to comment.