Skip to content

Commit 40986e8

Browse files
committed
Merge branch 'main' into ztest-remove-Bundle.TestName
2 parents f5a2627 + d1ccf5f commit 40986e8

File tree

13 files changed

+51
-64
lines changed

13 files changed

+51
-64
lines changed

cli/inputflags/flags.go

Lines changed: 19 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,81 +1,52 @@
11
package inputflags
22

33
import (
4-
"context"
54
"errors"
65
"flag"
7-
"fmt"
8-
"os"
96

10-
"github.com/brimdata/super"
117
"github.com/brimdata/super/cli/auto"
12-
"github.com/brimdata/super/pkg/storage"
13-
"github.com/brimdata/super/sio"
148
"github.com/brimdata/super/sio/anyio"
159
"github.com/brimdata/super/sio/bsupio"
1610
)
1711

1812
type Flags struct {
19-
anyio.ReaderOpts
20-
Dynamic bool
21-
ReadMax auto.Bytes
22-
ReadSize auto.Bytes
23-
Threads int
24-
}
25-
26-
func (f *Flags) Options() anyio.ReaderOpts {
27-
return f.ReaderOpts
13+
Dynamic bool
14+
ReaderOpts anyio.ReaderOpts
15+
bsupReadMax auto.Bytes
16+
bsupReadSize auto.Bytes
2817
}
2918

3019
func (f *Flags) SetFlags(fs *flag.FlagSet, validate bool) {
31-
fs.StringVar(&f.Format, "i", "auto", "format of input data [auto,arrows,bsup,csup,csv,json,line,parquet,sup,tsv,zeek,jsup]")
32-
f.CSV.Delim = ','
20+
f.bsupReadMax = auto.NewBytes(bsupio.MaxSize)
21+
fs.Var(&f.bsupReadMax, "bsup.readmax", "maximum Super Binary read buffer size in MiB, MB, etc.")
22+
f.bsupReadSize = auto.NewBytes(bsupio.ReadSize)
23+
fs.Var(&f.bsupReadSize, "bsup.readsize", "target Super Binary read buffer size in MiB, MB, etc.")
24+
opts := &f.ReaderOpts
25+
fs.IntVar(&opts.BSUP.Threads, "bsup.threads", 0, "number of Super Binary read threads (0=GOMAXPROCS)")
26+
fs.BoolVar(&opts.BSUP.Validate, "bsup.validate", validate, "validate format when reading Super Binary")
27+
opts.CSV.Delim = ','
3328
fs.Func("csv.delim", `CSV field delimiter (default ",")`, func(s string) error {
3429
if len(s) != 1 {
3530
return errors.New("CSV field delimiter must be exactly one character")
3631
}
37-
f.CSV.Delim = rune(s[0])
32+
opts.CSV.Delim = rune(s[0])
3833
return nil
3934

4035
})
41-
fs.IntVar(&f.BSUP.Threads, "bsup.threads", 0, "number of Super Binary read threads (0=GOMAXPROCS)")
42-
fs.BoolVar(&f.BSUP.Validate, "bsup.validate", validate, "validate format when reading Super Binary")
43-
f.ReadMax = auto.NewBytes(bsupio.MaxSize)
44-
fs.Var(&f.ReadMax, "bsup.readmax", "maximum Super Binary read buffer size in MiB, MB, etc.")
45-
f.ReadSize = auto.NewBytes(bsupio.ReadSize)
46-
fs.Var(&f.ReadSize, "bsup.readsize", "target Super Binary read buffer size in MiB, MB, etc.")
4736
fs.BoolVar(&f.Dynamic, "dynamic", false, "disable static type checking of inputs")
37+
fs.StringVar(&opts.Format, "i", "auto", "format of input data [auto,arrows,bsup,csup,csv,json,jsup,line,parquet,sup,tsv,zeek]")
4838
}
4939

5040
// Init is called after flags have been parsed.
5141
func (f *Flags) Init() error {
52-
f.BSUP.Max = int(f.ReadMax.Bytes)
53-
if f.BSUP.Max < 0 {
42+
bsup := &f.ReaderOpts.BSUP
43+
bsup.Max = int(f.bsupReadMax.Bytes)
44+
if bsup.Max < 0 {
5445
return errors.New("max read buffer size must be greater than zero")
5546
}
56-
f.BSUP.Size = int(f.ReadSize.Bytes)
57-
if f.BSUP.Size < 0 {
47+
bsup.Size = int(f.bsupReadSize.Bytes)
48+
if bsup.Size < 0 {
5849
return errors.New("target read buffer size must be greater than zero")
5950
}
6051
return nil
6152
}
62-
63-
func (f *Flags) Open(ctx context.Context, sctx *super.Context, engine storage.Engine, paths []string, stopOnErr bool) ([]sio.Reader, error) {
64-
var readers []sio.Reader
65-
for _, path := range paths {
66-
if path == "-" {
67-
path = "stdio:stdin"
68-
}
69-
file, err := anyio.Open(ctx, sctx, engine, path, f.ReaderOpts)
70-
if err != nil {
71-
err = fmt.Errorf("%s: %w", path, err)
72-
if stopOnErr {
73-
return nil, err
74-
}
75-
fmt.Fprintln(os.Stderr, err)
76-
continue
77-
}
78-
readers = append(readers, file)
79-
}
80-
return readers, nil
81-
}

cmd/super/db/load/command.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"github.com/brimdata/super/pkg/storage"
2323
"github.com/brimdata/super/pkg/units"
2424
"github.com/brimdata/super/sio"
25+
"github.com/brimdata/super/sio/anyio"
2526
"github.com/paulbellamy/ratecounter"
2627
"golang.org/x/term"
2728
)
@@ -79,7 +80,7 @@ func (c *Command) Run(args []string) error {
7980
paths := args
8081
c.engine = &engineWrap{Engine: storage.NewLocalEngine()}
8182
sctx := super.NewContext()
82-
readers, err := c.inputFlags.Open(ctx, sctx, c.engine, paths, false)
83+
readers, err := c.open(ctx, sctx, paths)
8384
if err != nil {
8485
return err
8586
}
@@ -116,6 +117,22 @@ func (c *Command) Run(args []string) error {
116117
return nil
117118
}
118119

120+
func (c *Command) open(ctx context.Context, sctx *super.Context, paths []string) ([]sio.Reader, error) {
121+
var readers []sio.Reader
122+
for _, path := range paths {
123+
if path == "-" {
124+
path = "stdio:stdin"
125+
}
126+
file, err := anyio.Open(ctx, sctx, c.engine, path, c.inputFlags.ReaderOpts)
127+
if err != nil {
128+
fmt.Fprintf(os.Stderr, "%s: %s\n", path, err)
129+
continue
130+
}
131+
readers = append(readers, file)
132+
}
133+
return readers, nil
134+
}
135+
119136
func (c *Command) Display(w io.Writer) bool {
120137
readBytes, completed := c.engine.status()
121138
fmt.Fprintf(w, "(%d/%d) ", completed, len(c.engine.readers))

cmd/super/root/command.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ func (c *Command) Run(args []string) error {
149149
env := exec.NewEnvironment(storage.NewLocalEngine(), nil)
150150
env.Dynamic = c.inputFlags.Dynamic
151151
env.IgnoreOpenErrors = !c.stopErr
152-
env.ReaderOpts = c.inputFlags.Options()
152+
env.ReaderOpts = c.inputFlags.ReaderOpts
153153
comp := compiler.NewCompilerWithEnv(env)
154154
query, err := runtime.CompileQuery(ctx, super.NewContext(), comp, ast, nil)
155155
if err != nil {

compiler/rungen/expr.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ func (b *Builder) compileBinary(e *dag.BinaryExpr) (expr.Evaluator, error) {
125125
case "<", "<=", ">", ">=":
126126
return expr.NewCompareRelative(b.sctx(), lhs, rhs, op)
127127
case "+", "-", "*", "/", "%":
128-
return expr.NewArithmetic(b.sctx(), lhs, rhs, op)
128+
return expr.NewArithmetic(b.sctx(), op, lhs, rhs)
129129
default:
130130
return nil, fmt.Errorf("invalid binary operator %s", op)
131131
}

compiler/rungen/vexpr.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,9 @@ func (b *Builder) compileVamBinary(e *dag.BinaryExpr) (vamexpr.Evaluator, error)
102102
case "in":
103103
return vamexpr.NewIn(b.sctx(), lhs, rhs), nil
104104
case "==", "!=", "<", "<=", ">", ">=":
105-
return vamexpr.NewCompare(b.sctx(), lhs, rhs, op), nil
105+
return vamexpr.NewCompare(b.sctx(), op, lhs, rhs), nil
106106
case "+", "-", "*", "/", "%":
107-
return vamexpr.NewArith(b.sctx(), lhs, rhs, op), nil
107+
return vamexpr.NewArith(b.sctx(), op, lhs, rhs), nil
108108
default:
109109
return nil, fmt.Errorf("invalid binary operator %s", op)
110110
}

runtime/sam/expr/eval.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ var DivideByZero = errors.New("divide by zero")
428428

429429
// NewArithmetic compiles an expression of the form "expr1 op expr2"
430430
// for the arithmetic operators +, -, *, /
431-
func NewArithmetic(sctx *super.Context, lhs, rhs Evaluator, op string) (Evaluator, error) {
431+
func NewArithmetic(sctx *super.Context, op string, lhs, rhs Evaluator) (Evaluator, error) {
432432
n := newNumeric(sctx, lhs, rhs)
433433
switch op {
434434
case "+":

runtime/vam/expr/arith.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ type Arith struct {
2020
rhs Evaluator
2121
}
2222

23-
func NewArith(sctx *super.Context, lhs, rhs Evaluator, op string) *Arith {
23+
func NewArith(sctx *super.Context, op string, lhs, rhs Evaluator) *Arith {
2424
return &Arith{sctx, vector.ArithOpFromString(op), lhs, rhs}
2525
}
2626

runtime/vam/expr/arith_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func TestArithOpsAndForms(t *testing.T) {
3535
for _, c := range cases {
3636
f := func(expected []int64, lhs, rhs vector.Any) {
3737
t.Helper()
38-
cmp := NewArith(super.NewContext(), &testEval{lhs}, &testEval{rhs}, c.op)
38+
cmp := NewArith(super.NewContext(), c.op, &testEval{lhs}, &testEval{rhs})
3939
assert.Equal(t, expected, cmp.Eval(nil).(*vector.Int).Values, "op: %s", c.op)
4040
}
4141

@@ -59,7 +59,7 @@ func TestArithOpsAndForms(t *testing.T) {
5959
f(c.expectedForConstLHS, Const, rhsView)
6060

6161
// Arithmetic on two vector.Consts returns another vector.Const.
62-
cmp := NewArith(super.NewContext(), &testEval{Const}, &testEval{Const}, c.op)
62+
cmp := NewArith(super.NewContext(), c.op, &testEval{Const}, &testEval{Const})
6363
val := cmp.Eval(nil).(*vector.Const)
6464
assert.Equal(t, uint32(3), val.Len(), "op: %s", c.op)
6565
expected := super.NewInt64(c.expectedForConstLHS[0])

runtime/vam/expr/compare.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ type Compare struct {
1919
rhs Evaluator
2020
}
2121

22-
func NewCompare(sctx *super.Context, lhs, rhs Evaluator, op string) *Compare {
22+
func NewCompare(sctx *super.Context, op string, lhs, rhs Evaluator) *Compare {
2323
return &Compare{sctx, vector.CompareOpFromString(op), lhs, rhs}
2424
}
2525

runtime/vam/expr/compare_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func TestCompareOpsAndForms(t *testing.T) {
4343
for _, c := range cases {
4444
f := func(expected string, lhs, rhs vector.Any) {
4545
t.Helper()
46-
cmp := NewCompare(super.NewContext(), &testEval{lhs}, &testEval{rhs}, c.op)
46+
cmp := NewCompare(super.NewContext(), c.op, &testEval{lhs}, &testEval{rhs})
4747
assert.Equal(t, expected, cmp.Eval(nil).(*vector.Bool).Bits.String(), "op: %s", c.op)
4848
}
4949

@@ -67,11 +67,10 @@ func TestCompareOpsAndForms(t *testing.T) {
6767
f(c.expectedForConstLHS, Const, rhsView)
6868

6969
// Comparing two vector.Consts yields another vector.Const.
70-
cmp := NewCompare(super.NewContext(), &testEval{Const}, &testEval{Const}, c.op)
70+
cmp := NewCompare(super.NewContext(), c.op, &testEval{Const}, &testEval{Const})
7171
val := cmp.Eval(nil).(*vector.Const)
7272
assert.Equal(t, uint32(3), val.Len(), "op: %s", c.op)
7373
expected := super.NewBool(c.expectedForConstLHS == "111")
7474
assert.Equal(t, expected, val.Value(), "op: %s", c.op)
7575
}
76-
7776
}

0 commit comments

Comments
 (0)