forked from apache/arrow
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PARQUET-454: Fix inconsistencies with boolean PLAIN encoding
Requires PARQUET-485 (apache#32) The boolean Encoding::PLAIN code path was using RleDecoder, inconsistent with other implementations of Parquet. This patch adds an implementation of plain encoding and uses BitReader instead of RleDecoder to decode plain-encoded boolean data. Unit tests to verify. Also closes PR apache#12. Thanks to @edani for reporting. Author: Wes McKinney <wes@cloudera.com> Closes apache#34 from wesm/PARQUET-454 and squashes the following commits: 01cb5a7 [Wes McKinney] Use a seed in the data generation 0bf5d8a [Wes McKinney] Fix inconsistencies with boolean PLAIN encoding. Change-Id: I1be5252c654d4864d14c3cdd70d63c507e0a9403
- Loading branch information
1 parent
006f38e
commit 9c0066c
Showing
6 changed files
with
144 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// Licensed to the Apache Software Foundation (ASF) under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The ASF licenses this file | ||
// to you under the Apache License, Version 2.0 (the | ||
// "License"); you may not use this file except in compliance | ||
// with the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
#include <cstdint> | ||
#include <string> | ||
#include <vector> | ||
|
||
#include <gtest/gtest.h> | ||
#include "parquet/util/test-common.h" | ||
|
||
#include "parquet/encodings/encodings.h" | ||
|
||
using std::string; | ||
using std::vector; | ||
|
||
namespace parquet_cpp { | ||
|
||
namespace test { | ||
|
||
TEST(BooleanTest, TestEncodeDecode) { | ||
// PARQUET-454 | ||
|
||
size_t nvalues = 100; | ||
size_t nbytes = BitUtil::RoundUp(nvalues, 8) / 8; | ||
|
||
// seed the prng so failure is deterministic | ||
vector<bool> draws = flip_coins_seed(nvalues, 0.5, 0); | ||
|
||
PlainEncoder<Type::BOOLEAN> encoder(nullptr); | ||
PlainDecoder<Type::BOOLEAN> decoder(nullptr); | ||
|
||
std::vector<uint8_t> encode_buffer(nbytes); | ||
|
||
size_t encoded_bytes = encoder.Encode(draws, nvalues, &encode_buffer[0]); | ||
ASSERT_EQ(nbytes, encoded_bytes); | ||
|
||
std::vector<uint8_t> decode_buffer(nbytes); | ||
const uint8_t* decode_data = &decode_buffer[0]; | ||
|
||
decoder.SetData(nvalues, &encode_buffer[0], encoded_bytes); | ||
size_t values_decoded = decoder.Decode(&decode_buffer[0], nvalues); | ||
ASSERT_EQ(nvalues, values_decoded); | ||
|
||
for (size_t i = 0; i < nvalues; ++i) { | ||
ASSERT_EQ(BitUtil::GetArrayBit(decode_data, i), draws[i]) << i; | ||
} | ||
} | ||
|
||
} // namespace test | ||
|
||
} // namespace parquet_cpp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters