-
Notifications
You must be signed in to change notification settings - Fork 67
/
filter.go
60 lines (52 loc) · 1.25 KB
/
filter.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package kernel
import (
"github.com/brimdata/zed/compiler/ast/dag"
"github.com/brimdata/zed/runtime/expr"
"github.com/brimdata/zed/zbuf"
)
type Filter struct {
pushdown dag.Expr
builder *Builder
}
var _ zbuf.Filter = (*Filter)(nil)
func (f *Filter) AsEvaluator() (expr.Evaluator, error) {
if f == nil {
return nil, nil
}
return f.builder.compileExpr(f.pushdown)
}
func (f *Filter) AsBufferFilter() (*expr.BufferFilter, error) {
if f == nil {
return nil, nil
}
return CompileBufferFilter(f.builder.octx.Zctx, f.pushdown)
}
type DeleteFilter struct {
*Filter
}
func (f *DeleteFilter) AsEvaluator() (expr.Evaluator, error) {
if f == nil {
return nil, nil
}
// For a DeleteFilter Evaluator the pushdown gets wrapped in a unary !
// expression so we get all values that don't match. We also add a missing
// call so if the expression results in an error("missing") the value is
// kept.
return f.builder.compileExpr(&dag.BinaryExpr{
Kind: "BinaryExpr",
Op: "or",
LHS: &dag.UnaryExpr{
Kind: "UnaryExpr",
Op: "!",
Operand: f.pushdown,
},
RHS: &dag.Call{
Kind: "Call",
Name: "missing",
Args: []dag.Expr{f.pushdown},
},
})
}
func (f *DeleteFilter) AsBufferFilter() (*expr.BufferFilter, error) {
return nil, nil
}