Documentation
¶
Index ¶
- Variables
- func FieldExprToString(node ast.FieldExpr) string
- func LookupCompare(typ zng.Type) comparefn
- func SortStable(records []*zng.Record, compare CompareFn)
- type CompareFn
- type ExpressionEvaluator
- type FieldExprResolver
- type Function
- type KeyCompareFn
- type NativeEvaluator
- type RecordSlice
- type ValueCompareFn
Constants ¶
This section is empty.
Variables ¶
var ErrBadArgument = errors.New("bad argument")
var ErrBadCast = errors.New("bad cast")
var ErrIncompatibleTypes = errors.New("incompatible types")
var ErrIndexOutOfBounds = errors.New("array index out of bounds")
var ErrNoSuchField = errors.New("field is not present")
var ErrNoSuchFunction = errors.New("no such function")
var ErrNotContainer = errors.New("cannot apply in to a non-container")
var ErrTooFewArgs = errors.New("too few arguments")
var ErrTooManyArgs = errors.New("too many arguments")
Functions ¶
func FieldExprToString ¶ added in v0.6.0
FieldExprToString returns ZQL for the ast.FieldExpr in node.
func LookupCompare ¶ added in v0.16.0
func SortStable ¶
SortStable performs a stable sort on the provided records.
Types ¶
type CompareFn ¶ added in v0.16.0
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
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 ¶
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 KeyCompareFn ¶ added in v0.14.0
func NewKeyCompareFn ¶ added in v0.14.0
func NewKeyCompareFn(key *zng.Record) (KeyCompareFn, error)
type NativeEvaluator ¶ added in v0.6.0
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
func NewValueCompareFn ¶ added in v0.16.0
func NewValueCompareFn(nullsMax bool) ValueCompareFn