Skip to content
This repository has been archived by the owner on Oct 21, 2024. It is now read-only.

Commit

Permalink
[ARROW-7073][Java] Add tests with null values
Browse files Browse the repository at this point in the history
  • Loading branch information
liyafan82 committed Feb 3, 2020
1 parent ad33e23 commit ee49dc6
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public ValueVector visit(BaseFixedWidthVector deltaVector, Void value) {
// append data buffer
PlatformDependent.copyMemory(deltaVector.getDataBuffer().memoryAddress(),
targetVector.getDataBuffer().memoryAddress() + deltaVector.getTypeWidth() * targetVector.getValueCount(),
deltaVector.getTypeWidth() * targetVector.getValueCount());
deltaVector.getTypeWidth() * deltaVector.getValueCount());
targetVector.setValueCount(newValueCount);
return targetVector;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -562,10 +562,14 @@ public static void setVector(ListVector vector, List<Integer>... values) {
int curPos = 0;
vector.getOffsetBuffer().setInt(0, curPos);
for (int i = 0; i < values.length; i++) {
BitVectorHelper.setBit(vector.getValidityBuffer(), i);
for (int value : values[i]) {
dataVector.set(curPos, value);
curPos += 1;
if (values[i] == null) {
BitVectorHelper.unsetBit(vector.getValidityBuffer(), i);
} else {
BitVectorHelper.setBit(vector.getValidityBuffer(), i);
for (int value : values[i]) {
dataVector.set(curPos, value);
curPos += 1;
}
}
vector.getOffsetBuffer().setInt((i + 1) * BaseRepeatedValueVector.OFFSET_WIDTH, curPos);
}
Expand All @@ -579,7 +583,9 @@ public static void setVector(ListVector vector, List<Integer>... values) {
*/
public static void setVector(FixedSizeListVector vector, List<Integer>... values) {
for (int i = 0; i < values.length; i++) {
assertEquals(vector.getListSize(), values[i].size());
if (values[i] != null) {
assertEquals(vector.getListSize(), values[i].size());
}
}

Types.MinorType type = Types.MinorType.INT;
Expand All @@ -591,10 +597,14 @@ public static void setVector(FixedSizeListVector vector, List<Integer>... values
// set underlying vectors
int curPos = 0;
for (int i = 0; i < values.length; i++) {
BitVectorHelper.setBit(vector.getValidityBuffer(), i);
for (int value : values[i]) {
dataVector.set(curPos, value);
curPos += 1;
if (values[i] == null) {
BitVectorHelper.unsetBit(vector.getValidityBuffer(), i);
} else {
BitVectorHelper.setBit(vector.getValidityBuffer(), i);
for (int value : values[i]) {
dataVector.set(curPos, value);
curPos += 1;
}
}
}
dataVector.setValueCount(curPos);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ public void testAppendFixedWidthVector() {
target.allocateNew(length1);
delta.allocateNew(length2);

ValueVectorDataPopulator.setVector(target, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9);
ValueVectorDataPopulator.setVector(delta, 10, 11, 12, 13, 14);
ValueVectorDataPopulator.setVector(target, 0, 1, 2, 3, 4, 5, 6, null, 8, 9);
ValueVectorDataPopulator.setVector(delta, null, 11, 12, 13, 14);

VectorAppender appender = new VectorAppender(target);
delta.accept(appender, null);
Expand All @@ -83,7 +83,7 @@ public void testAppendFixedWidthVector() {

try (IntVector expected = new IntVector("expected", allocator)) {
expected.allocateNew();
ValueVectorDataPopulator.setVector(expected, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14);
ValueVectorDataPopulator.setVector(expected, 0, 1, 2, 3, 4, 5, 6, null, 8, 9, null, 11, 12, 13, 14);
assertVectorsEqual(expected, target);
}
}
Expand All @@ -99,16 +99,16 @@ public void testAppendVariableWidthVector() {
target.allocateNew(5, length1);
delta.allocateNew(5, length2);

ValueVectorDataPopulator.setVector(target, "a0", "a1", "a2", "a3", "a4", "a5", "a6", "a7", "a8", "a9");
ValueVectorDataPopulator.setVector(delta, "a10", "a11", "a12", "a13", "a14");
ValueVectorDataPopulator.setVector(target, "a0", "a1", "a2", "a3", null, "a5", "a6", "a7", "a8", "a9");
ValueVectorDataPopulator.setVector(delta, "a10", "a11", "a12", "a13", null);

VectorAppender appender = new VectorAppender(target);
delta.accept(appender, null);

try (VarCharVector expected = new VarCharVector("expected", allocator)) {
expected.allocateNew();
ValueVectorDataPopulator.setVector(expected,
"a0", "a1", "a2", "a3", "a4", "a5", "a6", "a7", "a8", "a9", "a10", "a11", "a12", "a13", "a14");
"a0", "a1", "a2", "a3", null, "a5", "a6", "a7", "a8", "a9", "a10", "a11", "a12", "a13", null);
assertVectorsEqual(expected, target);
}
}
Expand All @@ -125,7 +125,7 @@ public void testAppendListVector() {
ValueVectorDataPopulator.setVector(target,
Arrays.asList(0, 1),
Arrays.asList(2, 3),
Arrays.asList(4, 5),
null,
Arrays.asList(6, 7),
Arrays.asList(8, 9));
assertEquals(length1, target.getValueCount());
Expand All @@ -147,8 +147,7 @@ public void testAppendListVector() {
expected = Arrays.asList(2, 3);
assertEquals(expected, target.getObject(1));

expected = Arrays.asList(4, 5);
assertEquals(expected, target.getObject(2));
assertTrue(target.isNull(2));

expected = Arrays.asList(6, 7);
assertEquals(expected, target.getObject(3));
Expand All @@ -172,7 +171,7 @@ public void testAppendFixedSizeListVector() {
target.allocateNew();
ValueVectorDataPopulator.setVector(target,
Arrays.asList(0, 1, 2, 3, 4),
Arrays.asList(5, 6, 7, 8, 9));
null);
assertEquals(2, target.getValueCount());

delta.allocateNew();
Expand All @@ -187,7 +186,7 @@ public void testAppendFixedSizeListVector() {
assertEquals(4, target.getValueCount());

assertEquals(Arrays.asList(0, 1, 2, 3, 4), target.getObject(0));
assertEquals(Arrays.asList(5, 6, 7, 8, 9), target.getObject(1));
assertTrue(target.isNull(1));
assertEquals(Arrays.asList(10, 11, 12, 13, 14), target.getObject(2));
assertEquals(Arrays.asList(15, 16, 17, 18, 19), target.getObject(3));
}
Expand All @@ -204,15 +203,15 @@ public void testAppendStructVector() {
VarCharVector targetChild2 = target.addOrGet("f1", FieldType.nullable(new ArrowType.Utf8()), VarCharVector.class);
targetChild1.allocateNew();
targetChild2.allocateNew();
ValueVectorDataPopulator.setVector(targetChild1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9);
ValueVectorDataPopulator.setVector(targetChild2, "a0", "a1", "a2", "a3", "a4", "a5", "a6", "a7", "a8", "a9");
ValueVectorDataPopulator.setVector(targetChild1, 0, 1, 2, 3, 4, null, 6, 7, 8, 9);
ValueVectorDataPopulator.setVector(targetChild2, "a0", "a1", "a2", "a3", "a4", "a5", "a6", null, "a8", "a9");
target.setValueCount(length1);

IntVector deltaChild1 = delta.addOrGet("f0", FieldType.nullable(new ArrowType.Int(32, true)), IntVector.class);
VarCharVector deltaChild2 = delta.addOrGet("f1", FieldType.nullable(new ArrowType.Utf8()), VarCharVector.class);
deltaChild1.allocateNew();
deltaChild2.allocateNew();
ValueVectorDataPopulator.setVector(deltaChild1, 10, 11, 12, 13, 14);
ValueVectorDataPopulator.setVector(deltaChild1, 10, 11, 12, null, 14);
ValueVectorDataPopulator.setVector(deltaChild2, "a10", "a11", "a12", "a13", "a14");
delta.setValueCount(length2);

Expand All @@ -228,9 +227,9 @@ public void testAppendStructVector() {
expected1.allocateNew();
expected2.allocateNew();

ValueVectorDataPopulator.setVector(expected1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14);
ValueVectorDataPopulator.setVector(expected1, 0, 1, 2, 3, 4, null, 6, 7, 8, 9, 10, 11, 12, null, 14);
ValueVectorDataPopulator.setVector(expected2,
"a0", "a1", "a2", "a3", "a4", "a5", "a6", "a7", "a8", "a9", "a10", "a11", "a12", "a13", "a14");
"a0", "a1", "a2", "a3", "a4", "a5", "a6", null, "a8", "a9", "a10", "a11", "a12", "a13", "a14");

assertVectorsEqual(expected1, target.getChild("f0"));
assertVectorsEqual(expected2, target.getChild("f1"));
Expand Down

0 comments on commit ee49dc6

Please sign in to comment.