expr

package
v1.15.0 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2024 License: BSD-3-Clause Imports: 27 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DivideByZero = errors.New("divide by zero")
View Source
var ErrSliceIndex = errors.New("slice index is not a number")
View Source
var ErrSliceIndexEmpty = errors.New("slice index is empty")

Functions

func CheckPutFields

func CheckPutFields(fields field.List) error

func CheckRenameField

func CheckRenameField(src, dst field.Path) error

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 EvalBool

func EvalBool(zctx *zed.Context, ectx Context, this zed.Value, e Evaluator) (zed.Value, bool)

EvalBool evaluates e with this and if the result is a Zed bool, returns the result and true. Otherwise, a Zed error (inclusive of missing) and false are returned.

func FlattenFields

func FlattenFields(fields []zed.Field) []zed.Field

FlattenFields turns nested records into a series of fields of the form "outer.inner".

func LookupCompare

func LookupCompare(typ zed.Type) comparefn

func NewContext

func NewContext() *allocator

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(ectx Context, this zed.Value) zed.Value

type Aggregator

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

func NewAggregator

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

func (*Aggregator) Apply

func (a *Aggregator) Apply(zctx *zed.Context, ectx Context, f agg.Function, this zed.Value)

func (*Aggregator) NewFunction

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

type And

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

func NewLogicalAnd

func NewLogicalAnd(zctx *zed.Context, lhs, rhs Evaluator) *And

func (*And) Eval

func (a *And) Eval(ectx Context, this zed.Value) zed.Value

type ArrayExpr

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

func NewArrayExpr

func NewArrayExpr(zctx *zed.Context, elems []VectorElem) *ArrayExpr

func (*ArrayExpr) Eval

func (a *ArrayExpr) Eval(ectx Context, this zed.Value) zed.Value

type Assignment

type Assignment struct {
	LHS *Lval
	RHS Evaluator
}

type Boolean

type Boolean func(zed.Value) bool

Boolean 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 CompareBytes

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 netip.Addr) (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 CompareNull

func CompareNull(op string) (Boolean, error)

func CompareString

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

func Comparison

func Comparison(op string, val zed.Value) (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.

func NewRegexpBoolean

func NewRegexpBoolean(re *regexp.Regexp) Boolean

NewRegexpBoolean returns a Boolean 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 NewBufferFilterForFieldName

func NewBufferFilterForFieldName(pattern string) *BufferFilter

func NewBufferFilterForString

func NewBufferFilterForString(pattern string) *BufferFilter

func NewBufferFilterForStringCase

func NewBufferFilterForStringCase(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 {
	// contains filtered or unexported fields
}

func NewCall

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

func (*Call) Eval

func (c *Call) Eval(ectx Context, this zed.Value) zed.Value

type Comparator

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

func NewComparator

func NewComparator(nullsMax, reverse bool, exprs ...Evaluator) *Comparator

NewComparator returns a zed.Value comparator for exprs according to nullsMax and reverse. To compare values a and b, it iterates over the elements e of exprs, stopping when e(a)!=e(b). nullsMax determines whether a null value compares larger (if true) or smaller (if false) than a non-null value. reverse reverses the sense of comparisons.

func (*Comparator) Compare

func (c *Comparator) Compare(a, b zed.Value) int

Compare returns an interger comparing two values according to the receiver's configuration. The result will be 0 if a==b, -1 if a < b, and +1 if a > b.

func (*Comparator) SortStable

func (c *Comparator) SortStable(vals []zed.Value)

SortStable sorts vals according to c, with equal values in their original order. SortStable allocates more memory than [SortStableReader].

func (*Comparator) SortStableReader

func (c *Comparator) SortStableReader(vals []zed.Value) zio.Reader

SortStableReader returns a reader for vals sorted according to c, with equal values in their original order.

func (*Comparator) WithMissingAsNull

func (c *Comparator) WithMissingAsNull() *Comparator

WithMissingAsNull returns the receiver after modifying it to treat missing values as the null value in comparisons.

type Compare

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

func NewCompareRelative

func NewCompareRelative(zctx *zed.Context, lhs, rhs Evaluator, operator string) (*Compare, error)

func (*Compare) Eval

func (c *Compare) Eval(ectx Context, this zed.Value) zed.Value

type CompareFn

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

func NewCompareFn

func NewCompareFn(nullsMax bool, exprs ...Evaluator) CompareFn

NewCompareFn creates a function that compares two values a and b according to nullsMax and exprs. To compare a and b, it iterates over the elements e of exprs, stopping when e(a)!=e(b). The handling of missing and null (collectively refered to as "null") values is governed by nullsMax. If nullsMax is true, a null value is considered larger than any non-null value, and vice versa.

func NewValueCompareFn

func NewValueCompareFn(o order.Which, nullsMax bool) CompareFn

type Conditional

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

func NewConditional

func NewConditional(zctx *zed.Context, predicate, thenExpr, elseExpr Evaluator) *Conditional

func (*Conditional) Eval

func (c *Conditional) Eval(ectx Context, this zed.Value) zed.Value

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) Eval

func (c *ConstShaper) Eval(ectx Context, this zed.Value) zed.Value

type Context

type Context interface {
	// Vars() accesses the variables reachable in the current scope.
	Vars() []zed.Value
	zed.Allocator
}

Context is an interface to a scope and value allocator for expressions. This allows external packages to implement efficient temporary buffering of Zed values both for let-style temporary variables accessible via the scope and for allocating results.

type Cutter

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

func NewCutter

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

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) Eval

func (c *Cutter) Eval(ectx Context, in zed.Value) zed.Value

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 zed.Missing.

func (*Cutter) FoundCut

func (c *Cutter) FoundCut() bool

func (*Cutter) Quiet

func (c *Cutter) Quiet()

type Divide

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

func (*Divide) Eval

func (d *Divide) Eval(ectx Context, this zed.Value) zed.Value

type DotExpr

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

func NewDotExpr

func NewDotExpr(zctx *zed.Context, record Evaluator, field string) *DotExpr

func (*DotExpr) Eval

func (d *DotExpr) Eval(ectx Context, this zed.Value) zed.Value

type Dropper

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

func NewDropper

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

func (*Dropper) Eval

func (d *Dropper) Eval(ectx Context, in zed.Value) zed.Value

type Entry

type Entry struct {
	Key Evaluator
	Val Evaluator
}

type Equal

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

func NewCompareEquality

func NewCompareEquality(zctx *zed.Context, lhs, rhs Evaluator, operator string) (*Equal, error)

func (*Equal) Eval

func (e *Equal) Eval(ectx Context, this zed.Value) zed.Value

type Evaluator

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

func LookupPrimitiveCaster

func LookupPrimitiveCaster(zctx *zed.Context, typ zed.Type) Evaluator

func NewAggregatorExpr

func NewAggregatorExpr(zctx *zed.Context, agg *Aggregator) Evaluator

NewAggregatorExpr returns an Evaluator from agg. The returned Evaluator retains the same functionality of the aggregation only it returns it's current state every time a new value is consumed.

func NewArithmetic

func NewArithmetic(zctx *zed.Context, lhs, rhs Evaluator, op string) (Evaluator, error)

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

func NewDottedExpr

func NewDottedExpr(zctx *zed.Context, f field.Path) Evaluator

func NewFilter

func NewFilter(expr Evaluator, pred Boolean) Evaluator

func NewFilterApplier

func NewFilterApplier(zctx *zed.Context, e Evaluator) Evaluator

func NewIndexExpr

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

func NewMapCall

func NewMapCall(zctx *zed.Context, e, inner Evaluator) Evaluator

func NewRecordExpr

func NewRecordExpr(zctx *zed.Context, elems []RecordElem) (Evaluator, error)

func NewSearch

func NewSearch(searchtext string, searchval zed.Value, expr Evaluator) (Evaluator, error)

NewSearch creates a filter that searches Zed records for the given value, which must be of a type other than 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 NewSearchString

func NewSearchString(term string, expr Evaluator) Evaluator

NewSearchString is like NewSeach but handles the special case of matching field names in addition to string values.

func NewShaper

func NewShaper(zctx *zed.Context, expr, typeExpr Evaluator, tf ShaperTransform) (Evaluator, error)

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

func SearchByPredicate

func SearchByPredicate(pred Boolean, e Evaluator) Evaluator

type ExprLvalElem

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

func NewExprLvalElem

func NewExprLvalElem(zctx *zed.Context, e Evaluator) *ExprLvalElem

func (*ExprLvalElem) Eval

func (l *ExprLvalElem) Eval(ectx Context, this zed.Value) (string, error)

type FieldNameFinder

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

func NewFieldNameFinder

func NewFieldNameFinder(pattern string) *FieldNameFinder

func (*FieldNameFinder) Find

func (f *FieldNameFinder) Find(zctx *zed.Context, buf []byte) bool

Find returns true if buf, which holds a sequence of ZNG value messages, might contain a record with a field whose fully-qualified name (e.g., a.b.c) matches the pattern. Find also returns true if it encounters an error.

type FieldNameIter

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

func (*FieldNameIter) Done

func (f *FieldNameIter) Done() bool

func (*FieldNameIter) Init

func (f *FieldNameIter) Init(t *zed.TypeRecord)

func (*FieldNameIter) Next

func (f *FieldNameIter) Next() []byte

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 Function

type Function interface {
	Call(zed.Allocator, []zed.Value) zed.Value
}

type In

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

func NewIn

func NewIn(zctx *zed.Context, elem, container Evaluator) *In

func (*In) Eval

func (i *In) Eval(ectx Context, this zed.Value) zed.Value

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(ectx Context, this zed.Value) zed.Value

type Literal

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

func NewLiteral

func NewLiteral(val zed.Value) *Literal

func (Literal) Eval

func (l Literal) Eval(Context, zed.Value) zed.Value

type Lval

type Lval struct {
	Elems []LvalElem
	// contains filtered or unexported fields
}

func NewLval

func NewLval(evals []LvalElem) *Lval

func (*Lval) Eval

func (l *Lval) Eval(ectx Context, this zed.Value) (field.Path, error)

Eval returns the path of the lval.

func (*Lval) Path

func (l *Lval) Path() (field.Path, bool)

Path returns the receiver's path. Path returns false when the receiver contains a dynamic element.

type LvalElem

type LvalElem interface {
	Eval(ectx Context, this zed.Value) (string, 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(ectx Context, this zed.Value) zed.Value

type Modulo

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

func (*Modulo) Eval

func (m *Modulo) Eval(ectx Context, this zed.Value) zed.Value

type Multiply

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

func (*Multiply) Eval

func (m *Multiply) Eval(ectx Context, this zed.Value) zed.Value

type Not

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

func NewLogicalNot

func NewLogicalNot(zctx *zed.Context, e Evaluator) *Not

func (*Not) Eval

func (n *Not) Eval(ectx Context, this zed.Value) zed.Value

type Or

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

func NewLogicalOr

func NewLogicalOr(zctx *zed.Context, lhs, rhs Evaluator) *Or

func (*Or) Eval

func (o *Or) Eval(ectx Context, this zed.Value) zed.Value

type Putter

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

Putter is an Evaluator that modifies the record stream with computed values. Each new value is called a clause and consists of a field name and an expression. Each put clause either replaces an existing value in the field specified or appends a value as a new field. Appended values appear as new fields in the order that the clause appears in the put expression.

func NewPutter

func NewPutter(zctx *zed.Context, clauses []Assignment) *Putter

func (*Putter) Eval

func (p *Putter) Eval(ectx Context, this zed.Value) zed.Value

type RecordElem

type RecordElem struct {
	Name   string
	Field  Evaluator
	Spread Evaluator
}

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(ectx Context, this zed.Value) zed.Value

type Renamer

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

Renamer renames one or more fields in a record. A field can only be renamed within its own record. For example id.orig_h can be renamed to id.src, but it cannot be renamed to src. Renames are applied left to right; each rename observes the effect of all.

func NewRenamer

func NewRenamer(zctx *zed.Context, srcs, dsts []*Lval) *Renamer

func (*Renamer) Eval

func (r *Renamer) Eval(ectx Context, this zed.Value) zed.Value

type SetExpr

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

func NewSetExpr

func NewSetExpr(zctx *zed.Context, elems []VectorElem) *SetExpr

func (*SetExpr) Eval

func (a *SetExpr) Eval(ectx Context, this zed.Value) zed.Value

type Shaper

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

func (*Shaper) Eval

func (s *Shaper) Eval(ectx Context, this zed.Value) zed.Value

type ShaperTransform

type ShaperTransform int

A ShaperTransform represents one of the different transforms that a shaper can apply. The transforms are represented as 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 created once per incoming type and then the resulting operator is run for every value of that type.

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

func NewShaperTransform

func NewShaperTransform(s string) ShaperTransform

type Slice

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

func NewSlice

func NewSlice(zctx *zed.Context, elem, from, to Evaluator) *Slice

func (*Slice) Eval

func (s *Slice) Eval(ectx Context, this zed.Value) zed.Value

type StaticLvalElem

type StaticLvalElem struct {
	Name string
}

func (*StaticLvalElem) Eval

func (l *StaticLvalElem) Eval(_ Context, _ zed.Value) (string, error)

type Subtract

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

func (*Subtract) Eval

func (s *Subtract) Eval(ectx Context, this zed.Value) zed.Value

type This

type This struct{}

func (*This) Eval

func (*This) Eval(_ Context, this zed.Value) zed.Value

type UDF

type UDF struct {
	Body Evaluator
}

func (*UDF) Call

func (u *UDF) Call(ectx zed.Allocator, args []zed.Value) zed.Value

type UnaryMinus

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

func NewUnaryMinus

func NewUnaryMinus(zctx *zed.Context, e Evaluator) *UnaryMinus

func (*UnaryMinus) Eval

func (u *UnaryMinus) Eval(ectx Context, this zed.Value) zed.Value

type Var

type Var int

func NewVar

func NewVar(slot int) *Var

func (Var) Eval

func (v Var) Eval(ectx Context, _ zed.Value) zed.Value

type VectorElem

type VectorElem struct {
	Value  Evaluator
	Spread Evaluator
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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