expr

package
v0.19.0 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2020 License: BSD-3-Clause Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrBadArgument = errors.New("bad argument")
View Source
var ErrBadCast = errors.New("bad cast")
View Source
var ErrIncompatibleTypes = errors.New("incompatible types")
View Source
var ErrIndexOutOfBounds = errors.New("array index out of bounds")
View Source
var ErrNoSuchField = errors.New("field is not present")
View Source
var ErrNoSuchFunction = errors.New("no such function")
View Source
var ErrNotContainer = errors.New("cannot apply in to a non-container")
View Source
var ErrTooFewArgs = errors.New("too few arguments")
View Source
var ErrTooManyArgs = errors.New("too many arguments")

Functions

func FieldExprToString added in v0.6.0

func FieldExprToString(node ast.FieldExpr) string

FieldExprToString returns ZQL for the ast.FieldExpr in node.

func LookupCompare added in v0.16.0

func LookupCompare(typ zng.Type) comparefn

func SortStable

func SortStable(records []*zng.Record, compare CompareFn)

SortStable performs a stable sort on the provided records.

Types

type CompareFn added in v0.16.0

type CompareFn func(a *zng.Record, b *zng.Record) int

func NewCompareFn added in v0.16.0

func NewCompareFn(nullsMax bool, fields ...FieldExprResolver) CompareFn

NewCompareFn creates a function that compares a pair of Records based on the provided ordered list of fields. The returned function uses the same return conventions as standard routines such as bytes.Compare() and strings.Compare(), so it may be used with packages such as heap and sort. The handling of records in which a comparison field is unset or not present (collectively refered to as fields in which the value is "null") is governed by the nullsMax parameter. If this parameter is true, a record with a null value is considered larger than a record with any other value, and vice versa.

type ExpressionEvaluator added in v0.6.0

type ExpressionEvaluator func(*zng.Record) (zng.Value, error)

func CompileExpr added in v0.6.0

func CompileExpr(node ast.Expression) (ExpressionEvaluator, error)

CompileExpr tries to compile the given Expression into a function that evalutes the expression against a provided Record. Returns an error if compilation fails for any reason.

This is currently not particularly optimized -- it creates a bunch of closures and every evaluation involves some allocations. Eventually, we could optimize this by compiling a particular Expression for a particular TypeRecord into a series of byte codes that could be implemented by a simple stack-based evaluator much more efficiently. ZNG unions are a challenge for this approach, but we could fail back to the "slow path" implemented here if an expression ever touches a union.

type FieldExprResolver

type FieldExprResolver func(*zng.Record) zng.Value

A FieldExprResolver is a compiled FieldExpr (where FieldExpr is the abstract type representing various zql ast nodes). This can be an expression as simple as "fieldname" or something more complex such as "len(vec[2].fieldname.subfieldname)". A FieldExpr is compiled into a function that takes a zbuf.Record as input, evaluates the given expression against that record, and returns the resulting typed value. If the expression can't be resolved (i.e., because some field reference refers to a non-existent field, an array index is out of bounds, etc.), the resolver returns (nil, nil)

func CompileFieldAccess added in v0.12.0

func CompileFieldAccess(s string) FieldExprResolver

func CompileFieldExpr

func CompileFieldExpr(node ast.FieldExpr) (FieldExprResolver, error)

CompileFieldExpr() takes a FieldExpr AST (which represents either a simple field reference like "fieldname" or something more complex like "fieldname[0].subfield.subsubfield[3]") and compiles it into a FieldExprResolver -- a function that takes a zbuf.Record and extracts the value to which the FieldExpr refers. If the FieldExpr cannot be compiled, this function returns an error. If the resolver is given a record for which the given expression cannot be evaluated (e.g., if the record doesn't have a requested field or an array index is out of bounds), the resolver returns (nil, nil).

func CompileFieldExprs added in v0.4.1

func CompileFieldExprs(nodes []ast.FieldExpr) ([]FieldExprResolver, error)

CompileFieldExprs calls CompileFieldExpr for each element of nodes.

type Function added in v0.6.1

type Function func([]zngnative.Value) (zngnative.Value, error)

type KeyCompareFn added in v0.14.0

type KeyCompareFn func(*zng.Record) int

func NewKeyCompareFn added in v0.14.0

func NewKeyCompareFn(key *zng.Record) (KeyCompareFn, error)

type NativeEvaluator added in v0.6.0

type NativeEvaluator func(*zng.Record) (zngnative.Value, error)

type RecordSlice

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

func NewRecordSlice

func NewRecordSlice(compare CompareFn) *RecordSlice

func (*RecordSlice) Index

func (r *RecordSlice) Index(i int) *zng.Record

Index returns the ith record.

func (*RecordSlice) Len

func (r *RecordSlice) Len() int

Swap implements sort.Interface for *Record slices.

func (*RecordSlice) Less

func (r *RecordSlice) Less(i, j int) bool

Less implements sort.Interface for *Record slices.

func (*RecordSlice) Pop

func (r *RecordSlice) Pop() interface{}

Pop removes the first element in the array. Implements heap.Interface.

func (*RecordSlice) Push

func (r *RecordSlice) Push(rec interface{})

Push adds x as element Len(). Implements heap.Interface.

func (*RecordSlice) Swap

func (r *RecordSlice) Swap(i, j int)

Swap implements sort.Interface for *Record slices.

type ValueCompareFn added in v0.16.0

type ValueCompareFn func(a zng.Value, b zng.Value) int

func NewValueCompareFn added in v0.16.0

func NewValueCompareFn(nullsMax bool) ValueCompareFn

Jump to

Keyboard shortcuts

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