[ 
https://issues.apache.org/jira/browse/DRILL-6486?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16514451#comment-16514451
 ] 

ASF GitHub Bot commented on DRILL-6486:
---------------------------------------

sohami commented on a change in pull request #1316: DRILL-6486: BitVector split 
and transfer does not work correctly for non byte-multiple transfer lengths
URL: https://github.com/apache/drill/pull/1316#discussion_r195875431
 
 

 ##########
 File path: 
exec/java-exec/src/test/java/org/apache/drill/exec/vector/TestSplitAndTransfer.java
 ##########
 @@ -77,4 +79,102 @@ public void test() throws Exception {
     varCharVector.close();
     allocator.close();
   }
+
+  /**
+   *  BitVector tests
+   */
+
+  enum TestBitPattern {
+    ZERO,
+    ONE,
+    ALTERNATING,
+    RANDOM
+  }
+
+  @Test
+  public void testBitVectorUnalignedStart() throws Exception {
+
+    testBitVectorImpl(24, new int[][] {{5, 17}}, TestBitPattern.ONE);
+    testBitVectorImpl(24, new int[][] {{5, 17}}, TestBitPattern.ZERO);
+    testBitVectorImpl(24, new int[][] {{5, 17}}, TestBitPattern.ALTERNATING);
+    testBitVectorImpl(24, new int[][] {{5, 17}}, TestBitPattern.RANDOM);
+
+    testBitVectorImpl(3443, new int[][] {{0, 2047}, {2047, 1396}}, 
TestBitPattern.ZERO);
+    testBitVectorImpl(3443, new int[][] {{0, 2047}, {2047, 1396}}, 
TestBitPattern.ONE);
+    testBitVectorImpl(3443, new int[][] {{0, 2047}, {2047, 1396}}, 
TestBitPattern.ALTERNATING);
+    testBitVectorImpl(3443, new int[][] {{0, 2047}, {2047, 1396}}, 
TestBitPattern.RANDOM);
+
+    testBitVectorImpl(3447, new int[][] {{0, 2047}, {2047, 1400}}, 
TestBitPattern.ZERO);
+    testBitVectorImpl(3447, new int[][] {{0, 2047}, {2047, 1400}}, 
TestBitPattern.ONE);
+    testBitVectorImpl(3447, new int[][] {{0, 2047}, {2047, 1400}}, 
TestBitPattern.ALTERNATING);
+    testBitVectorImpl(3447, new int[][] {{0, 2047}, {2047, 1400}}, 
TestBitPattern.RANDOM);
+  }
+
+  @Test
+  public void testBitVectorAlignedStart() throws Exception {
+
+    testBitVectorImpl(24, new int[][] {{0, 17}}, TestBitPattern.ONE);
+    testBitVectorImpl(24, new int[][] {{0, 17}}, TestBitPattern.ZERO);
+    testBitVectorImpl(24, new int[][] {{0, 17}}, TestBitPattern.ALTERNATING);
+    testBitVectorImpl(24, new int[][] {{0, 17}}, TestBitPattern.RANDOM);
+
+    testBitVectorImpl(3444, new int[][] {{0, 2048}, {2048, 1396}}, 
TestBitPattern.ZERO);
+    testBitVectorImpl(3444, new int[][] {{0, 2048}, {2048, 1396}}, 
TestBitPattern.ONE);
+    testBitVectorImpl(3444, new int[][] {{0, 2048}, {2048, 1396}}, 
TestBitPattern.ALTERNATING);
+    testBitVectorImpl(3444, new int[][] {{0, 2048}, {2048, 1396}}, 
TestBitPattern.RANDOM);
+
+    testBitVectorImpl(3448, new int[][] {{0, 2048}, {2048, 1400}}, 
TestBitPattern.ZERO);
+    testBitVectorImpl(3448, new int[][] {{0, 2048}, {2048, 1400}}, 
TestBitPattern.ONE);
+    testBitVectorImpl(3448, new int[][] {{0, 2048}, {2048, 1400}}, 
TestBitPattern.ALTERNATING);
+    testBitVectorImpl(3448, new int[][] {{0, 2048}, {2048, 1400}}, 
TestBitPattern.RANDOM);
+  }
+
+  int getBit(TestBitPattern pattern, int index) {
+    if (pattern == TestBitPattern.RANDOM) {
+      return (int) (Math.random() * 2);
+    }
+    return (pattern == TestBitPattern.ALTERNATING) ? (index % 2) : ((pattern 
== TestBitPattern.ONE) ? 1 : 0);
+  }
+
+  public void testBitVectorImpl(int valueCount, final int[][] startLengths, 
TestBitPattern pattern) throws Exception {
+    final DrillConfig drillConfig = DrillConfig.create();
+    final BufferAllocator allocator = 
RootAllocatorFactory.newRoot(drillConfig);
+    final MaterializedField field = MaterializedField.create("field", 
Types.optional(MinorType.BIT));
+    final BitVector bitVector = new BitVector(field, allocator);
+    bitVector.allocateNew(valueCount  + 8); // extra byte at the end that gets 
filled with junk
+    final int[] compareArray = new int[valueCount];
+
+    int testBitValue = 0 ;
+    final BitVector.Mutator mutator = bitVector.getMutator();
+    for (int i = 0; i < valueCount; i ++) {
+      testBitValue = getBit(pattern, i);
+      mutator.set(i, testBitValue);
+      compareArray[i] = testBitValue;
+    }
+
+    // write some junk value at the end to catch
+    // off-by-one out-of-bound reads
+    for (int j = valueCount; j < valueCount + 8; j++) {
+      mutator.set(j, ~testBitValue); // fill with compliment of testBit
+    }
+    mutator.setValueCount(valueCount);
+
+    final TransferPair tp = bitVector.getTransferPair(allocator);
+    final BitVector newBitVector = (BitVector) tp.getTo();
+    final BitVector.Accessor accessor = newBitVector.getAccessor();
+
+    for (final int[] startLength : startLengths) {
+      final int start = startLength[0];
+      final int length = startLength[1];
+      tp.splitAndTransfer(start, length);
+      newBitVector.getMutator().setValueCount(length);
 
 Review comment:
   instead of `setValueCount` in test I think we should check if 
`splitAndTransfer` is setting it correctly or not ?

----------------------------------------------------------------
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:
us...@infra.apache.org


> BitVector split and transfer does not work correctly for non byte-multiple 
> transfer lengths
> -------------------------------------------------------------------------------------------
>
>                 Key: DRILL-6486
>                 URL: https://issues.apache.org/jira/browse/DRILL-6486
>             Project: Apache Drill
>          Issue Type: Bug
>          Components: Execution - Data Types
>    Affects Versions: 1.13.0
>            Reporter: Karthikeyan Manivannan
>            Assignee: Karthikeyan Manivannan
>            Priority: Major
>             Fix For: 1.14.0
>
>         Attachments: TestSplitAndTransfer.java
>
>   Original Estimate: 24h
>  Remaining Estimate: 24h
>
> BitVector splitAndTransfer does not correctly handle transfers where the 
> transfer-length is not a multiple of 8. The attached bitVector tests will 
> expose this problem. 



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to