|
16 | 16 | */ |
17 | 17 | package org.apache.arrow.vector; |
18 | 18 |
|
| 19 | +import static java.util.Arrays.asList; |
19 | 20 | import static org.junit.jupiter.api.Assertions.assertArrayEquals; |
20 | 21 | import static org.junit.jupiter.api.Assertions.assertEquals; |
21 | 22 | import static org.junit.jupiter.api.Assertions.assertFalse; |
22 | 23 | import static org.junit.jupiter.api.Assertions.assertThrows; |
23 | 24 | import static org.junit.jupiter.api.Assertions.assertTrue; |
24 | 25 |
|
25 | 26 | import java.nio.charset.StandardCharsets; |
| 27 | +import java.util.ArrayList; |
26 | 28 | import java.util.HashMap; |
| 29 | +import java.util.List; |
27 | 30 | import java.util.Map; |
28 | 31 | import org.apache.arrow.memory.BufferAllocator; |
29 | 32 | import org.apache.arrow.memory.RootAllocator; |
|
36 | 39 | import org.apache.arrow.vector.complex.UnionVector; |
37 | 40 | import org.apache.arrow.vector.types.pojo.ArrowType; |
38 | 41 | import org.apache.arrow.vector.types.pojo.ArrowType.Struct; |
| 42 | +import org.apache.arrow.vector.types.pojo.Field; |
39 | 43 | import org.apache.arrow.vector.types.pojo.FieldType; |
40 | 44 | import org.apache.arrow.vector.util.TransferPair; |
41 | 45 | import org.junit.jupiter.api.AfterEach; |
@@ -198,6 +202,65 @@ public void testWithEmptyVector() { |
198 | 202 | toDUV.clear(); |
199 | 203 | } |
200 | 204 |
|
| 205 | + @Test |
| 206 | + public void testWithNullVector() { |
| 207 | + int valueCount = 123; |
| 208 | + int startIndex = 10; |
| 209 | + NullVector fromNullVector = new NullVector("nullVector"); |
| 210 | + fromNullVector.setValueCount(valueCount); |
| 211 | + TransferPair transferPair = fromNullVector.getTransferPair(fromNullVector.getAllocator()); |
| 212 | + transferPair.splitAndTransfer(startIndex, valueCount - startIndex); |
| 213 | + NullVector toNullVector = (NullVector) transferPair.getTo(); |
| 214 | + |
| 215 | + assertEquals(valueCount - startIndex, toNullVector.getValueCount()); |
| 216 | + // no allocations to clear for NullVector |
| 217 | + } |
| 218 | + |
| 219 | + @Test |
| 220 | + public void testWithZeroVector() { |
| 221 | + ZeroVector fromZeroVector = new ZeroVector("zeroVector"); |
| 222 | + TransferPair transferPair = fromZeroVector.getTransferPair(fromZeroVector.getAllocator()); |
| 223 | + transferPair.splitAndTransfer(0, 0); |
| 224 | + ZeroVector toZeroVector = (ZeroVector) transferPair.getTo(); |
| 225 | + |
| 226 | + assertEquals(0, toZeroVector.getValueCount()); |
| 227 | + // no allocations to clear for ZeroVector |
| 228 | + } |
| 229 | + |
| 230 | + @Test |
| 231 | + public void testListVectorWithEmptyMapVector() { |
| 232 | + // List<element: Map(false)<entries: Struct<key: Utf8 not null, value: Utf8> not null>> |
| 233 | + int valueCount = 1; |
| 234 | + List<Field> children = new ArrayList<>(); |
| 235 | + children.add(new Field("key", FieldType.notNullable(new ArrowType.Utf8()), null)); |
| 236 | + children.add(new Field("value", FieldType.nullable(new ArrowType.Utf8()), null)); |
| 237 | + Field structField = |
| 238 | + new Field("entries", FieldType.notNullable(ArrowType.Struct.INSTANCE), children); |
| 239 | + |
| 240 | + Field mapField = |
| 241 | + new Field("element", FieldType.notNullable(new ArrowType.Map(false)), asList(structField)); |
| 242 | + |
| 243 | + Field listField = new Field("list", FieldType.nullable(new ArrowType.List()), asList(mapField)); |
| 244 | + |
| 245 | + ListVector fromListVector = (ListVector) listField.createVector(allocator); |
| 246 | + fromListVector.allocateNew(); |
| 247 | + fromListVector.setValueCount(valueCount); |
| 248 | + |
| 249 | + // child vector is empty |
| 250 | + MapVector dataVector = (MapVector) fromListVector.getDataVector(); |
| 251 | + dataVector.allocateNew(); |
| 252 | + // unset capacity to mimic observed failure mode |
| 253 | + dataVector.getOffsetBuffer().capacity(0); |
| 254 | + |
| 255 | + TransferPair transferPair = fromListVector.getTransferPair(fromListVector.getAllocator()); |
| 256 | + transferPair.splitAndTransfer(0, valueCount); |
| 257 | + ListVector toListVector = (ListVector) transferPair.getTo(); |
| 258 | + |
| 259 | + assertEquals(valueCount, toListVector.getValueCount()); |
| 260 | + fromListVector.clear(); |
| 261 | + toListVector.clear(); |
| 262 | + } |
| 263 | + |
201 | 264 | @Test /* VarCharVector */ |
202 | 265 | public void test() throws Exception { |
203 | 266 | try (final VarCharVector varCharVector = new VarCharVector("myvector", allocator)) { |
|
0 commit comments