1 | initial version |
The method for filling a list of structured fields in Java Apache Arrow is as follows:
Here is an example of how to fill a list of structured fields in Java Apache Arrow:
List<Field> fields = new ArrayList<>();
fields.add(Field.nullable("id", new ArrowType.Int(32, true)));
fields.add(Field.nullable("name", new ArrowType.Utf8()));
Schema schema = new Schema(fields);
try (ArrowRecordBatchBuilder builder = new ArrowRecordBatchBuilder(new RootAllocator())) {
builder.setSchema(schema);
builder.addField(Field.nullable("id", new ArrowType.Int(32, true)));
builder.addField(Field.nullable("name", new ArrowType.Utf8()));
builder.start(2);
builder.setInteger(0, 0, 1);
builder.setVarchar(1, 0, "John");
builder.setInteger(0, 1, 2);
builder.setVarchar(1, 1, "Jane");
ArrowRecordBatch recordBatch = builder.build();
}
In this example, we create a list of two fields: an Integer field named "id" and a Utf8 field named "name". We then create a Schema object using the list of fields and an ArrowRecordBatchBuilder object using a RootAllocator (you can use a different allocator if you prefer).
We then add the two fields to the ArrowRecordBatchBuilder and fill in the data using the appropriate set methods for each Field type. Finally, we call the build method on the ArrowRecordBatchBuilder to get an Arrow RecordBatch object containing the structured data.