array

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2026 License: MIT Imports: 21 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 array decodes the serialized arrays of a flat segment into in-memory arrays. One file per encoding, found by its identifier through the footer's array specs.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Encodings

func Encodings() []string

Encodings lists the identifiers of the encodings that have a decoder.

Types

type Arena

type Arena struct {
	// contains filtered or unexported fields
}

Arena is the buffers of the arrays of one decode, taken from a pool and given back together by Release. The nil arena allocates, and gives nothing back. An arena is used by one goroutine at a time.

func (*Arena) Bytes

func (a *Arena) Bytes(n int, zero bool) []byte

Bytes returns n bytes, aligned for any number: unsafex.Slice shares them. They are zero when zero is set, and anything otherwise: the caller then writes every one of them.

func (*Arena) Ints

func (a *Arena) Ints(n int, zero bool) []int

Ints is Bytes for ints.

func (*Arena) Release

func (a *Arena) Release()

Release gives the buffers of the arena back to its pool: the arrays made in it must not be read any more. The arena is empty, and can be used again.

type Array

type Array struct {
	// Skipped is set when the array was not decoded because of an unsupported encoding,
	// and the caller accepted it (Options.Tolerate). The other fields are empty then.
	Skipped error
	// Validity is nil when every value is valid. It is ignored for the Null type.
	Validity *Bitmap
	// Elems is the elements of a List, a FixedSizeList and a Map (a struct of key and value).
	Elems *Array
	// Var is the content of a Variant array.
	Var *VariantData
	// Data is, for Prim, the values, little-endian; for Decimal, the values at Width bytes
	// each, little-endian two's complement; for Utf8 and Binary, the bytes Starts and Ends
	// point into.
	Data []byte
	// Starts and Ends are, per row, the range of Data (Utf8, Binary) or of Elems (List, Map)
	// of the row. Ranges may overlap and come in any order, but stay inside their target.
	Starts, Ends []int
	Fields       []*Array
	Bits         Bitmap // Bool: the values

	Type  DType
	Width int // Decimal: the bytes of a stored value
	Len   int
	// VOff is, for a Variant array, the row of Var that row 0 is.
	VOff int
	// contains filtered or unexported fields
}

Array is a decoded array. Only the fields of its Type are set.

func Concat

func Concat(t DType, parts []*Array) *Array

Concat joins arrays of type t into one.

func Decode

func Decode(seg []byte, specs []string, t DType, rows int, opt Options) (*Array, error)

Decode decodes the serialized array of seg: its buffers, the flatbuffer of the tree, then the length of the flatbuffer. specs are the array specs of the footer, rows the number of rows and t the type the array must have.

func TakeDict

func TakeDict(ar *Arena, values, codes *Array, p PType, t DType) (*Array, error)

TakeDict makes the array of type t, in the arena ar, whose row i is the value of values at the code of row i of codes, an array of integers of type p. A null code is a null row. A code past the values is an error. When values or codes were skipped, the result is skipped too.

func TakeDictInto

func TakeDictInto(out *Array, ar *Arena, values, codes *Array, p PType, t DType) (*Array, error)

TakeDictInto is TakeDict into out, which it overwrites and returns when the values are numbers, bytes or lists: it then allocates nothing but the buffers of the rows.

func (*Array) Null

func (a *Array) Null(i int) bool

Null reports whether row i is null.

func (*Array) Slice

func (a *Array) Slice(off, n int) *Array

Slice returns the n rows from row off, sharing the memory.

func (*Array) SliceInto

func (a *Array) SliceInto(out *Array, off, n int) *Array

SliceInto is Slice into out, which it overwrites and returns. It allocates nothing when out was filled by an earlier SliceInto of an array of the same shape: the children of a struct or of a fixed-size list are sliced into the ones out already has. out must not share any node with a.

func (*Array) VariantValue

func (a *Array) VariantValue(i int, dec variant.DecimalFunc) (any, error)

VariantValue returns row i of a Variant array as a Go value: nil, bool, int64, float64, string, []byte, time.Time, []any, map[string]any, or what dec returns for a decimal given its unscaled little-endian bytes and its scale. It allocates.

type Bitmap

type Bitmap struct {
	Bytes []byte
	Off   int
}

Bitmap is a sequence of bits, the first one being bit Off of Bytes (least significant bit first).

func (Bitmap) Get

func (b Bitmap) Get(i int) bool

Get returns bit i.

func (Bitmap) Slice

func (b Bitmap) Slice(i int) Bitmap

Slice returns the bits from bit i. The offset stays under 8.

type DType

type DType struct {
	Storage *DType // Ext
	// Elem is the element type of a List or a FixedSizeList, and the entry type (a struct of
	// key and value) of a Map.
	Elem   *DType
	Label  string  // Ext: the identifier of the extension type, when it comes from a protobuf DType
	Fields []Field // Struct
	Size   int     // FixedSizeList: the number of elements of every value
	Kind   Kind
	PType  PType
	Scale  int8 // Decimal, when the type comes from a protobuf DType
	// Nullable is whether the array may hold nulls.
	Nullable bool
	// Ticks is, on the storage of a timestamp, the number of ticks of its unit in a second.
	Ticks int32
}

DType is the type an array must decode to. It is not stored in the array: the parent gives it.

func ParseDType

func ParseDType(b []byte) (DType, error)

ParseDType decodes a DType in protobuf, as an array stores it in its metadata. A date, a time and a timestamp are an Ext of their storage, with the identifier in Label.

func (DType) NonNullable

func (t DType) NonNullable() DType

NonNullable returns t, but not nullable.

func (DType) String

func (t DType) String() string

String describes the type in a message.

type Decoder

type Decoder func(n *Node, t DType, rows int) (*Array, error)

Decoder builds the array of the given type and number of rows from a node.

type Field

type Field struct {
	Name string
	Type DType
}

Field is a named field of a struct type.

type Kind

type Kind uint8

Kind is the shape of a DType, as far as the decoders care.

const (
	Null Kind = iota
	Bool
	Prim
	Struct
	Ext
	Utf8
	Binary
	Decimal
	List
	FixedSizeList
	Map
	Variant
)

The shapes the decoders know.

type Node

type Node struct {
	// contains filtered or unexported fields
}

Node is a node of the tree of a serialized array, as a decoder sees it.

func (*Node) Buffer

func (n *Node) Buffer(i int) ([]byte, error)

Buffer returns buffer i of the node.

func (*Node) Child

func (n *Node) Child(i int, t DType, rows int) (*Array, error)

Child decodes child i as an array of type t with the given number of rows.

func (*Node) ChildEncoding

func (n *Node) ChildEncoding(i int) string

ChildEncoding is the identifier of the encoding that Child decodes child i with, "" when the footer has none for it.

func (*Node) Field

func (n *Node) Field(i int, name string, t DType, rows int) (*Array, error)

Field decodes child i as the struct field called name. When it fails with an unsupported encoding and Options.Tolerate accepts it, the result is an Array with Skipped set.

func (*Node) Metadata

func (n *Node) Metadata() []byte

Metadata is the protobuf of the encoding.

func (*Node) NumBuffers

func (n *Node) NumBuffers() int

NumBuffers is the number of buffers.

func (*Node) NumChildren

func (n *Node) NumChildren() int

NumChildren is the number of children.

func (*Node) Validity

func (n *Node) Validity(i, rows int) (*Bitmap, error)

Validity decodes child i as the validity of an array of the given number of rows.

type Options

type Options struct {
	// Tolerate is asked, for a struct field whose decoding failed with an unsupported
	// encoding, whether to carry on: the field then is an Array with Skipped set. The path
	// is the dotted names of the fields from the root. Tests use it, a scan never does.
	Tolerate func(path string, err error) bool
	// Pool, when not nil, is where a scan takes the buffers of its arrays from.
	Pool *Pool
	// Arena, when not nil, is where the buffers of the decoded array come from: the array
	// must not be read once the arena is released.
	Arena *Arena
	// MaxRows, when not 0, is the most rows of any node: the rows of a child come from the
	// file (the elements of a list, the codes of a dictionary), and a node that expands
	// without a buffer to bound it (a constant, a sequence) allocates as many.
	MaxRows int
}

Options changes how an array is decoded.

type PType

type PType uint8

PType is a primitive number type.

const (
	U8 PType = iota
	U16
	U32
	U64
	I8
	I16
	I32
	I64
	F16
	F32
	F64
)

The primitive types.

func (PType) Float

func (p PType) Float() bool

Float reports whether p is a floating-point type.

func (PType) Signed

func (p PType) Signed() bool

Signed reports whether p is a signed integer.

func (PType) String

func (p PType) String() string

String returns "u8", "i64", "f16"...

func (PType) Width

func (p PType) Width() int

Width is the size of a value in bytes.

type Pool

type Pool struct {
	// contains filtered or unexported fields
}

Pool keeps the buffers of the arrays a scan is done with, for the arrays it decodes next: a scan then works in the same memory from one batch to the next. It is safe for concurrent use.

func (*Pool) Forget

func (p *Pool) Forget()

Forget drops the retired arenas without releasing them: the scan ended, and what its last batch reads stays as it is.

func (*Pool) NewArena

func (p *Pool) NewArena() *Arena

NewArena returns an arena of the pool. A nil pool has the nil arena.

func (*Pool) Recycle

func (p *Pool) Recycle()

Recycle releases the retired arenas: the consumer has moved on to the next batch.

func (*Pool) Retire

func (p *Pool) Retire(a *Arena)

Retire records that the arrays of the arena are read by the current batch at most: Recycle releases it.

type Rows

type Rows struct {
	// contains filtered or unexported fields
}

Rows is a serialized array whose rows are decoded some at a time.

func OpenRows

func OpenRows(seg []byte, specs []string, opt Options) (*Rows, error)

OpenRows reads the tree of the serialized array of seg, like Decode does, and decodes nothing: Decode does, for the rows it is given.

func (*Rows) Can

func (r *Rows) Can() bool

Can reports whether every encoding on the way to the rows of the array decodes some rows only: Decode is then ok, unless the array is not what its tree says.

func (*Rows) Decode

func (r *Rows) Decode(t DType, rows int, idx []int, ar *Arena) (*Array, bool, error)

Decode decodes the rows idx, in increasing order, of the array, of type t and of that many rows, into buffers of the arena ar: row k of the result is row idx[k] of the array. It is not ok when an encoding of the array has no way to decode some rows only: the caller then decodes all of them.

type VariantData

type VariantData struct {
	Metadata, Value, Typed *Array
	Core, Shredded         *Array
	Parts                  []*Array
	// TypedType is the type of Typed or of Shredded, which the arrays alone cannot tell: an
	// extension type decodes as its storage.
	TypedType DType
}

VariantData is what a Variant array holds. There are three shapes.

A Parquet one (vortex.parquet.variant) has Metadata, the key dictionary of each row, Value, the encoded value of each row (nil when the array has none), and Typed, the shredded typed_value (nil when it has none), in the layout of Parquet: the fields of a shredded object are structs of a "value" and a "typed_value".

A logical one (vortex.variant with a shredded child) has Core, a Variant array of the first shape without typed_value, and Shredded, the typed values with no wrapper: a shredded object is a struct of its fields, a field that is itself partly shredded being a Variant array.

A chunked one has the Parts it was joined from.

Jump to

Keyboard shortcuts

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