Skip to content

Commit

Permalink
fix: adding c data interface test
Browse files Browse the repository at this point in the history
  • Loading branch information
vibhatha committed Jun 27, 2024
1 parent cf1f6f3 commit 01a5cac
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 2 deletions.
49 changes: 49 additions & 0 deletions java/c/src/test/java/org/apache/arrow/c/RoundtripTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -705,6 +705,55 @@ public void testMapVector() {
}
}

@Test
public void testMapVectorCustomFieldNames() {
Field keyField =
new Field(
"id", FieldType.notNullable(new ArrowType.Int(64, true)), Collections.emptyList());
Field valueField =
new Field(
"value", FieldType.nullable(new ArrowType.Int(64, true)), Collections.emptyList());
List<Field> structFields = new ArrayList<>();
structFields.add(keyField);
structFields.add(valueField);

Field structField =
new Field("entry", FieldType.notNullable(ArrowType.Struct.INSTANCE), structFields);
Field mapIntToIntField =
new Field(
"mapFieldIntToInt",
FieldType.notNullable(new ArrowType.Map(false)),
Collections.singletonList(structField));

Schema schema = new Schema(Collections.singletonList(mapIntToIntField));
try (VectorSchemaRoot vectorSchemaRoot = VectorSchemaRoot.create(schema, allocator);
MapVector mapVector = (MapVector) vectorSchemaRoot.getVector("mapFieldIntToInt")) {
UnionMapWriter mapWriter = mapVector.getWriter();
mapWriter.setPosition(0);
mapWriter.startMap();
for (int i = 0; i < 18; i++) {
mapWriter.startEntry();
if (i % 2 == 0) {
mapWriter.key().bigInt().writeBigInt(i);
if (i % 3 == 0) {
mapWriter.value().bigInt().writeBigInt(i * 7);
} else {
mapWriter.value().bigInt().writeNull();
}
} else {
mapWriter.key().bigInt().writeNull();
mapWriter.value().bigInt().writeNull();
}
mapWriter.endEntry();
}
mapWriter.endMap();

mapWriter.setValueCount(1);
vectorSchemaRoot.setRowCount(1);
roundtrip(mapVector, MapVector.class);
}
}

@Test
public void testUnionVector() {
final NullableUInt4Holder uInt4Holder = new NullableUInt4Holder();
Expand Down
2 changes: 0 additions & 2 deletions java/c/src/test/java/org/apache/arrow/c/StreamTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -313,8 +313,6 @@ public void roundtripMap() throws Exception {
mapWriter.setValueCount(1);
vectorSchemaRoot.setRowCount(1);

System.out.println(vectorSchemaRoot.contentToTSVString());

VectorUnloader unloader = new VectorUnloader(vectorSchemaRoot);
batches.add(unloader.getRecordBatch());
roundtrip(schema, batches);
Expand Down

0 comments on commit 01a5cac

Please sign in to comment.