vector

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2022 License: BSD-3-Clause Imports: 6 Imported by: 0

Documentation

Overview

Package vector implements the organization of Zed data on storage as vectors in a ZST vector storage object.

A ZST object is created by allocating a Writer for any top-level Zed type via NewWriter. The object to be written is wrapped in a Spiller with a vector threshold. Output is streamed to the underlying spiller in a single pass.

NewWriter recursively descends into the Zed type, allocating a Writer for each node in the type tree. The top-level body is written via a call to Write. Each vector buffers its data in memory until it reaches a byte threshold or until Flush is called.

After all of the Zed data is written, a metadata section is written consisting of segment maps for each vector, each obtained by calling the Metadata method on the zst.Writer interface.

Nulls for complex types are encoded by a special Nulls object. Each complex type is wrapped by a NullsWriter, which runlength encodes any 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 ZST file by scanning the metadata maps to build vector Readers for each Zed type by calling NewReader with the metadata, which recusirvely builds reassembly segments. An io.ReaderAt is passed to NewReader so each vector reader can access the underlying storage object and read its vector data effciently in largish vector segments.

Once the metadata is assembled in memory, the recontructed Zed sequence data can be read from the vector segments by calling the Read method on the top-level Reader and passing in a zcode.Builder to reconstruct the Zed value in place.

Index

Constants

View Source
const MaxSegmentThresh = 20 * 1024 * 1024

Variables

View Source
var ErrVectorMismatch = errors.New("zng record value doesn't match vector writer")
View Source
var Template = []interface{}{
	Record{},
	Array{},
	Set{},
	Map{},
	Union{},
	Primitive{},
	Named{},
	Nulls{},
}

Functions

This section is empty.

Types

type Array

type Array struct {
	Lengths []Segment
	Values  Metadata
}

func (*Array) Type

func (a *Array) Type(zctx *zed.Context) zed.Type

type ArrayReader

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

func NewArrayReader

func NewArrayReader(array *Array, r io.ReaderAt) (*ArrayReader, error)

func (*ArrayReader) Read

func (a *ArrayReader) Read(b *zcode.Builder) error

type ArrayWriter

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

func NewArrayWriter

func NewArrayWriter(inner zed.Type, spiller *Spiller) *ArrayWriter

func (*ArrayWriter) Flush

func (a *ArrayWriter) Flush(eof bool) error

func (*ArrayWriter) Metadata

func (a *ArrayWriter) Metadata() Metadata

func (*ArrayWriter) Write

func (a *ArrayWriter) Write(body zcode.Bytes) error

type Field

type Field struct {
	Name   string
	Values Metadata
}

type FieldReader

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

func NewFieldReader

func NewFieldReader(field Field, r io.ReaderAt) (*FieldReader, error)

func (*FieldReader) Read

func (f *FieldReader) Read(b *zcode.Builder) error

type FieldWriter

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

func (*FieldWriter) Flush

func (f *FieldWriter) Flush(eof bool) error

func (*FieldWriter) Metadata

func (f *FieldWriter) Metadata() Field

type Int64Reader

type Int64Reader struct {
	PrimitiveReader
}

func NewInt64Reader

func NewInt64Reader(segmap []Segment, r io.ReaderAt) *Int64Reader

func (*Int64Reader) Read

func (p *Int64Reader) Read() (int64, error)

type Int64Writer

type Int64Writer struct {
	PrimitiveWriter
}

func NewInt64Writer

func NewInt64Writer(spiller *Spiller) *Int64Writer

func (*Int64Writer) Write

func (p *Int64Writer) Write(v int64) error

type Map

type Map struct {
	Lengths []Segment
	Keys    Metadata
	Values  Metadata
}

func (*Map) Type

func (m *Map) Type(zctx *zed.Context) zed.Type

type MapReader

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

func NewMapReader

func NewMapReader(m *Map, r io.ReaderAt) (*MapReader, error)

func (*MapReader) Read

func (m *MapReader) Read(b *zcode.Builder) error

type MapWriter

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

func NewMapWriter

func NewMapWriter(typ *zed.TypeMap, spiller *Spiller) *MapWriter

func (*MapWriter) Flush

func (m *MapWriter) Flush(eof bool) error

func (*MapWriter) Metadata

func (m *MapWriter) Metadata() Metadata

func (*MapWriter) Write

func (m *MapWriter) Write(body zcode.Bytes) error

type Metadata

type Metadata interface {
	Type(*zed.Context) zed.Type
}

func Under

func Under(meta Metadata) Metadata

type Named

type Named struct {
	Name   string
	Values Metadata
}

func (*Named) Type

func (n *Named) Type(zctx *zed.Context) zed.Type

type NamedWriter

type NamedWriter struct {
	Writer
	// contains filtered or unexported fields
}

func (*NamedWriter) Metadata

func (n *NamedWriter) Metadata() Metadata

type Nulls

type Nulls struct {
	Runs   []Segment
	Values Metadata
}

func (*Nulls) Type

func (n *Nulls) Type(zctx *zed.Context) zed.Type

type NullsReader

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

func NewNullsReader

func NewNullsReader(vals Reader, segmap []Segment, r io.ReaderAt) *NullsReader

func (*NullsReader) Read

func (n *NullsReader) Read(b *zcode.Builder) error

type NullsWriter

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

NullsWriter 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 NewNullsWriter

func NewNullsWriter(values Writer, spiller *Spiller) *NullsWriter

func (*NullsWriter) Flush

func (n *NullsWriter) Flush(eof bool) error

func (*NullsWriter) Metadata

func (n *NullsWriter) Metadata() Metadata

func (*NullsWriter) Write

func (n *NullsWriter) Write(body zcode.Bytes) error

type Primitive

type Primitive struct {
	Typ    zed.Type `zed:"Type"`
	Segmap []Segment
}

func (*Primitive) Type

func (p *Primitive) Type(zctx *zed.Context) zed.Type

type PrimitiveReader

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

func NewPrimitiveReader

func NewPrimitiveReader(primitive *Primitive, reader io.ReaderAt) *PrimitiveReader

func (*PrimitiveReader) Read

func (p *PrimitiveReader) Read(b *zcode.Builder) error

type PrimitiveWriter

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

func NewPrimitiveWriter

func NewPrimitiveWriter(typ zed.Type, spiller *Spiller) *PrimitiveWriter

func (*PrimitiveWriter) Flush

func (p *PrimitiveWriter) Flush(eof bool) error

func (*PrimitiveWriter) Metadata

func (p *PrimitiveWriter) Metadata() Metadata

func (*PrimitiveWriter) Segmap

func (p *PrimitiveWriter) Segmap() []Segment

func (*PrimitiveWriter) Write

func (p *PrimitiveWriter) Write(body zcode.Bytes) error

type Reader

type Reader interface {
	Read(*zcode.Builder) error
}

func NewReader

func NewReader(meta Metadata, r io.ReaderAt) (Reader, error)

type Record

type Record struct {
	Fields []Field
}

func (*Record) Lookup

func (r *Record) Lookup(path field.Path) *Field

func (*Record) LookupField

func (r *Record) LookupField(name string) *Field

func (*Record) Type

func (r *Record) Type(zctx *zed.Context) zed.Type

type RecordReader

type RecordReader []FieldReader

func NewRecordReader

func NewRecordReader(record *Record, reader io.ReaderAt) (RecordReader, error)

func (RecordReader) Read

func (r RecordReader) Read(b *zcode.Builder) error

type RecordWriter

type RecordWriter []*FieldWriter

func NewRecordWriter

func NewRecordWriter(typ *zed.TypeRecord, spiller *Spiller) RecordWriter

func (RecordWriter) Flush

func (r RecordWriter) Flush(eof bool) error

func (RecordWriter) Metadata

func (r RecordWriter) Metadata() Metadata

func (RecordWriter) Write

func (r RecordWriter) Write(body zcode.Bytes) error

type Segment

type Segment struct {
	Offset int64
	Length int32
}

func (Segment) NewSectionReader

func (s Segment) NewSectionReader(r io.ReaderAt) io.Reader

type Set

type Set Array

func (*Set) Type

func (s *Set) Type(zctx *zed.Context) zed.Type

type SetWriter

type SetWriter struct {
	ArrayWriter
}

func NewSetWriter

func NewSetWriter(inner zed.Type, spiller *Spiller) *SetWriter

func (*SetWriter) Metadata

func (s *SetWriter) Metadata() Metadata

type Spiller

type Spiller struct {
	Thresh int
	// contains filtered or unexported fields
}

func NewSpiller

func NewSpiller(w io.Writer, thresh int) *Spiller

func (*Spiller) Position

func (s *Spiller) Position() int64

func (*Spiller) Write

func (s *Spiller) Write(segments []Segment, b zcode.Bytes) ([]Segment, error)

type Union

type Union struct {
	Tags   []Segment
	Values []Metadata
}

func (*Union) Type

func (u *Union) Type(zctx *zed.Context) zed.Type

type UnionReader

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

func NewUnionReader

func NewUnionReader(union *Union, r io.ReaderAt) (*UnionReader, error)

func (*UnionReader) Read

func (u *UnionReader) Read(b *zcode.Builder) error

type UnionWriter

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

func NewUnionWriter

func NewUnionWriter(typ *zed.TypeUnion, spiller *Spiller) *UnionWriter

func (*UnionWriter) Flush

func (u *UnionWriter) Flush(eof bool) error

func (*UnionWriter) Metadata

func (u *UnionWriter) Metadata() Metadata

func (*UnionWriter) Write

func (u *UnionWriter) Write(body zcode.Bytes) error

type Writer

type Writer interface {
	// Write encodes the given value into memory.  When the vector exceeds
	// a threshold, it is automatically flushed.  Flush may also be called
	// explicitly to push vectors to storage and thus avoid too much row skew
	// between vectors.
	Write(zcode.Bytes) error
	// Push all in-memory vector data to the storage layer.
	Flush(bool) error
	// Metadata returns the data structure conforming to the ZST specification
	// describing the layout of vectors.  This is called after all data is
	// written and flushed by the Writer with the result marshaled to build
	// the metadata section of the ZST file.
	Metadata() Metadata
}

func NewWriter

func NewWriter(typ zed.Type, spiller *Spiller) Writer

Jump to

Keyboard shortcuts

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