Class JsonRowBridge<T>
- Type Parameters:
T- the Jackson-compatible row type
- All Implemented Interfaces:
RowBridge<T>
Values are mapped through Jackson: each top-level property becomes one column.
Text becomes Utf8, integral numbers Int(64), floating point
FloatingPoint(DOUBLE), booleans Bool, and binary Binary;
nested objects and arrays are stored as their JSON text. Scalar types such as
String or Long map to a single column named value.
The Arrow schema can come from three places, in order of preference: an
explicit Arrow Schema, a JSON Schema document through
fromJsonSchema(Class, String), or inference from the first batch's
non-null sample values. Inference locks in after the first non-empty batch, so
later batches use the same schema; prefer an explicit schema in production so a
batch of unusual first values cannot change column types.
Example
record Transaction(String user, long amount) {}
var bridge = new JsonRowBridge<>(Transaction.class);
try (var batch = bridge.rowsToBatch(List.of(new Transaction("ada", 7)), allocator)) {
// columns: user (Utf8), amount (Int(64))
List<Transaction> back = bridge.batchToRows(batch);
}
-
Constructor Summary
ConstructorsConstructorDescriptionJsonRowBridge(Class<T> type) Creates a bridge that infers its Arrow schema from the first non-empty batch.JsonRowBridge(Class<T> type, com.fasterxml.jackson.databind.ObjectMapper objectMapper) Creates a schema-inferring bridge with a caller-supplied Jackson mapper.JsonRowBridge(Class<T> type, com.fasterxml.jackson.databind.ObjectMapper objectMapper, org.apache.arrow.vector.types.pojo.Schema schema) Creates a bridge with an explicit Arrow schema and Jackson mapper.JsonRowBridge(Class<T> type, org.apache.arrow.vector.types.pojo.Schema schema) Creates a bridge with an explicit Arrow schema. -
Method Summary
Modifier and TypeMethodDescriptionbatchToRows(org.apache.arrow.vector.VectorSchemaRoot batch) Converts an Arrow payload batch back into one value per row.static <T> JsonRowBridge<T> fromJsonSchema(Class<T> type, String jsonSchema) Creates a bridge whose Arrow fields come from a JSON Schema instead of sample rows.static <T> JsonRowBridge<T> fromJsonSchema(Class<T> type, String jsonSchema, com.fasterxml.jackson.databind.ObjectMapper objectMapper) Creates a JSON Schema driven bridge with a caller-supplied Jackson mapper.org.apache.arrow.vector.VectorSchemaRootrowsToBatch(List<T> rows, org.apache.arrow.memory.BufferAllocator allocator) Builds one Arrow batch with one row per value.
-
Constructor Details
-
JsonRowBridge
-
JsonRowBridge
-
JsonRowBridge
-
JsonRowBridge
public JsonRowBridge(Class<T> type, com.fasterxml.jackson.databind.ObjectMapper objectMapper, org.apache.arrow.vector.types.pojo.Schema schema) Creates a bridge with an explicit Arrow schema and Jackson mapper.- Parameters:
type- the row class values are bound to and fromobjectMapper- the mapper used for binding rowsschema- the Arrow schema every batch uses
-
-
Method Details
-
fromJsonSchema
Creates a bridge whose Arrow fields come from a JSON Schema instead of sample rows.Property types map as in schema inference; a property is nullable unless it is listed in
required, and$refpointers within the document are resolved.- Type Parameters:
T- the Jackson-compatible row type- Parameters:
type- the row class values are bound to and fromjsonSchema- the JSON Schema document describing the rows- Returns:
- a bridge with fields derived from the schema
- Throws:
IllegalArgumentException- if the document is not a JSON object, lacks properties, or contains an unresolvable reference
-
fromJsonSchema
public static <T> JsonRowBridge<T> fromJsonSchema(Class<T> type, String jsonSchema, com.fasterxml.jackson.databind.ObjectMapper objectMapper) Creates a JSON Schema driven bridge with a caller-supplied Jackson mapper.- Type Parameters:
T- the Jackson-compatible row type- Parameters:
type- the row class values are bound to and fromjsonSchema- the JSON Schema document describing the rowsobjectMapper- the mapper used for binding rows- Returns:
- a bridge with fields derived from the schema
- Throws:
IllegalArgumentException- if the document is not a JSON object, lacks properties, or contains an unresolvable reference
-
rowsToBatch
public org.apache.arrow.vector.VectorSchemaRoot rowsToBatch(List<T> rows, org.apache.arrow.memory.BufferAllocator allocator) Builds one Arrow batch with one row per value.If the bridge has no schema yet, one is inferred from this batch's non-null values and kept for all later batches, provided the batch is not empty.
- Specified by:
rowsToBatchin interfaceRowBridge<T>- Parameters:
rows- the values to convert, in record orderallocator- the allocator that owns the batch's buffers- Returns:
- the payload batch; the caller must close it
- Throws:
ColumnarException- if a required field is null or a value cannot be written
-
batchToRows
Converts an Arrow payload batch back into one value per row.- Specified by:
batchToRowsin interfaceRowBridge<T>- Parameters:
batch- the payload batch to convert; the bridge reads it and leaves it open- Returns:
- the values in row order
- Throws:
ColumnarException- if a row cannot be bound to the row class
-