Class ArrowValues
java.lang.Object
io.krabka.streams.columnar.ArrowValues
Type-coercing Arrow batch helpers for
RowBridge and
ColumnarProcessor implementations.
These are the same conversions the built-in operators and bridges use: a write
dispatches on the vector's type and accepts natural Java values (Number,
CharSequence, byte[] or ByteBuffer, Boolean,
BigDecimal, java.time types, Collection for lists,
Map for maps and structs), and a read returns the matching Java value with
Text normalized to String, binary to a read-only
ByteBuffer, and unsigned 64-bit integers to BigInteger. Using them
keeps custom code consistent with the rest of the engine instead of reimplementing
raw vector access.
Example
var fields = List.of(
new Field("user", FieldType.nullable(new ArrowType.Utf8()), null));
VectorSchemaRoot root = ArrowValues.createRoot(fields, 2, allocator);
ArrowValues.set(root.getVector("user"), 0, "ada");
ArrowValues.set(root.getVector("user"), 1, null);
ArrowValues.finish(root);
Object first = ArrowValues.get(root.getVector("user"), 0); // "ada"
-
Method Summary
Modifier and TypeMethodDescriptionstatic org.apache.arrow.vector.VectorSchemaRootcreateRoot(List<org.apache.arrow.vector.types.pojo.Field> fields, int rows, org.apache.arrow.memory.BufferAllocator allocator) Creates a batch with allocated vectors and the given row count.static voidfinish(org.apache.arrow.vector.VectorSchemaRoot root) Sets every vector's value count to the batch's row count.static Objectget(org.apache.arrow.vector.FieldVector vector, int row) Reads one value from a vector as its natural Java representation.static voidWrites one value into a vector, coercing it to the vector's Arrow type.
-
Method Details
-
createRoot
public static org.apache.arrow.vector.VectorSchemaRoot createRoot(List<org.apache.arrow.vector.types.pojo.Field> fields, int rows, org.apache.arrow.memory.BufferAllocator allocator) Creates a batch with allocated vectors and the given row count.- Parameters:
fields- the columns of the batchrows- the number of rows the batch holdsallocator- the allocator that owns the batch's buffers- Returns:
- the batch; the caller must close it
-
set
Writes one value into a vector, coercing it to the vector's Arrow type.- Parameters:
vector- the vector to write torow- the row index to write atvalue- the value to write; null marks the row null- Throws:
ColumnarException- if the vector's Arrow type is unsupported or the value does not fit it
-
get
Reads one value from a vector as its natural Java representation.- Parameters:
vector- the vector to read fromrow- the row index to read- Returns:
- the value, or null if the row is null
-
finish
public static void finish(org.apache.arrow.vector.VectorSchemaRoot root) Sets every vector's value count to the batch's row count.Call this once after the last
set(FieldVector, int, Object)so readers observe every written row.- Parameters:
root- the batch to finish
-