Documentation
¶
Overview ¶
Package vng implements the reading and writing of VNG serialization objects. The VNG format is described at https://github.com/brimdata/zed/blob/main/docs/formats/vng.md.
A VNG object is created by allocating an Encoder for any top-level Zed type via NewEncoder, which recursively descends into the Zed type, allocating an Encoder for each node in the type tree. The top-level ZNG body is written via a call to Write. Each vector buffers its data in memory until the object is encoded.
After all of the Zed data is written, a metadata section is written consisting of a single Zed value describing the layout of all the vector data obtained by calling the Metadata method on the Encoder interface.
Nulls are encoded by a special Nulls object. Each type is wrapped by a NullsEncoder, which run-length encodes alternating sequences of nulls and values. If no nulls are encountered, then the Nulls object is omitted from the metadata.
Data is read from a VNG object by reading the metadata and creating vector Builders for each Zed type by calling NewBuilder with the metadata, which recusirvely creates Builders. An io.ReaderAt is passed to NewBuilder so each vector reader can access the underlying storage object and read its vector data effciently in large vector segments.
Once the metadata is assembled in memory, the recontructed Zed sequence data can be read from the vector segments by calling the Build method on the top-level Builder and passing in a zcode.Builder to reconstruct the Zed value.
Index ¶
- Constants
- Variables
- func NewZedReader(zctx *zed.Context, meta Metadata, r io.ReaderAt) (zio.Reader, error)
- func ReadIntVector(loc Segment, r io.ReaderAt) ([]int32, error)
- func ReadUint32Vector(loc Segment, r io.ReaderAt) ([]uint32, error)
- type Array
- type ArrayBuilder
- type ArrayEncoder
- type Builder
- type Const
- type ConstBuilder
- type DictBuilder
- type DictEntry
- type Encoder
- type Error
- type ErrorEncoder
- type Field
- type FieldBuilder
- type FieldEncoder
- type Header
- type Int64Decoder
- type Int64Encoder
- type Map
- type MapBuilder
- type MapEncoder
- type Metadata
- type Named
- type NamedEncoder
- type Nulls
- type NullsBuilder
- type NullsEncoder
- type Object
- type Primitive
- type PrimitiveBuilder
- type PrimitiveEncoder
- type Record
- type RecordBuilder
- type RecordEncoder
- type Segment
- type Set
- type SetEncoder
- type Union
- type UnionBuilder
- type UnionEncoder
- type Variant
- type VariantEncoder
- type Writer
Constants ¶
const ( Version = 4 HeaderSize = 16 MaxMetaSize = 100 * 1024 * 1024 MaxDataSize = 2 * 1024 * 1024 * 1024 )
const ( CompressionFormatNone uint8 = 0 // No compression CompressionFormatLZ4 uint8 = 1 // LZ4 compression )
Values for [Segment.CompressionFormat].
const MaxDictSize = 256
Variables ¶
Functions ¶
func NewZedReader ¶ added in v1.13.0
func ReadIntVector ¶
XXX change this to single vector read
Types ¶
type ArrayBuilder ¶ added in v1.13.0
type ArrayBuilder struct { Elems Builder Lengths *Int64Decoder }
func NewArrayBuilder ¶ added in v1.13.0
func NewArrayBuilder(array *Array, r io.ReaderAt) (*ArrayBuilder, error)
type ArrayEncoder ¶ added in v1.13.0
type ArrayEncoder struct {
// contains filtered or unexported fields
}
func NewArrayEncoder ¶ added in v1.13.0
func NewArrayEncoder(typ *zed.TypeArray) *ArrayEncoder
func (*ArrayEncoder) Encode ¶ added in v1.13.0
func (a *ArrayEncoder) Encode(group *errgroup.Group)
func (*ArrayEncoder) Metadata ¶ added in v1.13.0
func (a *ArrayEncoder) Metadata(off uint64) (uint64, Metadata)
func (*ArrayEncoder) Write ¶ added in v1.13.0
func (a *ArrayEncoder) Write(body zcode.Bytes)
type ConstBuilder ¶ added in v1.13.0
func NewConstBuilder ¶ added in v1.13.0
func NewConstBuilder(c *Const) *ConstBuilder
type DictBuilder ¶ added in v1.13.0
func NewDictBuilder ¶ added in v1.13.0
func NewDictBuilder(primitive *Primitive, reader io.ReaderAt) *DictBuilder
type Encoder ¶ added in v1.13.0
type Encoder interface { // Write collects up values to be encoded into memory. Write(zcode.Bytes) // Encode encodes all in-memory vector data into its storage-ready serialized format. // Vectors may be encoded concurrently and errgroup.Group is used to sync // and return errors. Encode(*errgroup.Group) // Metadata returns the data structure conforming to the VNG specification // describing the layout of vectors. This is called after all data is // written and encoded by the Encode with the result marshaled to build // the header section of the VNG object. An offset is passed down into // the traversal representing where in the data section the vector data // will land. This is called in a sequential fashion (no parallelism) so // that the metadata can be computed and the VNG header written before the // vector data is written via Emit. Metadata(uint64) (uint64, Metadata) Emit(w io.Writer) error }
func NewEncoder ¶ added in v1.13.0
type ErrorEncoder ¶ added in v1.18.0
type ErrorEncoder struct {
Encoder
}
type FieldBuilder ¶ added in v1.13.0
type FieldBuilder struct {
Values Builder
}
func NewFieldBuilder ¶ added in v1.13.0
func NewFieldBuilder(field Field, r io.ReaderAt) (*FieldBuilder, error)
type FieldEncoder ¶ added in v1.13.0
type FieldEncoder struct {
// contains filtered or unexported fields
}
func (*FieldEncoder) Encode ¶ added in v1.13.0
func (f *FieldEncoder) Encode(group *errgroup.Group)
type Header ¶ added in v1.13.0
func (*Header) Deserialize ¶ added in v1.13.0
type Int64Decoder ¶ added in v1.13.0
type Int64Decoder struct {
PrimitiveBuilder
}
func NewInt64Decoder ¶ added in v1.13.0
func NewInt64Decoder(loc Segment, r io.ReaderAt) *Int64Decoder
func (*Int64Decoder) Next ¶ added in v1.13.0
func (p *Int64Decoder) Next() (int64, error)
type Int64Encoder ¶ added in v1.13.0
type Int64Encoder struct {
PrimitiveEncoder
}
func NewInt64Encoder ¶ added in v1.13.0
func NewInt64Encoder() *Int64Encoder
func (*Int64Encoder) Write ¶ added in v1.13.0
func (p *Int64Encoder) Write(v int64)
type MapBuilder ¶ added in v1.13.0
type MapBuilder struct { Keys Builder Values Builder Lengths *Int64Decoder }
func NewMapBuilder ¶ added in v1.13.0
func NewMapBuilder(m *Map, r io.ReaderAt) (*MapBuilder, error)
type MapEncoder ¶ added in v1.13.0
type MapEncoder struct {
// contains filtered or unexported fields
}
func NewMapEncoder ¶ added in v1.13.0
func NewMapEncoder(typ *zed.TypeMap) *MapEncoder
func (*MapEncoder) Encode ¶ added in v1.13.0
func (m *MapEncoder) Encode(group *errgroup.Group)
func (*MapEncoder) Metadata ¶ added in v1.13.0
func (m *MapEncoder) Metadata(off uint64) (uint64, Metadata)
func (*MapEncoder) Write ¶ added in v1.13.0
func (m *MapEncoder) Write(body zcode.Bytes)
type NamedEncoder ¶ added in v1.13.0
type NamedEncoder struct { Encoder // contains filtered or unexported fields }
type NullsBuilder ¶ added in v1.13.0
type NullsBuilder struct { Values Builder Runs Int64Decoder // contains filtered or unexported fields }
func NewNullsBuilder ¶ added in v1.13.0
func NewNullsBuilder(values Builder, loc Segment, r io.ReaderAt) *NullsBuilder
type NullsEncoder ¶ added in v1.13.0
type NullsEncoder struct {
// contains filtered or unexported fields
}
NullsEncoder emits a sequence of runs of the length of alternating sequences of nulls and values, beginning with nulls. Every run is non-zero except for the first, which may be zero when the first value is non-null.
func NewNullsEncoder ¶ added in v1.13.0
func NewNullsEncoder(values Encoder) *NullsEncoder
func (*NullsEncoder) Encode ¶ added in v1.13.0
func (n *NullsEncoder) Encode(group *errgroup.Group)
func (*NullsEncoder) Metadata ¶ added in v1.13.0
func (n *NullsEncoder) Metadata(off uint64) (uint64, Metadata)
func (*NullsEncoder) Write ¶ added in v1.13.0
func (n *NullsEncoder) Write(body zcode.Bytes)
type Object ¶
type Object struct {
// contains filtered or unexported fields
}
func (*Object) DataReader ¶ added in v1.13.0
type Primitive ¶ added in v1.13.0
type PrimitiveBuilder ¶ added in v1.13.0
func NewPrimitiveBuilder ¶ added in v1.13.0
func NewPrimitiveBuilder(primitive *Primitive, reader io.ReaderAt) *PrimitiveBuilder
type PrimitiveEncoder ¶ added in v1.13.0
type PrimitiveEncoder struct {
// contains filtered or unexported fields
}
func NewPrimitiveEncoder ¶ added in v1.13.0
func NewPrimitiveEncoder(typ zed.Type, useDict bool) *PrimitiveEncoder
func (*PrimitiveEncoder) Const ¶ added in v1.13.0
func (p *PrimitiveEncoder) Const() *Const
func (*PrimitiveEncoder) Encode ¶ added in v1.13.0
func (p *PrimitiveEncoder) Encode(group *errgroup.Group)
func (*PrimitiveEncoder) Metadata ¶ added in v1.13.0
func (p *PrimitiveEncoder) Metadata(off uint64) (uint64, Metadata)
func (*PrimitiveEncoder) Write ¶ added in v1.13.0
func (p *PrimitiveEncoder) Write(body zcode.Bytes)
type Record ¶ added in v1.13.0
func (*Record) LookupField ¶ added in v1.13.0
type RecordBuilder ¶ added in v1.13.0
type RecordBuilder struct { Names []string Values []FieldBuilder }
func NewRecordBuilder ¶ added in v1.13.0
func NewRecordBuilder(record *Record, reader io.ReaderAt) (*RecordBuilder, error)
type RecordEncoder ¶ added in v1.13.0
type RecordEncoder struct {
// contains filtered or unexported fields
}
func NewRecordEncoder ¶ added in v1.13.0
func NewRecordEncoder(typ *zed.TypeRecord) *RecordEncoder
func (*RecordEncoder) Encode ¶ added in v1.13.0
func (r *RecordEncoder) Encode(group *errgroup.Group)
func (*RecordEncoder) Metadata ¶ added in v1.13.0
func (r *RecordEncoder) Metadata(off uint64) (uint64, Metadata)
func (*RecordEncoder) Write ¶ added in v1.13.0
func (r *RecordEncoder) Write(body zcode.Bytes)
type Segment ¶ added in v1.13.0
type SetEncoder ¶ added in v1.13.0
type SetEncoder struct {
ArrayEncoder
}
func NewSetEncoder ¶ added in v1.13.0
func NewSetEncoder(typ *zed.TypeSet) *SetEncoder
type UnionBuilder ¶ added in v1.13.0
type UnionBuilder struct {
// contains filtered or unexported fields
}
func NewUnionBuilder ¶ added in v1.13.0
func NewUnionBuilder(union *Union, r io.ReaderAt) (*UnionBuilder, error)
type UnionEncoder ¶ added in v1.13.0
type UnionEncoder struct {
// contains filtered or unexported fields
}
func NewUnionEncoder ¶ added in v1.13.0
func NewUnionEncoder(typ *zed.TypeUnion) *UnionEncoder
func (*UnionEncoder) Encode ¶ added in v1.13.0
func (u *UnionEncoder) Encode(group *errgroup.Group)
func (*UnionEncoder) Metadata ¶ added in v1.13.0
func (u *UnionEncoder) Metadata(off uint64) (uint64, Metadata)
func (*UnionEncoder) Write ¶ added in v1.13.0
func (u *UnionEncoder) Write(body zcode.Bytes)
type VariantEncoder ¶ added in v1.13.0
type VariantEncoder struct {
// contains filtered or unexported fields
}
func NewVariantEncoder ¶ added in v1.13.0
func NewVariantEncoder() *VariantEncoder
func (*VariantEncoder) Encode ¶ added in v1.13.0
func (v *VariantEncoder) Encode() (Metadata, uint64, error)
func (*VariantEncoder) Write ¶ added in v1.13.0
func (v *VariantEncoder) Write(val zed.Value) error
The variant encoder self-organizes around the types that are written to it. No need to define the schema up front! We track the types seen first-come, first-served and the VNG metadata structure follows accordingly.