expr

package
v0.33.0 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2021 License: BSD-3-Clause Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrBadValue      = errors.New("bad value")
	ErrFieldRequired = errors.New("field parameter required")
)
View Source
var ErrBadCast = errors.New("bad cast")
View Source
var ErrIncompatibleTypes = coerce.ErrIncompatibleTypes
View Source
var ErrIndexOutOfBounds = errors.New("array index out of bounds")
View Source
var ErrNotContainer = errors.New("cannot apply in to a non-container")
View Source
var ErrSliceIndex = errors.New("slice index is not a number")
View Source
var ErrSliceIndexEmpty = errors.New("slice index is empty")

Functions

func CompileRegexp

func CompileRegexp(pattern string) (*regexp.Regexp, error)

func DotExprToField

func DotExprToField(e Evaluator) (field.Path, error)

func DotExprToString

func DotExprToString(e Evaluator) (string, error)

DotExprToString returns Zed for the Evaluator assuming it's a field expr.

func FlattenColumns

func FlattenColumns(cols []zed.Column) []zed.Column

FlattenColumns turns nested records into a series of columns of the form "outer.inner".

func LookupCompare

func LookupCompare(typ zed.Type) comparefn

func SortStable

func SortStable(records []zed.Value, compare CompareFn)

SortStable performs a stable sort on the provided records.

Types

type Add

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

func (*Add) Eval

func (a *Add) Eval(rec *zed.Value) (zed.Value, error)

type AggExpr

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

func NewAggExpr

func NewAggExpr(zctx *zed.Context, pattern agg.Pattern, src Generator) *AggExpr

func (*AggExpr) Eval

func (a *AggExpr) Eval(rec *zed.Value) (zed.Value, error)

type Aggregator

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

func NewAggregator

func NewAggregator(op string, expr Evaluator, where Filter) (*Aggregator, error)

func (*Aggregator) Apply

func (a *Aggregator) Apply(f agg.Function, rec *zed.Value) error

func (*Aggregator) NewFunction

func (a *Aggregator) NewFunction() agg.Function

type And

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

func NewLogicalAnd

func NewLogicalAnd(lhs, rhs Evaluator) *And

func (*And) Eval

func (a *And) Eval(rec *zed.Value) (zed.Value, error)

type ArrayExpr

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

func NewArrayExpr

func NewArrayExpr(zctx *zed.Context, exprs []Evaluator) *ArrayExpr

func (*ArrayExpr) Eval

func (a *ArrayExpr) Eval(rec *zed.Value) (zed.Value, error)

type Assignment

type Assignment struct {
	LHS field.Path
	RHS Evaluator
}

type Boolean

type Boolean func(zed.Value) bool

Predicate is a function that takes a Value and returns a boolean result based on the typed value.

func CompareBool

func CompareBool(op string, pattern bool) (Boolean, error)

CompareBool returns a Predicate that compares zed.Values to a boolean literal that must be a boolean or coercible to an integer. In the later case, the integer is converted to a boolean.

func CompareBstring

func CompareBstring(op string, pattern []byte) (Boolean, error)

func CompareBytes added in v0.32.0

func CompareBytes(op string, pattern []byte) (Boolean, error)

func CompareFloat64

func CompareFloat64(op string, pattern float64) (Boolean, error)

CompareFloat64 returns a Predicate that compares typed byte slices that must be coercible to an double with the value's double value using a comparison based on op. Int, count, port, and double types can all be converted to the integer value. XXX there are some overflow issues here.

func CompareIP

func CompareIP(op string, pattern net.IP) (Boolean, error)

Comparison returns a Predicate that compares typed byte slices that must be TypeAddr with the value's address using a comparison based on op. Only equality operands are allowed.

func CompareInt64

func CompareInt64(op string, pattern int64) (Boolean, error)

Return a predicate for comparing this value to one more typed byte slices by calling the predicate function with a Value. Operand is one of "=", "!=", "<", "<=", ">", ">=".

func CompareSubnet

func CompareSubnet(op string, pattern *net.IPNet) (Boolean, error)

Comparison returns a Predicate that compares typed byte slices that must be an addr or a subnet to the value's subnet value using a comparison based on op. Onluy equalty and inequality are permitted. If the typed byte slice is a subnet, then the comparison is based on strict equality. If the typed byte slice is an addr, then the comparison is performed by doing a CIDR match on the address with the subnet.

func CompareTime

func CompareTime(op string, pattern int64) (Boolean, error)

func CompareUnset

func CompareUnset(op string) (Boolean, error)

func Comparison

func Comparison(op string, primitive astzed.Primitive) (Boolean, error)

Comparison returns a Predicate for comparing this value to other values. The op argument is one of "=", "!=", "<", "<=", ">", ">=". See the comments of the various type implementations of this method as some types limit the operand to equality and the various types handle coercion in different ways.

func Contains

func Contains(compare Boolean) Boolean

Given a predicate for comparing individual elements, produce a new predicate that implements the "in" comparison. The new predicate looks at the type of the value being compared, if it is a set or array, the original predicate is applied to each element. The new precicate returns true iff the predicate matched an element from the collection.

func NewRegexpBoolean

func NewRegexpBoolean(re *regexp.Regexp) Boolean

NewRegexpBoolean returns a Booelan that compares values that must be a stringy the given regexp.

type BufferFilter

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

BufferFilter is a filter for byte slices containing ZNG values.

func NewAndBufferFilter

func NewAndBufferFilter(left, right *BufferFilter) *BufferFilter

func NewBufferFilterForString

func NewBufferFilterForString(pattern string) *BufferFilter

func NewBufferFilterForStringCase

func NewBufferFilterForStringCase(pattern string) *BufferFilter

func NewFieldNameFinder

func NewFieldNameFinder(pattern string) *BufferFilter

func NewOrBufferFilter

func NewOrBufferFilter(left, right *BufferFilter) *BufferFilter

func (*BufferFilter) Eval

func (b *BufferFilter) Eval(zctx *zed.Context, buf []byte) bool

Eval returns true if buf matches the receiver and false otherwise.

type Call

type Call struct {
	AddRoot bool
	// contains filtered or unexported fields
}

func NewCall

func NewCall(zctx *zed.Context, fn function.Interface, exprs []Evaluator) *Call

func (*Call) Eval

func (c *Call) Eval(rec *zed.Value) (zed.Value, error)

type Compare

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

func NewCompareRelative

func NewCompareRelative(lhs, rhs Evaluator, operator string) (*Compare, error)

func (*Compare) Eval

func (c *Compare) Eval(rec *zed.Value) (zed.Value, error)

type CompareFn

type CompareFn func(a *zed.Value, b *zed.Value) int

func NewCompareFn

func NewCompareFn(nullsMax bool, fields ...Evaluator) 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 Conditional

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

func NewConditional

func NewConditional(predicate, thenExpr, elseExpr Evaluator) *Conditional

func (*Conditional) Eval

func (c *Conditional) Eval(rec *zed.Value) (zed.Value, error)

type ConstShaper

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

func NewConstShaper

func NewConstShaper(zctx *zed.Context, expr Evaluator, shapeTo zed.Type, tf ShaperTransform) *ConstShaper

NewConstShaper returns a shaper that will shape the result of expr to the provided shapeTo type.

func (*ConstShaper) Apply

func (s *ConstShaper) Apply(in *zed.Value) (*zed.Value, error)

func (*ConstShaper) Eval

func (c *ConstShaper) Eval(in *zed.Value) (zed.Value, error)

type Cutter

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

func NewCutter

func NewCutter(zctx *zed.Context, fieldRefs field.List, fieldExprs []Evaluator) (*Cutter, error)

NewCutter returns a Cutter for fieldnames. If complement is true, the Cutter copies fields that are not in fieldnames. If complement is false, the Cutter copies any fields in fieldnames, where targets specifies the copied field names.

func (*Cutter) AllowPartialCuts

func (c *Cutter) AllowPartialCuts()

func (*Cutter) Apply

func (c *Cutter) Apply(in *zed.Value) (*zed.Value, error)

Apply returns a new record comprising fields copied from in according to the receiver's configuration. If the resulting record would be empty, Apply returns nil.

func (*Cutter) Eval

func (c *Cutter) Eval(rec *zed.Value) (zed.Value, error)

func (*Cutter) FoundCut

func (c *Cutter) FoundCut() bool

func (*Cutter) Quiet

func (c *Cutter) Quiet()

func (*Cutter) String

func (_ *Cutter) String() string

func (*Cutter) Warning

func (c *Cutter) Warning() string

type Divide

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

func (*Divide) Eval

func (d *Divide) Eval(rec *zed.Value) (zed.Value, error)

type DotExpr

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

func NewDotAccess

func NewDotAccess(record Evaluator, field string) *DotExpr

func (*DotExpr) Eval

func (f *DotExpr) Eval(rec *zed.Value) (zed.Value, error)

type Dropper

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

func NewDropper

func NewDropper(zctx *zed.Context, fields field.List) *Dropper

func (*Dropper) Apply

func (d *Dropper) Apply(in *zed.Value) (*zed.Value, error)

Apply implements proc.Function and returns a new record comprising fields that are not specified in the set of drop targets.

func (*Dropper) String

func (_ *Dropper) String() string

func (*Dropper) Warning

func (_ *Dropper) Warning() string

type Entry

type Entry struct {
	Key Evaluator
	Val Evaluator
}

type Equal

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

func NewCompareEquality

func NewCompareEquality(lhs, rhs Evaluator, operator string) (*Equal, error)

func (*Equal) Eval

func (e *Equal) Eval(rec *zed.Value) (zed.Value, error)

type Evaluator

type Evaluator interface {
	Eval(*zed.Value) (zed.Value, error)
}

func NewArithmetic

func NewArithmetic(lhs, rhs Evaluator, op string) (Evaluator, error)

NewArithmetic compiles an expression of the form "expr1 op expr2" for the arithmetic operators +, -, *, /

func NewCast

func NewCast(expr Evaluator, typ zed.Type) (Evaluator, error)

func NewDotExpr

func NewDotExpr(f field.Path) Evaluator

func NewIndexExpr

func NewIndexExpr(zctx *zed.Context, container, index Evaluator) (Evaluator, error)

func NewRootField

func NewRootField(name string) Evaluator

type Filter

type Filter func(*zed.Value) bool

func Apply

func Apply(e Evaluator, pred Boolean) Filter

func EvalAny

func EvalAny(eval Boolean, recursive bool) Filter

func LogicalAnd

func LogicalAnd(left, right Filter) Filter

func LogicalNot

func LogicalNot(expr Filter) Filter

func LogicalOr

func LogicalOr(left, right Filter) Filter

func SearchRecordOther

func SearchRecordOther(searchtext string, searchval astzed.Primitive) (Filter, error)

SearchRecordOther creates a filter that searches zng records for the given value, which must be of a type other than (b)string. The filter matches a record that contains this value either as the value of any field or inside any set or array. It also matches a record if the string representaton of the search value appears inside inside any string-valued field (or inside any element of a set or array of strings).

func SearchRecordString

func SearchRecordString(term string) Filter

SearchRecordString handles the special case of string searching -- it matches both field names and values.

type FilterEvaluator

type FilterEvaluator Filter

func (FilterEvaluator) Eval

func (f FilterEvaluator) Eval(rec *zed.Value) (zed.Value, error)

type FilterMethod

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

func NewFilterMethod

func NewFilterMethod(src Generator) *FilterMethod

func (*FilterMethod) Init

func (f *FilterMethod) Init(rec *zed.Value)

func (*FilterMethod) Next

func (f *FilterMethod) Next() (zed.Value, error)

func (*FilterMethod) Ref

func (f *FilterMethod) Ref() *zed.Value

func (*FilterMethod) Set

func (f *FilterMethod) Set(e Evaluator)

type Flattener

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

func NewFlattener

func NewFlattener(zctx *zed.Context) *Flattener

NewFlattener returns a flattener that transforms nested records to flattened records where the type context of the received records must match the zctx parameter provided here. Any new type descriptors that are created to flatten types also use zctx.

func (*Flattener) Flatten

func (f *Flattener) Flatten(r *zed.Value) (*zed.Value, error)

type Generator

type Generator interface {
	Init(*zed.Value)
	Next() (zed.Value, error)
}

type Has

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

https://github.com/brimdata/zed/blob/main/docs/language/functions.md#has

func NewHas

func NewHas(exprs []Evaluator) *Has

func (*Has) Eval

func (h *Has) Eval(rec *zed.Value) (zed.Value, error)

type In

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

func NewIn

func NewIn(elem, container Evaluator) *In

func (*In) Eval

func (i *In) Eval(rec *zed.Value) (zed.Value, error)

type Index

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

Index represents an index operator "container[index]" where container is either an array (with index type integer) or a record (with index type string).

func (*Index) Eval

func (i *Index) Eval(rec *zed.Value) (zed.Value, error)

type KeyCompareFn

type KeyCompareFn func(*zed.Value) int

func NewKeyCompareFn

func NewKeyCompareFn(key *zed.Value) (KeyCompareFn, error)

type Literal

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

func NewLiteral

func NewLiteral(zv zed.Value) *Literal

func (*Literal) Eval

func (l *Literal) Eval(*zed.Value) (zed.Value, error)

type MapExpr

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

func NewMapExpr

func NewMapExpr(zctx *zed.Context, entries []Entry) *MapExpr

func (*MapExpr) Eval

func (m *MapExpr) Eval(rec *zed.Value) (zed.Value, error)

type MapMethod

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

func NewMapMethod

func NewMapMethod(src Generator) *MapMethod

func (*MapMethod) Init

func (m *MapMethod) Init(rec *zed.Value)

func (*MapMethod) Next

func (m *MapMethod) Next() (zed.Value, error)

func (*MapMethod) Ref

func (m *MapMethod) Ref() *zed.Value

func (*MapMethod) Set

func (m *MapMethod) Set(e Evaluator)

type Missing

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

https://github.com/brimdata/zed/blob/main/docs/language/functions.md#missing

func NewMissing

func NewMissing(exprs []Evaluator) *Missing

func (*Missing) Eval

func (m *Missing) Eval(rec *zed.Value) (zed.Value, error)

type Multiply

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

func (*Multiply) Eval

func (m *Multiply) Eval(rec *zed.Value) (zed.Value, error)

type Not

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

func NewLogicalNot

func NewLogicalNot(e Evaluator) *Not

func (*Not) Eval

func (n *Not) Eval(rec *zed.Value) (zed.Value, error)

type Or

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

func NewLogicalOr

func NewLogicalOr(lhs, rhs Evaluator) *Or

func (*Or) Eval

func (o *Or) Eval(rec *zed.Value) (zed.Value, error)

type PrimitiveCaster

type PrimitiveCaster func(zv zed.Value) (zed.Value, error)

func LookupPrimitiveCaster

func LookupPrimitiveCaster(typ zed.Type) PrimitiveCaster

type RecordExpr

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

func NewRecordExpr

func NewRecordExpr(zctx *zed.Context, names []string, exprs []Evaluator) *RecordExpr

func (*RecordExpr) Eval

func (r *RecordExpr) Eval(rec *zed.Value) (zed.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) *zed.Value

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 RegexpMatch

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

func NewRegexpMatch

func NewRegexpMatch(re *regexp.Regexp, e Evaluator) *RegexpMatch

func (*RegexpMatch) Eval

func (r *RegexpMatch) Eval(rec *zed.Value) (zed.Value, error)

type RootRecord

type RootRecord struct{}

func (*RootRecord) Eval

func (r *RootRecord) Eval(rec *zed.Value) (zed.Value, error)

type Selector

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

func NewSelector

func NewSelector(selectors []Evaluator) *Selector

func (*Selector) Init

func (s *Selector) Init(rec *zed.Value)

func (*Selector) Next

func (s *Selector) Next() (zed.Value, error)

type SetExpr

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

func NewSetExpr

func NewSetExpr(zctx *zed.Context, exprs []Evaluator) *SetExpr

func (*SetExpr) Eval

func (s *SetExpr) Eval(rec *zed.Value) (zed.Value, error)

type Shaper

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

func NewShaper

func NewShaper(zctx *zed.Context, expr, typExpr Evaluator, tf ShaperTransform) *Shaper

NewShaper returns a shaper that will shape the result of expr to the type returned by typExpr.

func (*Shaper) Eval

func (s *Shaper) Eval(rec *zed.Value) (zed.Value, error)

type ShaperTransform

type ShaperTransform int

A ShaperTransform represents one of the different transforms that a shaper can apply. The transforms are represented as a bit flags that can be bitwise-ored together to create a single shaping operator that represents the composition of all operators. This composition is efficient as it is carried once per incoming type signature and then the resulting operator is run for every value of that type.

const (
	Cast ShaperTransform = 1 << iota
	Fill
	Crop
	Order
)

type Slice

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

func NewSlice

func NewSlice(elem, from, to Evaluator) *Slice

func (*Slice) Eval

func (s *Slice) Eval(rec *zed.Value) (zed.Value, error)

type Subtract

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

func (*Subtract) Eval

func (s *Subtract) Eval(rec *zed.Value) (zed.Value, error)

type TypeFunc

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

A TyepFunc returns a type value of the named type (where the name is a Zed typedef). It returns MISSING if the name doesn't exist.

func NewTypeFunc

func NewTypeFunc(zctx *zed.Context, name string) *TypeFunc

func (*TypeFunc) Eval

func (t *TypeFunc) Eval(rec *zed.Value) (zed.Value, error)

type Unflattener

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

func NewUnflattener

func NewUnflattener(zctx *zed.Context) *Unflattener

NewUnflattener returns a Unflattener that turns successive dotted field names into nested records. For example, unflattening {"a.a": 1, "a.b": 1} results in {a:{a:1,b:1}}. Note that while unflattening is applied recursively from the top-level and applies to arbitrary-depth dotted names, it is not applied to dotted names that start at lower levels (for example {a:{"a.a":1}} is unchanged).

func (*Unflattener) Apply

func (u *Unflattener) Apply(in *zed.Value) (*zed.Value, error)

Apply returns a new record comprising fields copied from in according to the receiver's configuration. If the resulting record would be empty, Apply returns nil.

func (*Unflattener) Eval

func (c *Unflattener) Eval(rec *zed.Value) (zed.Value, error)

type ValueCompareFn

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

func NewValueCompareFn

func NewValueCompareFn(nullsMax bool) ValueCompareFn

type Var

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

func NewVar

func NewVar(ref *zed.Value) *Var

func (*Var) Eval

func (v *Var) Eval(*zed.Value) (zed.Value, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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