You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@orc.apache.org by ga...@apache.org on 2019/04/29 17:42:36 UTC

[orc] branch master updated: ORC-370:[C++] Reset BooleanRleDecoder remainingbits to zero on seek

This is an automated email from the ASF dual-hosted git repository.

gangwu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/orc.git


The following commit(s) were added to refs/heads/master by this push:
     new 44a6002  ORC-370:[C++] Reset BooleanRleDecoder remainingbits to zero on seek
44a6002 is described below

commit 44a6002f55efc03e4a73384706d6c87ade1c593b
Author: Yurui Zhou <gi...@yuruiz.com>
AuthorDate: Tue Apr 30 01:42:31 2019 +0800

    ORC-370:[C++] Reset BooleanRleDecoder remainingbits to zero on seek
    
    This closes #388
---
 c++/src/ByteRLE.cc      |  1 +
 c++/test/TestByteRle.cc | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 50 insertions(+)

diff --git a/c++/src/ByteRLE.cc b/c++/src/ByteRLE.cc
index 5fbd4a5..ee1a457 100644
--- a/c++/src/ByteRLE.cc
+++ b/c++/src/ByteRLE.cc
@@ -521,6 +521,7 @@ namespace orc {
   void BooleanRleDecoderImpl::seek(PositionProvider& location) {
     ByteRleDecoderImpl::seek(location);
     uint64_t consumed = location.next();
+    remainingBits = 0;
     if (consumed > 8) {
       throw ParseError("bad position");
     }
diff --git a/c++/test/TestByteRle.cc b/c++/test/TestByteRle.cc
index bc19e07..65d1551 100644
--- a/c++/test/TestByteRle.cc
+++ b/c++/test/TestByteRle.cc
@@ -1462,4 +1462,53 @@ TEST(BooleanRle, seekBoolAndByteRLE) {
     EXPECT_ANY_THROW(decoder->next(data, 1, nullptr));
   }
 
+
+
+  TEST(BooleanRle, testSeekWithRemainBitNotZero) {
+    MemoryOutputStream memStream(1024 * 1024);
+
+    uint64_t capacity = 500 * 1024;
+    uint64_t block = 1024;
+    std::unique_ptr<BufferedOutputStream> outStream(
+            new BufferedOutputStream(*getDefaultPool(), &memStream, capacity, block));
+
+    std::unique_ptr<ByteRleEncoder> encoder =
+            createBooleanRleEncoder(std::move(outStream));
+
+    uint64_t numValues = 1779;
+    char * data = new char[numValues];
+    for (uint64_t i = 0; i < numValues; ++i) {
+      data[i] = static_cast<char>(i % 2);
+    }
+    encoder->add(data, numValues, nullptr);
+    encoder->flush();
+
+    std::unique_ptr<SeekableInputStream> inStream(
+            new SeekableArrayInputStream(memStream.getData(), memStream.getLength()));
+
+    std::unique_ptr<ByteRleDecoder> decoder =
+            createBooleanRleDecoder(std::move(inStream));
+
+    char* decodedData = new char[numValues];
+    decoder->next(decodedData, 9, nullptr);
+
+    for (uint64_t i = 0; i < 9; ++i) {
+      bool expect = data[i] != 0;
+      bool actual = decodedData[i] != 0;
+      EXPECT_EQ(expect, actual) << "Output wrong at " << i;
+    }
+
+    std::list<uint64_t> positions = {0, 0, 0};
+    PositionProvider positionProvider(positions);
+    decoder->seek(positionProvider);
+    decoder->next(decodedData, numValues, nullptr);
+    for (uint64_t i = 0; i < numValues; ++i) {
+      bool expect = data[i] != 0;
+      bool actual = decodedData[i] != 0;
+      EXPECT_EQ(expect, actual)
+                    << "Output wrong at " << i;
+    }
+
+    delete [] decodedData;
+  }
 }  // namespace orc