Arrow helpers
On this page
Building and emitting Arrow batches.
struct BatchBuilder
Section titled âstruct BatchBuilderâtype BatchBuilder struct {schema *arrow.Schemamem memory.Allocatorcolumns []columnBuilderrowCount int64}Description
BatchBuilder accumulates rows for a single output schema and emits an arrow.RecordBatch.
Methods
method AppendNullRow
Section titled âmethod AppendNullRowâfunc (b *BatchBuilder) AppendNullRow()AppendNullRow appends a row of all NULLs. Useful for placeholders.
method AppendRow
Section titled âmethod AppendRowâfunc (b *BatchBuilder) AppendRow(row map[string]any) errorAppendRow writes one row from a name-keyed value map. Missing keys, nil values, and nil pointers produce NULLs. Returns the first per-column error it encounters; the row is left in a partially-appended state if that happens (call Release() to discard).
method Build
Section titled âmethod Buildâfunc (b *BatchBuilder) Build() (arrow.RecordBatch, error)Build finalizes the accumulated rows into a RecordBatch and releases the underlying builders. The returned batch is owned by the caller and must be Released by them when no longer needed.
function NewBatchBuilder
Section titled âfunction NewBatchBuilderâfunc NewBatchBuilder(schema *arrow.Schema) *BatchBuilderNewBatchBuilder constructs a BatchBuilder for the given schema using the default Arrow allocator.
function NewBatchBuilderWithAllocator
Section titled âfunction NewBatchBuilderWithAllocatorâfunc NewBatchBuilderWithAllocator(schema *arrow.Schema, mem memory.Allocator) *BatchBuilderNewBatchBuilderWithAllocator constructs a BatchBuilder with a caller-provided memory allocator. Useful when integrating with an existing arena.
method Release
Section titled âmethod Releaseâfunc (b *BatchBuilder) Release()Release discards any accumulated state without producing a batch. Safe to call after Build() (no-op).
method Rows
Section titled âmethod Rowsâfunc (b *BatchBuilder) Rows() int64Rows returns the number of rows appended so far.
method Schema
Section titled âmethod Schemaâfunc (b *BatchBuilder) Schema() *arrow.SchemaSchema returns the output schema.
func type EmitOption
Section titled âfunc type EmitOptionâtype EmitOption func(map[string]string) errorDescription
EmitOption contributes annotation metadata to an emitted batch. Options are applied in order, so a later option overwrites an earlier oneâs keys.
Methods
function WithCacheControl
Section titled âfunction WithCacheControlâfunc WithCacheControl(cc *CacheControl) EmitOptionWithCacheControl advertises a cacheable result. The cache-control keys are read once per result, off the FIRST data batch of the stream â passing this on a later batch has no effect. Nil is a no-op, so a caller can write
var cc *vgi.CacheControlif firstBatch { cc = &vgi.CacheControl{Ttl: vgi.Seconds(300)} }vgi.Emit(out, batch, vgi.WithCacheControl(cc))function WithMetadata
Section titled âfunction WithMetadataâfunc WithMetadata(key, value string) EmitOptionWithMetadata sets one arbitrary annotation key on the emitted batch.
struct PartitionValue
Section titled âstruct PartitionValueâtype PartitionValue struct {Min anyMax any}Description
PartitionValue is the (min, max) pair for one partition column. Values are Go scalars compatible with the columnâs Arrow type (see appendValue).
struct columnBuilder
Section titled âstruct columnBuilderâtype columnBuilder struct {field arrow.Fieldbuilder array.Builderappender func(v any) error}Description
columnBuilder pairs a typed Arrow builder with the field it serves. The appender closure encapsulates the type-specific dispatch path.
function BatchToSecretsMap
Section titled âfunction BatchToSecretsMapâfunc BatchToSecretsMap(batch arrow.RecordBatch) map[string]map[string]interface{}BatchToSecretsMap converts a secrets RecordBatch to a map of maps.
function BatchToSettingsMap
Section titled âfunction BatchToSettingsMapâfunc BatchToSettingsMap(batch arrow.RecordBatch) map[string]interface{}BatchToSettingsMap converts a single-row settings RecordBatch to a map.
function BuildArgSchema
Section titled âfunction BuildArgSchemaâfunc BuildArgSchema(specs []ArgSpec) *arrow.SchemaBuildArgSchema creates an Arrow schema from ArgSpecs with VGI metadata markers.
function DeserializeRecordBatch
Section titled âfunction DeserializeRecordBatchâfunc DeserializeRecordBatch(data []byte) (arrow.RecordBatch, error)DeserializeRecordBatch reads a RecordBatch from IPC bytes.
function DeserializeSchema
Section titled âfunction DeserializeSchemaâfunc DeserializeSchema(data []byte) (*arrow.Schema, error)DeserializeSchema reads an Arrow schema from IPC bytes.
function Emit
Section titled âfunction Emitâfunc Emit(out *vgirpc.OutputCollector, batch arrow.RecordBatch, opts âŚEmitOption) errorEmit emits a batch with the annotation metadata contributed by opts. With no options it is equivalent to out.Emit(batch).
function EmitBatchIndex
Section titled âfunction EmitBatchIndexâfunc EmitBatchIndex(out *vgirpc.OutputCollector, batch arrow.RecordBatch, batchIndex int64, opts âŚEmitOption) errorEmitBatchIndex emits a batch tagged with vgi_batch_index. Use it from a table function that declares SupportsBatchIndex. The C++ extension enforces monotonicity and the per-pipeline cap.
function EmitParentRows
Section titled âfunction EmitParentRowsâfunc EmitParentRows(out *vgirpc.OutputCollector, batch arrow.RecordBatch, parentRows []int32, opts âŚEmitOption) errorEmitParentRows emits a batch declaring, per output row, which input row produced it â the provenance map for the batched correlated LATERAL operator (a blended function under FROM t, f(t.x) / LATERAL f(t.x)): the C++ extension ships a whole input chunk to the worker in ONE exchange and reads ONE output batch, then maps each output row back to the input row that produced it via this array â so a 1->N fan-out or 1->0 filter can be batched instead of driven row-by-row.
parentRows[i] is the 0-based index (into the input batch) of the row that produced output row i. Encoded as a raw little-endian int32 array (NOT Arrow IPC), base64-encoded, under vgi_rpc.parent_row#b64 â the C++ side reinterprets the bytes directly. Absent metadata means an identity 1->1 map (the common case: the extension assumes it, and requires output rows == input rows).
Contract: len(parentRows) MUST equal batch.NumRows() (a mismatch is a worker bug that would corrupt the stamping). Values are range-checked against the input width on the C++ side (which knows it authoritatively). Mirrors vgi-pythonâs out.emit(âŚ, parent_rows=âŚ).
function EmitPartitioned
Section titled âfunction EmitPartitionedâfunc EmitPartitioned(out *vgirpc.OutputCollector, batch arrow.RecordBatch, partitionFields []arrow.Field, kind PartitionKind, explicit map[string]PartitionValue, opts âŚEmitOption) errorEmitPartitioned emits a batch annotated with vgi_partition_values for a partition-aware table function. partitionFields are the declared partition columns (build them with PartitionField). For each, the (min, max) pair comes from explicit when present, else is auto-extracted from the same-named column in the emitted batch. Mirrors vgi-pythonâs _merge_partition_values contract: the SINGLE_VALUE distinct-value check, the ârequires partition-annotated fieldsâ guard, and the annotated-but-absent error.
function EmptyBatch
Section titled âfunction EmptyBatchâfunc EmptyBatch(schema *arrow.Schema) arrow.RecordBatchEmptyBatch creates a zero-row batch with the given schema.
function PartitionField
Section titled âfunction PartitionFieldâfunc PartitionField(name string, typ arrow.DataType, nullable bool) arrow.FieldPartitionField builds an Arrow field annotated as a partition column (schema metadata vgi.partition_column=true). Mirrors vgi-pythonâs partition_field.
function ProjectSchema
Section titled âfunction ProjectSchemaâfunc ProjectSchema(projectionIDs []int32, schema *arrow.Schema) *arrow.SchemaProjectSchema returns a new schema with only the fields at the given indices.
function SchemaFromOrderedFields
Section titled âfunction SchemaFromOrderedFieldsâfunc SchemaFromOrderedFields(names []string, types []arrow.DataType) *arrow.SchemaSchemaFromOrderedFields creates an Arrow schema preserving insertion order.
function SerializeRecordBatch
Section titled âfunction SerializeRecordBatchâfunc SerializeRecordBatch(batch arrow.RecordBatch) ([]byte, error)SerializeRecordBatch serializes a RecordBatch to IPC bytes.
function SerializeSchema
Section titled âfunction SerializeSchemaâfunc SerializeSchema(schema *arrow.Schema) ([]byte, error)SerializeSchema serializes an Arrow schema to IPC bytes.
function ValidateTypeBounds
Section titled âfunction ValidateTypeBoundsâfunc ValidateTypeBounds(specs []ArgSpec, inputSchema *arrow.Schema) errorValidateTypeBounds validates that the input schema field types satisfy the TypeBound predicates declared on each ArgSpec. For each non-const ArgSpec with ArrowType âanyâ and non-nil TypeBound, the corresponding input schema field must satisfy at least one predicate (OR logic). For varargs, all fields from the specâs position onward are validated.
function applyEmitOptions
Section titled âfunction applyEmitOptionsâfunc applyEmitOptions(base map[string]string, opts []EmitOption) (map[string]string, error)applyEmitOptions folds opts into a fresh metadata map, seeded with base. Returns nil when nothing was contributed, so the caller can emit unannotated.
function argTypeToArrowType
Section titled âfunction argTypeToArrowTypeâfunc argTypeToArrowType(t string) arrow.DataTypeargTypeToArrowType converts a VGI arg type string to an Arrow DataType.
function bbToFloat64
Section titled âfunction bbToFloat64âfunc bbToFloat64(v any) (float64, bool)function bbToSliceAny
Section titled âfunction bbToSliceAnyâfunc bbToSliceAny(v any) ([]any, bool)toSliceAny coerces []T (for any T) and []any to a []any view via reflection. Returns ok=false for non-slices.
function bbToString
Section titled âfunction bbToStringâfunc bbToString(v any) (string, bool)function bbToUint64
Section titled âfunction bbToUint64âfunc bbToUint64(v any) (uint64, bool)function columnMinMax
Section titled âfunction columnMinMaxâfunc columnMinMax(col arrow.Array) (min, max any, moreThanOne bool, err error)columnMinMax returns the min and max of a non-null Arrow column, plus whether the column carries more than one distinct value. Supports the scalar types used by partition columns. moreThanOne is exactly (min != max) over the non-null values, so no per-row set is needed to detect a SINGLE_VALUE violation.
function deref
Section titled âfunction derefâfunc deref(v any) anyderef dereferences pointer types so toX helpers can accept *string, *int64, etc.
function deserializeJoinKeys
Section titled âfunction deserializeJoinKeysâfunc deserializeJoinKeys(entries [][]byte) map[string]arrow.ArraydeserializeJoinKeys unpacks a list of IPC-serialized RecordBatches into a map from column name to Arrow array. Each batch should be a single-column batch; all columns across batches are flattened into one map by field name.
function extractScalarValue
Section titled âfunction extractScalarValueâfunc extractScalarValue(col arrow.Array, idx int) interface{}extractScalarValue extracts a Go value from an Arrow array at the given index.
function isNil
Section titled âfunction isNilâfunc isNil(v any) boolisNil returns true for untyped nil, nil interface, nil pointer, nil slice, nil map, and nil chan/func. Anything else is non-nil â including a non-nil pointer to a zero value.
function makeAppender
Section titled âfunction makeAppenderâfunc makeAppender(builder array.Builder, dt arrow.DataType) func(any) errormakeAppender returns a closure that appends a single value to builder,
dispatching on the fieldâs Arrow type. The closure is built once per column
at construction time so AppendRowâs hot path is one map lookup + one virtual
call per column.
function matchesAnyBound
Section titled âfunction matchesAnyBoundâfunc matchesAnyBound(fieldType arrow.DataType, bounds []TypeBoundPredicate) boolfunction predicateNames
Section titled âfunction predicateNamesâfunc predicateNames(bounds []TypeBoundPredicate) []stringpredicateNames recovers the symbolic name of each TypeBoundPredicate via runtime reflection. Used in TypeBoundError messages to keep the wire-level error text aligned with vgi-pythonâs â_is_multipliable_typeâ / â_is_addable_typeâ convention (the SQL tests assert on these substrings).