You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2020/08/04 09:28:42 UTC

[GitHub] [arrow] liyafan82 commented on a change in pull request #7817: ARROW-9377: [Java] Support unsigned dictionary indices

liyafan82 commented on a change in pull request #7817:
URL: https://github.com/apache/arrow/pull/7817#discussion_r464922151



##########
File path: java/vector/src/test/java/org/apache/arrow/vector/TestDictionaryVector.java
##########
@@ -878,6 +880,103 @@ public void testEncodeStructSubFieldWithCertainColumns() {
     }
   }
 
+  private void testDictionary(Dictionary dictionary, ToIntBiFunction<ValueVector, Integer> valGetter) {
+    try (VarCharVector vector = new VarCharVector("vector", allocator)) {
+      setVector(vector, "1", "3", "5", "7", "9");
+      try (ValueVector encodedVector = DictionaryEncoder.encode(vector, dictionary)) {
+
+        // verify encoded result
+        assertEquals(vector.getValueCount(), encodedVector.getValueCount());
+        assertEquals(valGetter.applyAsInt(encodedVector, 0), 1);
+        assertEquals(valGetter.applyAsInt(encodedVector, 1), 3);
+        assertEquals(valGetter.applyAsInt(encodedVector, 2), 5);
+        assertEquals(valGetter.applyAsInt(encodedVector, 3), 7);
+        assertEquals(valGetter.applyAsInt(encodedVector, 4), 9);
+
+        try (ValueVector decodedVector = DictionaryEncoder.decode(encodedVector, dictionary)) {
+          assertTrue(decodedVector instanceof VarCharVector);
+          assertEquals(vector.getValueCount(), decodedVector.getValueCount());
+          assertArrayEquals("1".getBytes(), ((VarCharVector) decodedVector).get(0));
+          assertArrayEquals("3".getBytes(), ((VarCharVector) decodedVector).get(1));
+          assertArrayEquals("5".getBytes(), ((VarCharVector) decodedVector).get(2));
+          assertArrayEquals("7".getBytes(), ((VarCharVector) decodedVector).get(3));
+          assertArrayEquals("9".getBytes(), ((VarCharVector) decodedVector).get(4));
+        }
+      }
+    }
+  }
+
+  @Test
+  public void testDictionaryUInt1() {
+    try (VarCharVector dictionaryVector = new VarCharVector("dict vector", allocator)) {
+      setVector(dictionaryVector, "0", "1", "2", "3", "4", "5", "6", "7", "8", "9");
+      Dictionary dictionary1 = new Dictionary(dictionaryVector,
+          new DictionaryEncoding(/*id=*/10L, /*ordered=*/false, /*indexType=*/ new ArrowType.Int(8, false)));

Review comment:
       Parameter comments added. Thanks for your kind reminder. 




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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