-
Notifications
You must be signed in to change notification settings - Fork 67
/
file.go
92 lines (83 loc) · 2.86 KB
/
file.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package compiler
import (
"errors"
"github.com/brimdata/zed/compiler/ast"
"github.com/brimdata/zed/compiler/data"
"github.com/brimdata/zed/lakeparse"
"github.com/brimdata/zed/pkg/storage"
"github.com/brimdata/zed/runtime"
"github.com/brimdata/zed/runtime/op"
"github.com/brimdata/zed/zio"
)
type fsCompiler struct {
anyCompiler
src *data.Source
}
func NewFileSystemCompiler(engine storage.Engine) runtime.Compiler {
return &fsCompiler{src: data.NewSource(engine, nil)}
}
func (f *fsCompiler) NewQuery(pctx *op.Context, o ast.Op, readers []zio.Reader) (*runtime.Query, error) {
job, err := NewJob(pctx, o, f.src, nil)
if err != nil {
return nil, err
}
if isJoin(o) {
if len(readers) != 2 {
return nil, errors.New("join operaetor requires two inputs")
}
if len(job.readers) != 2 {
return nil, errors.New("internal error: join expected by semantic analyzer")
}
job.readers[0].Readers = readers[0:1]
job.readers[1].Readers = readers[1:2]
} else if len(readers) == 0 {
// If there's no reader but the DAG wants an input, then
// flag an error.
if len(job.readers) != 0 {
return nil, errors.New("no input specified: use a command-line file or a Zed source operator")
}
} else {
// If there's a reader but the DAG doesn't want an input,
// then flag an error.
// TBD: we could have such a configuration is a composite
// from command includes a "pass" operator, but we can add this later.
// See issue #2640.
if len(job.readers) == 0 {
return nil, errors.New("redundant inputs specified: use either command-line files or a Zed source operator")
}
if len(job.readers) != 1 {
return nil, errors.New("Zed query requires a single input path")
}
job.readers[0].Readers = readers
}
return optimizeAndBuild(job)
}
func (*fsCompiler) NewLakeQuery(pctx *op.Context, program ast.Op, parallelism int, head *lakeparse.Commitish) (*runtime.Query, error) {
panic("NewLakeQuery called on compiler.fsCompiler")
}
func (*fsCompiler) NewLakeDeleteQuery(pctx *op.Context, program ast.Op, head *lakeparse.Commitish) (*runtime.DeleteQuery, error) {
panic("NewLakeDeleteQuery called on compiler.fsCompiler")
}
func isJoin(o ast.Op) bool {
seq, ok := o.(*ast.Sequential)
if !ok || len(seq.Ops) == 0 {
return false
}
_, ok = seq.Ops[0].(*ast.Join)
return ok
}
func optimizeAndBuild(job *Job) (*runtime.Query, error) {
// Call optimize to possible push down a filter predicate into the
// kernel.Reader so that the zng scanner can do boyer-moore.
if err := job.Optimize(); err != nil {
return nil, err
}
// For an internal reader (like a shaper on intake), we don't do
// any parallelization right now though this could be potentially
// beneficial depending on where the bottleneck is for a given shaper.
// See issue #2641.
if err := job.Build(); err != nil {
return nil, err
}
return runtime.NewQuery(job.pctx, job.Puller(), job.builder.Meter()), nil
}