vibhatha commented on code in PR #40340:
URL: https://github.com/apache/arrow/pull/40340#discussion_r1565236498
##########
java/vector/src/test/java/org/apache/arrow/vector/TestValueVector.java:
##########
@@ -2019,89 +2118,102 @@ public void testCopyFromWithNulls1() {
}
}
+ private void testSetLastSetUsageHelper(AbstractVariableWidthVector vector) {
+ vector.allocateNew(1024 * 10, 1024);
+
+ setBytes(0, STR1, vector);
+ setBytes(1, STR2, vector);
+ setBytes(2, STR3, vector);
+ setBytes(3, STR4, vector);
+ setBytes(4, STR5, vector);
+ setBytes(5, STR6, vector);
+
+ /* Check current lastSet */
+ assertEquals(-1, vector.getLastSet());
+
+ /* Check the vector output */
+ assertArrayEquals(STR1, vector.get(0));
+ assertArrayEquals(STR2, vector.get(1));
+ assertArrayEquals(STR3, vector.get(2));
+ assertArrayEquals(STR4, vector.get(3));
+ assertArrayEquals(STR5, vector.get(4));
+ assertArrayEquals(STR6, vector.get(5));
+
+ /*
+ * If we don't do setLastSe(5) before setValueCount(), then the latter
will corrupt
+ * the value vector by filling in all positions [0,valuecount-1] will
empty byte arrays.
+ * Run the test by commenting out next line and we should see incorrect
vector output.
+ */
+ vector.setLastSet(5);
+ vector.setValueCount(20);
+
+ /* Check current lastSet */
+ assertEquals(19, vector.getLastSet());
+
+ /* Check the vector output again */
+ assertArrayEquals(STR1, vector.get(0));
+ assertArrayEquals(STR2, vector.get(1));
+ assertArrayEquals(STR3, vector.get(2));
+ assertArrayEquals(STR4, vector.get(3));
+ assertArrayEquals(STR5, vector.get(4));
+ assertArrayEquals(STR6, vector.get(5));
+
+ assertEquals(0, vector.getValueLength(6));
+ assertEquals(0, vector.getValueLength(7));
+ assertEquals(0, vector.getValueLength(8));
+ assertEquals(0, vector.getValueLength(9));
+ assertEquals(0, vector.getValueLength(10));
+ assertEquals(0, vector.getValueLength(11));
+ assertEquals(0, vector.getValueLength(12));
+ assertEquals(0, vector.getValueLength(13));
+ assertEquals(0, vector.getValueLength(14));
+ assertEquals(0, vector.getValueLength(15));
+ assertEquals(0, vector.getValueLength(16));
+ assertEquals(0, vector.getValueLength(17));
+ assertEquals(0, vector.getValueLength(18));
+ assertEquals(0, vector.getValueLength(19));
+
+ /* Check offsets */
+ if (vector instanceof BaseVariableWidthVector) {
Review Comment:
I think it would be better to have something like `commonTestXYZ` and do the
assertions in a vector specific manner.
You have pointed it out here:
https://github.com/apache/arrow/pull/40340#discussion_r1557121026
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]