You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@drill.apache.org by GitBox <gi...@apache.org> on 2018/08/04 17:16:14 UTC

[GitHub] ilooner closed pull request #1395: DRILL-6629 BitVector split and transfer does not work correctly for transfer length < 8

ilooner closed pull request #1395: DRILL-6629 BitVector split and transfer does not work correctly for transfer length < 8
URL: https://github.com/apache/drill/pull/1395
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

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 057fa131804..96dbd7caa2b 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 void test() throws Exception {
   @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 void testBitVectorUnalignedStart() throws Exception {
   @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 0dd34f51ef0..a6b87378d75 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 void splitAndTransferTo(int startIndex, int length, BitVector target) {
       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.


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services