Documentation
¶
Overview ¶
Package arrow is a pure-Go (CGO=0), MRI-faithful implementation of the Ruby red-arrow gem's core surface — Apache Arrow's columnar in-memory format and its IPC (Feather / Arrow stream & file) serialization.
Relationship to upstream ¶
The real red-arrow gem is a thin Ruby binding over the C library libarrow (via GObject introspection), so it cannot be shipped in a CGO-free static binary. This package mirrors red-arrow's observable Ruby surface — Array, ArrayBuilder, DataType, Field, Schema, RecordBatch, Table and the IPC round-trip — on top of github.com/apache/arrow-go/v18, the official pure-Go Apache Arrow implementation. It does not reimplement the columnar format itself; it re-presents arrow-go through Ruby's naming and semantics so it can back an embedded Ruby (go-embedded-ruby / rbgo) with no cgo.
Ruby-to-Go mapping ¶
Arrow::Array -> *Array (Enumerable via Each/ToSlice) Arrow::ArrayBuilder -> *ArrayBuilder Arrow::DataType -> *DataType (Int8()..Decimal128()/ListOf/StructOf) Arrow::Field -> *Field Arrow::Schema -> *Schema Arrow::RecordBatch -> *RecordBatch Arrow::Table -> *Table Arrow::Error (tree) -> *Error (Kind + RubyClass mapping)
Ruby predicate methods ending in "?" map to Go methods ending in "Q" (IsNull -> null?, etc.), and mutating "!" methods are spelled out. Ruby integer/float towers collapse onto Go's int64/float64 at the boundary, with explicit typed builders preserving Arrow's Int8..Int64 / UInt8..UInt64 / Float32/Float64 / Boolean / String / Timestamp / Date32 / Decimal128 / List / Struct widths.
IPC wire compatibility ¶
Tables and record batches round-trip through both the Arrow IPC streaming format (WriteTableStream / ReadTableStream) and the Arrow IPC file (a.k.a. Feather v2) format (WriteTableFile / ReadTableFile). The bytes this package emits are the bytes arrow-go's canonical ipc.Reader/FileReader consume, and vice-versa — verified by the differential tests, not asserted. Arrow buffers are little-endian on the wire on every architecture; on big-endian targets (s390x) arrow-go performs the byte swap, so the same bytes round-trip identically across all six supported 64-bit arches.
Scope ¶
This covers red-arrow's Array/Schema/Table/RecordBatch core plus IPC. It does not (yet) cover red-arrow's compute kernels, Parquet/CSV readers, Datasets, Flight, or the full CategoricalArray/DictionaryArray DSL; those are additive follow-ups on the same arrow-go foundation.
Index ¶
- Variables
- func WriteTableFile(w io.Writer, t *Table) error
- func WriteTableStream(w io.Writer, t *Table) error
- type Array
- func (a *Array) DataType() *DataType
- func (a *Array) Each(fn func(i int, v any) error) error
- func (a *Array) Get(i int) (any, error)
- func (a *Array) Length() int
- func (a *Array) NNulls() int
- func (a *Array) NullQ(i int) bool
- func (a *Array) Release()
- func (a *Array) String() string
- func (a *Array) ToSlice() []any
- func (a *Array) Unwrap() xarrow.Array
- func (a *Array) ValidQ(i int) bool
- type ArrayBuilder
- func (b *ArrayBuilder) Append(v any) error
- func (b *ArrayBuilder) AppendNull() *ArrayBuilder
- func (b *ArrayBuilder) AppendValues(values []any) error
- func (b *ArrayBuilder) DataType() *DataType
- func (b *ArrayBuilder) Finish() *Array
- func (b *ArrayBuilder) Length() int
- func (b *ArrayBuilder) Release()
- type DataType
- func Boolean() *DataType
- func Date() *DataType
- func Decimal128(precision, scale int32) *DataType
- func Float() *DataType
- func Float32() *DataType
- func Float64() *DataType
- func FromArrowType(dt xarrow.DataType) *DataType
- func Int8() *DataType
- func Int16() *DataType
- func Int32() *DataType
- func Int64() *DataType
- func ListOf(elem *DataType) *DataType
- func StringType() *DataType
- func StructOf(fields ...*Field) *DataType
- func Timestamp() *DataType
- func UInt8() *DataType
- func UInt16() *DataType
- func UInt32() *DataType
- func UInt64() *DataType
- type Error
- type ErrorKind
- type Field
- type Format
- type RecordBatch
- func (r *RecordBatch) Column(i int) (*Array, error)
- func (r *RecordBatch) ColumnByName(name string) (*Array, bool)
- func (r *RecordBatch) EachRecord(fn func(row int, values map[string]any) error) error
- func (r *RecordBatch) Get(key any) (*Array, error)
- func (r *RecordBatch) NumColumns() int64
- func (r *RecordBatch) NumRows() int64
- func (r *RecordBatch) Release()
- func (r *RecordBatch) Schema() *Schema
- func (r *RecordBatch) Slice(offset, length int64) (*RecordBatch, error)
- func (r *RecordBatch) String() string
- func (r *RecordBatch) ToHash() map[string][]any
- func (r *RecordBatch) Unwrap() xarrow.RecordBatch
- type Schema
- type Table
- func ConcatTables(tables ...*Table) (*Table, error)
- func DecodeTable(data []byte) (*Table, error)
- func LoadTable(path string) (*Table, error)
- func NewTable(schema *Schema, columns []*Array) (*Table, error)
- func NewTableFromRecordBatches(batches ...*RecordBatch) (*Table, error)
- func ReadTableFile(r io.Reader) (*Table, error)
- func ReadTableStream(r io.Reader) (*Table, error)
- func (t *Table) Column(key any) (*Array, error)
- func (t *Table) EachRecord(fn func(row int, values map[string]any) error) error
- func (t *Table) NumColumns() int64
- func (t *Table) NumRows() int64
- func (t *Table) RecordBatch() *RecordBatch
- func (t *Table) Release()
- func (t *Table) Save(path string, format Format) error
- func (t *Table) Schema() *Schema
- func (t *Table) Slice(offset, length int64) (*Table, error)
- func (t *Table) String() string
- func (t *Table) ToHash() map[string][]any
Constants ¶
This section is empty.
Variables ¶
var ( // ErrArrow matches any [*Error] regardless of kind is not provided; use the // specific sentinels below. ErrType matches KindType errors, etc. ErrType = &Error{Kind: KindType} ErrIndex = &Error{Kind: KindIndex} ErrArgument = &Error{Kind: KindArgument} ErrIO = &Error{Kind: KindIO} ErrNotImplemented = &Error{Kind: KindNotImplemented} )
Sentinel values for errors.Is matching by kind.
Functions ¶
func WriteTableFile ¶
WriteTableFile writes a table to w in the Arrow IPC file / Feather v2 format (Arrow::Table#save with format: :arrow).
Types ¶
type Array ¶
type Array struct {
// contains filtered or unexported fields
}
Array is the pure-Go counterpart of Arrow::Array — an immutable, typed, nullable column. Build one with NewArray (type inferred), NewArrayOf (explicit type), or an ArrayBuilder. It is Enumerable via Array.Each and Array.ToSlice.
func NewArray ¶
NewArray builds an Array from values, inferring the element type from the first non-null value (Arrow::Array.new(values)). Bool infers Boolean, string infers String, floats infer Float64, signed ints infer Int64, unsigned ints infer UInt64, and time.Time infers Timestamp. An empty or all-null slice is an error, as the type cannot be inferred.
func NewArrayOf ¶
NewArrayOf builds an Array of the explicit type dt from values (Arrow::Array.new(values, type: dt)).
func (*Array) Each ¶
Each iterates the elements in order (Arrow::Array#each, Enumerable). It stops and returns the first error fn yields.
func (*Array) Get ¶
Get returns the element at index i (Arrow::Array#[]). It supports Ruby-style negative indexing and returns an *Error of KindIndex when out of range. A null element reads back as nil.
func (*Array) NullQ ¶
NullQ reports whether the element at index i is null (Arrow::Array#null?). It supports Ruby-style negative indexing.
func (*Array) Release ¶
func (a *Array) Release()
Release drops the array's reference to its buffers.
func (*Array) ToSlice ¶
ToSlice returns all elements as a Go slice (Arrow::Array#to_a), nulls as nil.
type ArrayBuilder ¶
type ArrayBuilder struct {
// contains filtered or unexported fields
}
ArrayBuilder is the pure-Go counterpart of Arrow::ArrayBuilder — an appender that accumulates typed values (and nulls) and freezes them into an Array.
func NewArrayBuilder ¶
func NewArrayBuilder(dt *DataType) *ArrayBuilder
NewArrayBuilder returns a builder for the given element type (Arrow::ArrayBuilder.build's typed builder).
func (*ArrayBuilder) Append ¶
func (b *ArrayBuilder) Append(v any) error
Append appends one value, coercing Go scalars to the column type. A nil value appends a null (Arrow::ArrayBuilder#append_value / #append_null).
func (*ArrayBuilder) AppendNull ¶
func (b *ArrayBuilder) AppendNull() *ArrayBuilder
AppendNull appends a null and returns the builder for chaining.
func (*ArrayBuilder) AppendValues ¶
func (b *ArrayBuilder) AppendValues(values []any) error
AppendValues appends each value in order, stopping at the first error (Arrow::ArrayBuilder#append_values).
func (*ArrayBuilder) DataType ¶
func (b *ArrayBuilder) DataType() *DataType
DataType returns the element type this builder produces.
func (*ArrayBuilder) Finish ¶
func (b *ArrayBuilder) Finish() *Array
Finish freezes the accumulated values into an Array and resets the builder (Arrow::ArrayBuilder#finish).
func (*ArrayBuilder) Length ¶
func (b *ArrayBuilder) Length() int
Length returns the number of values appended so far.
func (*ArrayBuilder) Release ¶
func (b *ArrayBuilder) Release()
Release frees the builder's working buffers.
type DataType ¶
type DataType struct {
// contains filtered or unexported fields
}
DataType is the pure-Go counterpart of Ruby's Arrow::DataType. It wraps an arrow-go xarrow.DataType and re-presents it with Ruby naming. Construct one with the type constructors (Int8, StringType, ListOf, StructOf, …).
func Date ¶
func Date() *DataType
Date returns the 32-bit date type — days since the Unix epoch (Arrow::Date32DataType).
func Decimal128 ¶
Decimal128 returns a 128-bit fixed-point decimal type with the given precision and scale (Arrow::Decimal128DataType).
func Float ¶
func Float() *DataType
Float is an alias of Float64, matching red-arrow's default for Ruby Floats.
func Float32 ¶
func Float32() *DataType
Float32 returns the single-precision float type (Arrow::FloatDataType).
func Float64 ¶
func Float64() *DataType
Float64 returns the double-precision float type (Arrow::DoubleDataType).
func FromArrowType ¶
FromArrowType wraps an arbitrary arrow-go data type as a DataType. It is the escape hatch for types this package's constructors do not spell out (for example a type recovered from an externally-produced IPC stream).
func StringType ¶
func StringType() *DataType
StringType returns the UTF-8 string type (Arrow::StringDataType).
func StructOf ¶
StructOf returns a struct type composed of the given fields (Arrow::StructDataType).
func Timestamp ¶
func Timestamp() *DataType
Timestamp returns a microsecond, timezone-naive timestamp type (Arrow::TimestampDataType), the default red-arrow infers for Ruby Time.
func UInt8 ¶
func UInt8() *DataType
UInt8 returns the 8-bit unsigned integer type (Arrow::UInt8DataType).
func (*DataType) Name ¶
Name returns the Arrow type name (e.g. "int64", "utf8"), mirroring Arrow::DataType#name.
type Error ¶
Error is the pure-Go counterpart of red-arrow's Arrow::Error exception tree. It carries the ErrorKind (so the exact Ruby class can be reconstructed) and an optional wrapped cause, and it participates in errors.Is/As via Error.Is and Error.Unwrap.
func (*Error) Is ¶
Is reports whether target is an *Error of the same ErrorKind, letting callers write errors.Is(err, arrow.ErrType) against the sentinel values.
type ErrorKind ¶
type ErrorKind int
ErrorKind identifies which node of red-arrow's exception tree an Error corresponds to. red-arrow raises a small set of Ruby exception classes; the kind records which one so a host (rbgo) can re-raise the faithful class.
const ( // KindError is the base Arrow::Error (a StandardError in Ruby). KindError ErrorKind = iota // KindType maps to Ruby's TypeError — a value did not fit the column type. KindType // KindIndex maps to Ruby's IndexError — an out-of-range row/column. KindIndex // KindArgument maps to Ruby's ArgumentError — a malformed call. KindArgument // KindIO maps to Arrow::Error::Io — an IPC read/write failure. KindIO // KindNotImplemented maps to Ruby's NotImplementedError. KindNotImplemented )
type Field ¶
type Field struct {
// contains filtered or unexported fields
}
Field is the pure-Go counterpart of Arrow::Field — a named, nullable slot in a Schema or struct type.
func NewFieldNonNull ¶
NewFieldNonNull returns a non-nullable field named name of type dt.
func (*Field) NullableQ ¶
NullableQ reports whether the field admits nulls (Arrow::Field#nullable?).
type Format ¶
type Format int
Format selects the Arrow IPC serialization used by Table.Save and produced by the byte encoders, mirroring red-arrow's :arrow_streaming vs :arrow_file.
const ( // FormatStream is the Arrow IPC streaming format (a schema message followed // by record-batch messages and an end-of-stream marker). FormatStream Format = iota // FormatFile is the Arrow IPC file format (a.k.a. Feather v2): the stream // body framed by "ARROW1" magic and a random-access footer. FormatFile )
type RecordBatch ¶
type RecordBatch struct {
// contains filtered or unexported fields
}
RecordBatch is the pure-Go counterpart of Arrow::RecordBatch — a set of equal-length Array columns sharing one Schema. It is the row-batch unit of the Arrow IPC format.
func NewRecordBatch ¶
func NewRecordBatch(schema *Schema, columns []*Array) (*RecordBatch, error)
NewRecordBatch builds a record batch from a schema and one Array per field (Arrow::RecordBatch.new). It returns an *Error if the column count, a column's type, or a column's length does not match the schema.
func (*RecordBatch) Column ¶
func (r *RecordBatch) Column(i int) (*Array, error)
Column returns the i-th column, supporting Ruby-style negative indexing. Out of range yields an *Error of KindIndex.
func (*RecordBatch) ColumnByName ¶
func (r *RecordBatch) ColumnByName(name string) (*Array, bool)
ColumnByName returns the column named name and whether it was found.
func (*RecordBatch) EachRecord ¶
EachRecord yields each row as a column-name-to-value map (Arrow::RecordBatch#each_record). It stops at the first error fn returns.
func (*RecordBatch) Get ¶
func (r *RecordBatch) Get(key any) (*Array, error)
Get returns a column by integer index or by string name (Arrow::RecordBatch#[]).
func (*RecordBatch) NumColumns ¶
func (r *RecordBatch) NumColumns() int64
NumColumns returns the number of columns (Arrow::RecordBatch#n_columns).
func (*RecordBatch) NumRows ¶
func (r *RecordBatch) NumRows() int64
NumRows returns the number of rows (Arrow::RecordBatch#n_rows).
func (*RecordBatch) Release ¶
func (r *RecordBatch) Release()
Release drops the batch's reference to its buffers.
func (*RecordBatch) Schema ¶
func (r *RecordBatch) Schema() *Schema
Schema returns the batch's schema (Arrow::RecordBatch#schema).
func (*RecordBatch) Slice ¶
func (r *RecordBatch) Slice(offset, length int64) (*RecordBatch, error)
Slice returns a zero-copy row slice [offset, offset+length) (Arrow::RecordBatch#slice). Out-of-range bounds yield an *Error of KindIndex.
func (*RecordBatch) String ¶
func (r *RecordBatch) String() string
String returns a compact human-readable summary of the batch.
func (*RecordBatch) ToHash ¶
func (r *RecordBatch) ToHash() map[string][]any
ToHash returns the batch as an ordered column-name-to-values map (Arrow::RecordBatch#to_h). Column order follows the schema.
func (*RecordBatch) Unwrap ¶
func (r *RecordBatch) Unwrap() xarrow.RecordBatch
Unwrap returns the underlying arrow-go record batch.
type Schema ¶
type Schema struct {
// contains filtered or unexported fields
}
Schema is the pure-Go counterpart of Arrow::Schema — an ordered list of [Field]s describing a RecordBatch or Table.
func (*Schema) FieldByName ¶
FieldByName returns the field named name and whether it was found (Arrow::Schema#[] by name).
type Table ¶
type Table struct {
// contains filtered or unexported fields
}
Table is the pure-Go counterpart of Arrow::Table — a schema plus one column per field. Unlike Arrow's chunked table, this materializes to a single record batch, so Table and RecordBatch share observable behaviour; the extra value a Table carries is multi-batch assembly (NewTableFromRecordBatches, ConcatTables) and IPC round-tripping.
func ConcatTables ¶
ConcatTables concatenates the rows of two or more tables sharing a schema (Arrow::Table#concatenate / #combine).
func DecodeTable ¶
DecodeTable reads a table from in-memory Arrow IPC bytes, auto-detecting the file format (by its "ARROW1" magic) versus the streaming format.
func LoadTable ¶
LoadTable reads a table from a file at path, auto-detecting the IPC format (Arrow::Table.load).
func NewTable ¶
NewTable builds a table from a schema and one Array per field (Arrow::Table.new). Errors mirror NewRecordBatch.
func NewTableFromRecordBatches ¶
func NewTableFromRecordBatches(batches ...*RecordBatch) (*Table, error)
NewTableFromRecordBatches assembles one table from a non-empty sequence of record batches, concatenating each column across the batches. The batches must agree on column count and column types; otherwise an *Error is returned.
func ReadTableFile ¶
ReadTableFile reads an Arrow IPC file (Feather v2) from r into a Table (Arrow::Table.load of a file input).
func ReadTableStream ¶
ReadTableStream reads an Arrow IPC stream from r into a Table (Arrow::Table.load of a streaming input). Every record batch in the stream is concatenated into the returned table.
func (*Table) Column ¶
Column returns a column by integer index or by string name (Arrow::Table#[]).
func (*Table) EachRecord ¶
EachRecord yields each row as a column-name-to-value map (Arrow::Table#each_record).
func (*Table) NumColumns ¶
NumColumns returns the number of columns (Arrow::Table#n_columns).
func (*Table) RecordBatch ¶
func (t *Table) RecordBatch() *RecordBatch
RecordBatch returns the table's rows as a single RecordBatch.
func (*Table) Release ¶
func (t *Table) Release()
Release drops the table's reference to its buffers.
func (*Table) Slice ¶
Slice returns the row range [offset, offset+length) as a new table (Arrow::Table#slice).
