From e795ad2c750459d7516cdff68960b9de8a58c047 Mon Sep 17 00:00:00 2001 From: Gang Wu Date: Wed, 26 Apr 2017 23:08:16 -0700 Subject: [PATCH 1/3] ORC-181: ByteRleDecoder doesn't seek correctly --- c++/src/ByteRLE.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/c++/src/ByteRLE.cc b/c++/src/ByteRLE.cc index 2c0032cdcd..c34af73e9d 100644 --- a/c++/src/ByteRLE.cc +++ b/c++/src/ByteRLE.cc @@ -118,7 +118,7 @@ namespace orc { // read a new header readHeader(); // skip ahead the given number of records - skip(location.next()); + ByteRleDecoderImpl::skip(location.next()); } void ByteRleDecoderImpl::skip(uint64_t numValues) { From 1ed9936e2ffc4f1cfa98cb3aa869422a3d357b02 Mon Sep 17 00:00:00 2001 From: Gang Wu Date: Fri, 28 Apr 2017 00:14:08 -0700 Subject: [PATCH 2/3] Added a test case --- c++/test/TestByteRle.cc | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/c++/test/TestByteRle.cc b/c++/test/TestByteRle.cc index ecaa504c4e..5200b2f732 100644 --- a/c++/test/TestByteRle.cc +++ b/c++/test/TestByteRle.cc @@ -1382,4 +1382,42 @@ TEST(BooleanRle, seekTestWithNulls) { } while (i != 0); } +TEST(BooleanRle, seekBoolAndByteRLE) { + // ORC-181 + // original data is as follows (1 is true and 0 is false): + // 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, + // 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, + // 0, 0, 1, 1 + // The RLE result is 0xf9, 0xf0, 0xf0, 0xf7, 0x1c, 0x71, 0xc1, 0x80 + // The position of the 21st number (index starts from 0) in the RLE result + // is [0, 2, 5]; the position of the 45th number is [0, 5, 5]. + const char num[] = { + 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, + 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, + 0, 0, 1, 1 + }; + const unsigned char buffer[] = { + 0xf9, 0xf0, 0xf0, 0xf7, 0x1c, 0x71, 0xc1, 0x80 + }; + + std::unique_ptr stream + (new SeekableArrayInputStream(buffer, ARRAY_SIZE(buffer))); + std::unique_ptr rle = + createBooleanRleDecoder(std::move(stream)); + std::vector data(sizeof(num) / sizeof(char)); + rle->next(data.data(), data.size(), nullptr); + for (size_t i = 0; i < data.size(); ++i) { + EXPECT_EQ(num[i], data[i]) << "Output wrong at " << i; + } + + std::list pos21st = {0, 2, 5}, pos45th = {0, 5, 5}; + PositionProvider posProvider21st(pos21st), provider2(pos45th); + char value[1]; + rle->seek(posProvider21st); + rle->next(value, 1, nullptr); + EXPECT_EQ(num[21], value[0]); + rle->seek(provider2); + rle->next(value, 1, nullptr); + EXPECT_EQ(num[45], value[0]); + } } // namespace orc From aa8a24b5672397222680cc7177351447e9e41ede Mon Sep 17 00:00:00 2001 From: Gang Wu Date: Fri, 28 Apr 2017 00:16:42 -0700 Subject: [PATCH 3/3] correct variable name --- c++/test/TestByteRle.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/c++/test/TestByteRle.cc b/c++/test/TestByteRle.cc index 5200b2f732..2c4d4e3d99 100644 --- a/c++/test/TestByteRle.cc +++ b/c++/test/TestByteRle.cc @@ -1411,12 +1411,12 @@ TEST(BooleanRle, seekBoolAndByteRLE) { } std::list pos21st = {0, 2, 5}, pos45th = {0, 5, 5}; - PositionProvider posProvider21st(pos21st), provider2(pos45th); + PositionProvider posProvider21st(pos21st), posProvider45th(pos45th); char value[1]; rle->seek(posProvider21st); rle->next(value, 1, nullptr); EXPECT_EQ(num[21], value[0]); - rle->seek(provider2); + rle->seek(posProvider45th); rle->next(value, 1, nullptr); EXPECT_EQ(num[45], value[0]); }