cdata

package
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 23, 2026 License: Apache-2.0 Imports: 14 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package cdata implements the Arrow C Data Interface and the Arrow C Stream Interface in pure Go.

The structs in this file are the ABI shared with foreign producers and consumers. Their field order, sizes, and alignment must match the C definitions in the Arrow specification. Release fields are function pointers represented as uintptr so they can be installed with purego callbacks and invoked with purego.SyscallN without cgo.

All ownership is explicit:

  • ImportSchema borrows the source schema. It neither moves nor releases it.
  • ImportArray and ImportRecordBatch take ownership of the source array, move it into Go owned memory, and invoke the producer's release callback exactly once when the last imported Arrow buffer is released.
  • Export operations transfer ownership of the emitted structure to the caller. The caller must invoke the release callback exactly once, either on the original structure or on a bitwise copy that has been moved out of the original location.
  • Release callbacks may receive the address of a bitwise copy of the structure. They must therefore not infer ownership from the address and must keep their bookkeeping in PrivateData.

Index

Constants

View Source
const (
	FlagDictionaryOrdered int64 = 1 << 0
	FlagNullable          int64 = 1 << 1
	FlagMapKeysSorted     int64 = 1 << 2
)

ArrowSchema flags from the C Data Interface specification.

Variables

View Source
var (
	// ErrInvalid reports malformed or inconsistent Arrow C data.
	ErrInvalid = errors.New("cdata: invalid Arrow C data")
	// ErrUnsupported reports an Arrow type that this package does not bridge.
	ErrUnsupported = errors.New("cdata: unsupported Arrow type")
)

Functions

func CopyBorrowedRecordBatch

func CopyBorrowedRecordBatch(src *ArrowArray, srcSchema *ArrowSchema) (arrow.RecordBatch, error)

CopyBorrowedRecordBatch copies a borrowed C record batch into Go-owned memory.

The mapper callback receives an ArrowArray/ArrowSchema pair that is valid only for the duration of the callback. ImportRecordBatch normally takes ownership of its source, which is not allowed for a borrowed producer value. This helper imports a shallow copy of the array structure whose release callbacks are neutralized, then copies every Arrow buffer into Go memory. The producer's array and release callback are left untouched.

The returned batch owns all of its buffers and remains valid after the native callback returns. The schema is imported before the array so the existing import validation is reused for both layouts.

func ExportArray

func ExportArray(arr arrow.Array, dst *ArrowArray) error

ExportArray exports arr into dst. On success dst owns the release callback and the caller must release it exactly once. The Go array and its buffers are retained and pinned until that release. On error dst is zeroed.

func ExportField

func ExportField(field arrow.Field, dst *ArrowSchema) error

ExportField exports one field, including its metadata, into dst. On success the caller owns dst and must release it exactly once. On error dst is zeroed and no resources are leaked.

func ExportRecordBatch

func ExportRecordBatch(batch arrow.RecordBatch, dst *ArrowArray) error

ExportRecordBatch exports batch as a struct array with one child per column. The batch is retained until the destination's release callback is invoked.

func ExportRecordReader

func ExportRecordReader(reader array.RecordReader, dst *ArrowArrayStream) error

ExportRecordReader exports reader as an Arrow C stream. On success dst owns the stream and the caller must invoke its release callback exactly once, possibly after moving the structure. The reader is retained until release. On error dst is zeroed.

func ExportSchema

func ExportSchema(schema *arrow.Schema, dst *ArrowSchema) error

ExportSchema exports schema into dst. On success dst owns the release callback and the caller must release it exactly once, possibly after moving the structure to another address. On error dst is zeroed and no resources are leaked.

func FormatOf

func FormatOf(dt arrow.DataType) (string, error)

FormatOf returns the Arrow C Data Interface format string for dt.

Dictionary types use the format string of their index type; the dictionary values are carried by a separate ArrowSchema.

func ImportArray

func ImportArray(src *ArrowArray, dt arrow.DataType) (arrow.Array, error)

ImportArray imports src and transfers ownership of the C structure to Go.

On success src.Release is set to zero and the producer's release callback will be invoked exactly once, when the last Arrow buffer reachable from the returned array is released. This includes buffers reached through slices, children, and dictionaries. On error src is consumed as well: its release callback is invoked exactly once if it had one.

ImportArray does not copy array buffers. The caller must keep the foreign buffers valid until the returned array is released.

Ownership is unambiguous on every path: if src is non-nil and has a non-zero release callback, ImportArray either moves that callback into the returned array's buffer owner or invokes it before returning an error. A nil src or a src without a release callback has no ownership to transfer.

func ImportField

func ImportField(src *ArrowSchema) (arrow.Field, error)

ImportField imports one field from a borrowed ArrowSchema.

Unlike ImportSchema, src may describe any Arrow type rather than a record batch root. src remains owned by the caller and is not released.

func ImportRecordBatch

func ImportRecordBatch(src *ArrowArray, schema *arrow.Schema) (arrow.RecordBatch, error)

ImportRecordBatch imports a C ArrowArray that contains a struct of columns.

The source array is moved and its release callback is invoked exactly once, after the last imported column buffer is released. On every error path the source is consumed in the same way, so a failed import does not leak a producer-owned array. A nil source or a source without a release callback has no ownership to transfer. The root struct's row validity bitmap is not representable in arrow.RecordBatch; ImportRecordBatch therefore rejects a root with a non-zero null count.

func ImportSchema

func ImportSchema(src *ArrowSchema) (*arrow.Schema, error)

ImportSchema imports an ArrowSchema as a record batch schema. The source structure is borrowed: ImportSchema does not move it and does not invoke or clear its release callback. The returned schema owns copies of all strings and metadata.

func ParseFormat

func ParseFormat(format string) (arrow.DataType, error)

ParseFormat parses an Arrow C Data Interface format string into a data type. Nested formats (list, struct, map, fixed-size list) return their container type without children; callers that need children must use ImportSchema.

func ReleaseArray

func ReleaseArray(src *ArrowArray)

ReleaseArray invokes src.Release exactly once if it is non-zero. Its semantics match ReleaseSchema, including support for moved structures.

func ReleaseSchema

func ReleaseSchema(src *ArrowSchema)

ReleaseSchema invokes src.Release if it is non-zero. The producer marks the structure released inside its callback. It is safe for nil or already released structures, foreign producers, and structures copied away from their original address. It does not clear src.PrivateData: the producer's release callback owns that state and may still need it.

func ReleaseStream

func ReleaseStream(src *ArrowArrayStream)

ReleaseStream invokes src.Release exactly once if it is non-zero. Its semantics match ReleaseSchema, including support for moved structures.

Types

type ArrowArray

type ArrowArray struct {
	Length      int64
	NullCount   int64
	Offset      int64
	NBuffers    int64
	NChildren   int64
	Buffers     *unsafe.Pointer
	Children    **ArrowArray
	Dictionary  *ArrowArray
	Release     uintptr
	PrivateData unsafe.Pointer
}

ArrowArray mirrors struct ArrowArray.

type ArrowArrayStream

type ArrowArrayStream struct {
	GetSchema    uintptr
	GetNext      uintptr
	GetLastError uintptr
	Release      uintptr
	PrivateData  unsafe.Pointer
}

ArrowArrayStream mirrors struct ArrowArrayStream.

type ArrowSchema

type ArrowSchema struct {
	Format      *byte
	Name        *byte
	Metadata    *byte
	Flags       int64
	NChildren   int64
	Children    **ArrowSchema
	Dictionary  *ArrowSchema
	Release     uintptr
	PrivateData unsafe.Pointer
}

ArrowSchema mirrors struct ArrowSchema.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL