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

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


The following commit(s) were added to refs/heads/master by this push:
     new a544033  DRILL-6629 BitVector split and transfer does not work 
correctly for transfer length < 8
a544033 is described below

commit a5440331bcd87b6f6fc27e3202f95d8fdf0da5e1
Author: karthik <[email protected]>
AuthorDate: Mon Jul 23 16:28:49 2018 -0700

    DRILL-6629 BitVector split and transfer does not work correctly for 
transfer length < 8
    
    closes #1395
---
 .../drill/exec/vector/TestSplitAndTransfer.java    | 26 ++++++++++++++++++++++
 .../org/apache/drill/exec/vector/BitVector.java    |  8 ++++++-
 2 files changed, 33 insertions(+), 1 deletion(-)

diff --git 
a/exec/java-exec/src/test/java/org/apache/drill/exec/vector/TestSplitAndTransfer.java
 
b/exec/java-exec/src/test/java/org/apache/drill/exec/vector/TestSplitAndTransfer.java
index 057fa13..96dbd7c 100644
--- 
a/exec/java-exec/src/test/java/org/apache/drill/exec/vector/TestSplitAndTransfer.java
+++ 
b/exec/java-exec/src/test/java/org/apache/drill/exec/vector/TestSplitAndTransfer.java
@@ -94,6 +94,21 @@ public class TestSplitAndTransfer {
   @Test
   public void testBitVectorUnalignedStart() throws Exception {
 
+    testBitVectorImpl(16, new int[][] {{2, 4}}, TestBitPattern.RANDOM);
+    testBitVectorImpl(16, new int[][] {{2, 4}}, TestBitPattern.ONE);
+    testBitVectorImpl(16, new int[][] {{2, 4}}, TestBitPattern.ZERO);
+    testBitVectorImpl(16, new int[][] {{2, 4}}, TestBitPattern.ALTERNATING);
+
+    testBitVectorImpl(4096, new int[][] {{4092, 4}}, TestBitPattern.ONE);
+    testBitVectorImpl(4096, new int[][] {{4092, 4}}, TestBitPattern.ZERO);
+    testBitVectorImpl(4096, new int[][] {{4092, 4}}, 
TestBitPattern.ALTERNATING);
+    testBitVectorImpl(4096, new int[][] {{4092, 4}}, TestBitPattern.RANDOM);
+
+    testBitVectorImpl(4096, new int[][] {{1020, 8}}, TestBitPattern.ONE);
+    testBitVectorImpl(4096, new int[][] {{1020, 8}}, TestBitPattern.ZERO);
+    testBitVectorImpl(4096, new int[][] {{1020, 8}}, 
TestBitPattern.ALTERNATING);
+    testBitVectorImpl(4096, new int[][] {{1020, 8}}, TestBitPattern.RANDOM);
+
     testBitVectorImpl(24, new int[][] {{5, 17}}, TestBitPattern.ONE);
     testBitVectorImpl(24, new int[][] {{5, 17}}, TestBitPattern.ZERO);
     testBitVectorImpl(24, new int[][] {{5, 17}}, TestBitPattern.ALTERNATING);
@@ -113,6 +128,17 @@ public class TestSplitAndTransfer {
   @Test
   public void testBitVectorAlignedStart() throws Exception {
 
+    testBitVectorImpl(32, new int[][] {{0, 4}}, TestBitPattern.RANDOM);
+    testBitVectorImpl(32, new int[][] {{0, 4}}, TestBitPattern.ONE);
+    testBitVectorImpl(32, new int[][] {{0, 4}}, TestBitPattern.ZERO);
+    testBitVectorImpl(32, new int[][] {{0, 4}}, TestBitPattern.ALTERNATING);
+
+
+    testBitVectorImpl(32, new int[][] {{0, 8}}, TestBitPattern.ONE);
+    testBitVectorImpl(32, new int[][] {{0, 8}}, TestBitPattern.ZERO);
+    testBitVectorImpl(32, new int[][] {{0, 8}}, TestBitPattern.ALTERNATING);
+    testBitVectorImpl(32, new int[][] {{0, 8}}, TestBitPattern.RANDOM);
+
     testBitVectorImpl(24, new int[][] {{0, 17}}, TestBitPattern.ONE);
     testBitVectorImpl(24, new int[][] {{0, 17}}, TestBitPattern.ZERO);
     testBitVectorImpl(24, new int[][] {{0, 17}}, TestBitPattern.ALTERNATING);
diff --git 
a/exec/vector/src/main/java/org/apache/drill/exec/vector/BitVector.java 
b/exec/vector/src/main/java/org/apache/drill/exec/vector/BitVector.java
index 0dd34f5..a6b8737 100644
--- a/exec/vector/src/main/java/org/apache/drill/exec/vector/BitVector.java
+++ b/exec/vector/src/main/java/org/apache/drill/exec/vector/BitVector.java
@@ -323,8 +323,14 @@ public final class BitVector extends BaseDataValueVector 
implements FixedWidthVe
       if (length % 8 != 0) {
         // start is not byte aligned so we have to copy some bits from the 
last full byte read in the
         // previous loop
-        byte lastButOneByte = byteIPlus1;
+        // if numBytesHoldingSourceBits == 1, lastButOneByte is the first 
byte, but we have not read it yet, so read it
+        byte lastButOneByte = (numBytesHoldingSourceBits == 1) ? 
this.data.getByte(firstByteIndex) : byteIPlus1;
         byte bitsFromLastButOneByte = (byte)((lastButOneByte & 0xFF) >>> 
firstBitOffset);
+        // if last bit to be copied is before the end of the first byte, then 
mask of the trailing extra bits
+        if (8 > (length + firstBitOffset)) {
+          byte mask = (byte)((0x1 << length) - 1);
+          bitsFromLastButOneByte = (byte)((bitsFromLastButOneByte & mask));
+        }
 
         // If we have to read more bits than what we have already read, read 
it into lastByte otherwise set lastByte to 0.
         // (length % 8) is num of remaining bits to be read.

Reply via email to