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

Commit ee49dc6

Browse files
committed
[ARROW-7073][Java] Add tests with null values
1 parent ad33e23 commit ee49dc6

File tree

3 files changed

+35
-26
lines changed

3 files changed

+35
-26
lines changed

java/vector/src/main/java/org/apache/arrow/vector/util/VectorAppender.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public ValueVector visit(BaseFixedWidthVector deltaVector, Void value) {
7575
// append data buffer
7676
PlatformDependent.copyMemory(deltaVector.getDataBuffer().memoryAddress(),
7777
targetVector.getDataBuffer().memoryAddress() + deltaVector.getTypeWidth() * targetVector.getValueCount(),
78-
deltaVector.getTypeWidth() * targetVector.getValueCount());
78+
deltaVector.getTypeWidth() * deltaVector.getValueCount());
7979
targetVector.setValueCount(newValueCount);
8080
return targetVector;
8181
}

java/vector/src/test/java/org/apache/arrow/vector/testing/ValueVectorDataPopulator.java

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -562,10 +562,14 @@ public static void setVector(ListVector vector, List<Integer>... values) {
562562
int curPos = 0;
563563
vector.getOffsetBuffer().setInt(0, curPos);
564564
for (int i = 0; i < values.length; i++) {
565-
BitVectorHelper.setBit(vector.getValidityBuffer(), i);
566-
for (int value : values[i]) {
567-
dataVector.set(curPos, value);
568-
curPos += 1;
565+
if (values[i] == null) {
566+
BitVectorHelper.unsetBit(vector.getValidityBuffer(), i);
567+
} else {
568+
BitVectorHelper.setBit(vector.getValidityBuffer(), i);
569+
for (int value : values[i]) {
570+
dataVector.set(curPos, value);
571+
curPos += 1;
572+
}
569573
}
570574
vector.getOffsetBuffer().setInt((i + 1) * BaseRepeatedValueVector.OFFSET_WIDTH, curPos);
571575
}
@@ -579,7 +583,9 @@ public static void setVector(ListVector vector, List<Integer>... values) {
579583
*/
580584
public static void setVector(FixedSizeListVector vector, List<Integer>... values) {
581585
for (int i = 0; i < values.length; i++) {
582-
assertEquals(vector.getListSize(), values[i].size());
586+
if (values[i] != null) {
587+
assertEquals(vector.getListSize(), values[i].size());
588+
}
583589
}
584590

585591
Types.MinorType type = Types.MinorType.INT;
@@ -591,10 +597,14 @@ public static void setVector(FixedSizeListVector vector, List<Integer>... values
591597
// set underlying vectors
592598
int curPos = 0;
593599
for (int i = 0; i < values.length; i++) {
594-
BitVectorHelper.setBit(vector.getValidityBuffer(), i);
595-
for (int value : values[i]) {
596-
dataVector.set(curPos, value);
597-
curPos += 1;
600+
if (values[i] == null) {
601+
BitVectorHelper.unsetBit(vector.getValidityBuffer(), i);
602+
} else {
603+
BitVectorHelper.setBit(vector.getValidityBuffer(), i);
604+
for (int value : values[i]) {
605+
dataVector.set(curPos, value);
606+
curPos += 1;
607+
}
598608
}
599609
}
600610
dataVector.setValueCount(curPos);

java/vector/src/test/java/org/apache/arrow/vector/util/TestVectorAppender.java

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ public void testAppendFixedWidthVector() {
7373
target.allocateNew(length1);
7474
delta.allocateNew(length2);
7575

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

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

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

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

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

108108
try (VarCharVector expected = new VarCharVector("expected", allocator)) {
109109
expected.allocateNew();
110110
ValueVectorDataPopulator.setVector(expected,
111-
"a0", "a1", "a2", "a3", "a4", "a5", "a6", "a7", "a8", "a9", "a10", "a11", "a12", "a13", "a14");
111+
"a0", "a1", "a2", "a3", null, "a5", "a6", "a7", "a8", "a9", "a10", "a11", "a12", "a13", null);
112112
assertVectorsEqual(expected, target);
113113
}
114114
}
@@ -125,7 +125,7 @@ public void testAppendListVector() {
125125
ValueVectorDataPopulator.setVector(target,
126126
Arrays.asList(0, 1),
127127
Arrays.asList(2, 3),
128-
Arrays.asList(4, 5),
128+
null,
129129
Arrays.asList(6, 7),
130130
Arrays.asList(8, 9));
131131
assertEquals(length1, target.getValueCount());
@@ -147,8 +147,7 @@ public void testAppendListVector() {
147147
expected = Arrays.asList(2, 3);
148148
assertEquals(expected, target.getObject(1));
149149

150-
expected = Arrays.asList(4, 5);
151-
assertEquals(expected, target.getObject(2));
150+
assertTrue(target.isNull(2));
152151

153152
expected = Arrays.asList(6, 7);
154153
assertEquals(expected, target.getObject(3));
@@ -172,7 +171,7 @@ public void testAppendFixedSizeListVector() {
172171
target.allocateNew();
173172
ValueVectorDataPopulator.setVector(target,
174173
Arrays.asList(0, 1, 2, 3, 4),
175-
Arrays.asList(5, 6, 7, 8, 9));
174+
null);
176175
assertEquals(2, target.getValueCount());
177176

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

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

211210
IntVector deltaChild1 = delta.addOrGet("f0", FieldType.nullable(new ArrowType.Int(32, true)), IntVector.class);
212211
VarCharVector deltaChild2 = delta.addOrGet("f1", FieldType.nullable(new ArrowType.Utf8()), VarCharVector.class);
213212
deltaChild1.allocateNew();
214213
deltaChild2.allocateNew();
215-
ValueVectorDataPopulator.setVector(deltaChild1, 10, 11, 12, 13, 14);
214+
ValueVectorDataPopulator.setVector(deltaChild1, 10, 11, 12, null, 14);
216215
ValueVectorDataPopulator.setVector(deltaChild2, "a10", "a11", "a12", "a13", "a14");
217216
delta.setValueCount(length2);
218217

@@ -228,9 +227,9 @@ public void testAppendStructVector() {
228227
expected1.allocateNew();
229228
expected2.allocateNew();
230229

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

235234
assertVectorsEqual(expected1, target.getChild("f0"));
236235
assertVectorsEqual(expected2, target.getChild("f1"));

0 commit comments

Comments
 (0)