Documentation
¶
Overview ¶
Package expr compiles a small row-predicate language into a function over decoded records.
The grammar:
expr = or
or = and { "or" and }
and = not { "and" not }
not = "not" not | primary
primary = "(" expr ")" | path op literal | path ["not"] "in" "(" literal {"," literal} ")"
| path "is" ["not"] "empty" | path ("contains" | "starts_with") string
op = "=" | "!=" | "<" | "<=" | ">" | ">="
path = name { "." name } name is an identifier or a `quoted` segment
literal = number | 'string' | "string" | true | false
A literal's type decides how a value is compared: a string literal compares the value's text, a number literal compares numerically (a text value is parsed), a boolean literal compares true or false. A missing, null or empty value matches no comparison; use "is empty" to test for it.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrSyntax = errors.New("syntax error")
ErrSyntax is wrapped by every parse error.
var ErrUncomparable = errors.New("value cannot be compared")
ErrUncomparable is returned in strict mode when a value cannot be compared with its literal's type.
Functions ¶
Types ¶
type Evaluator ¶
type Evaluator struct {
// contains filtered or unexported fields
}
Evaluator evaluates a Predicate on records. It owns scratch buffers, so one serves one worker.
func (*Evaluator) Columns ¶
Columns returns the columns the expression compares and, for each, whether any record had it. `is empty` tests are left out: asking about a column that may be absent is their point.
type Predicate ¶
type Predicate struct {
// contains filtered or unexported fields
}
Predicate is a compiled expression. Build one worker's evaluator with NewEvaluator; a Predicate itself holds only the parsed tree and is safe to share.
func Compile ¶
Compile parses src. In strict mode a value that cannot be compared with its literal (a non-numeric string against a number) is an error; otherwise it simply doesn't match and is counted.
func (*Predicate) NewEvaluator ¶
NewEvaluator builds an evaluator for one worker.