Skip to content

Commit 2e0781f

Browse files
committed
Merge branch 'main' into hugo-docs
2 parents 0588e2c + c388844 commit 2e0781f

File tree

19 files changed

+230
-60
lines changed

19 files changed

+230
-60
lines changed

lake/branch.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
"github.com/brimdata/super/pkg/plural"
1717
"github.com/brimdata/super/pkg/storage"
1818
"github.com/brimdata/super/runtime"
19+
"github.com/brimdata/super/zbuf"
1920
"github.com/brimdata/super/zio"
2021
"github.com/brimdata/super/zson"
2122
"github.com/segmentio/ksuid"
@@ -154,7 +155,7 @@ func (b *Branch) DeleteWhere(ctx context.Context, c runtime.Compiler, ast *parse
154155
if err != nil {
155156
return nil, err
156157
}
157-
err = zio.CopyWithContext(ctx, w, runtime.AsReader(query))
158+
err = zbuf.CopyPuller(w, query)
158159
if closeErr := w.Close(); err == nil {
159160
err = closeErr
160161
}

mdtest/mdtest.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,23 @@
4444
// hello
4545
// ...
4646
// ```
47+
//
48+
// # SPQ tests
49+
//
50+
// A fenced code block with mdtest-spq as the first word of its info string
51+
// contains an SPQ test. The content of the block must comprise three sections,
52+
// each preceeded by one or more "#"-prefixed lines. The first section contains
53+
// an SPQ program, the second contains input provided to the program when the
54+
// test runs, and the third contains the program's expected output.
55+
//
56+
// ```mdtest-spq
57+
// # spq
58+
// yield a
59+
// # input
60+
// {a:1}
61+
// # expected output
62+
// 1
63+
// ```
4764
package mdtest
4865

4966
import (
@@ -53,6 +70,7 @@ import (
5370
"io/fs"
5471
"os"
5572
"path/filepath"
73+
"regexp"
5674
"strconv"
5775
"strings"
5876
"testing"
@@ -131,6 +149,9 @@ func (f *File) Run(t *testing.T) {
131149
}
132150
}
133151

152+
// Matches one or more "#"-prefixed lines.
153+
var spqSeparatorRE = regexp.MustCompile(`(?m:^#.*\n)+`)
154+
134155
func parseMarkdown(source []byte) (map[string]string, []*Test, error) {
135156
var commandFCB *ast.FencedCodeBlock
136157
var inputs map[string]string
@@ -197,6 +218,23 @@ func parseMarkdown(source []byte) (map[string]string, []*Test, error) {
197218
GoExample: fcbLines(fcb, source),
198219
Line: fcbLineNumber(fcb, source),
199220
})
221+
case "mdtest-spq":
222+
lines := fcbLines(fcb, source)
223+
if !strings.HasPrefix(lines, "#") {
224+
return ast.WalkStop, fcbError(fcb, source, "mdtest-spq content must begin with '#'")
225+
}
226+
sections := spqSeparatorRE.Split(lines, -1)
227+
// Ignore sections[0].
228+
if n := len(sections); n != 4 {
229+
msg := fmt.Sprintf("mdtest-spq content has %d '#'-prefixed sections (expected 3)", n-1)
230+
return ast.WalkStop, fcbError(fcb, source, msg)
231+
}
232+
tests = append(tests, &Test{
233+
Expected: sections[3],
234+
Line: fcbLineNumber(fcb, source),
235+
Input: sections[2],
236+
SPQ: sections[1],
237+
})
200238
}
201239
return ast.WalkContinue, nil
202240
})

mdtest/mdtest_test.go

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,66 @@ block 2
162162
{Command: "block 1\n", Expected: "block 2\n...\n", Line: 2},
163163
},
164164
},
165+
{
166+
name: "mdtest-spq",
167+
markdown: `
168+
~~~mdtest-spq
169+
# Multiple '#' lines are allowed.
170+
#
171+
spq
172+
#
173+
input
174+
#
175+
expected
176+
~~~
177+
`,
178+
tests: []*Test{
179+
{Expected: "expected\n", Line: 2, Input: "input\n", SPQ: "spq\n"},
180+
},
181+
},
182+
{
183+
name: "mdtest-spq with leading garbage",
184+
markdown: `
185+
~~~mdtest-spq
186+
garbage
187+
#
188+
spq
189+
#
190+
input
191+
#
192+
expected
193+
~~~
194+
`,
195+
strerror: `line 2: mdtest-spq content must begin with '#'`,
196+
},
197+
{
198+
name: "mdtest-spq with too many sections",
199+
markdown: `
200+
~~~mdtest-spq
201+
#
202+
spq
203+
#
204+
input
205+
#
206+
expected
207+
#
208+
extra
209+
~~~
210+
`,
211+
strerror: `line 2: mdtest-spq content has 4 '#'-prefixed sections (expected 3)`,
212+
},
213+
{
214+
name: "mdtest-spq with too few sections",
215+
markdown: `
216+
~~~mdtest-spq
217+
#
218+
spq
219+
#
220+
input
221+
~~~
222+
`,
223+
strerror: `line 2: mdtest-spq content has 2 '#'-prefixed sections (expected 3)`,
224+
},
165225
}
166226
for _, tc := range tests {
167227
tc := tc

mdtest/test.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,26 @@ type Test struct {
2020
Head bool
2121
Line int
2222
GoExample string
23+
24+
// For SPQ tests
25+
Input string
26+
SPQ string
2327
}
2428

2529
// Run runs the test, returning nil on success.
2630
func (t *Test) Run() error {
2731
if t.GoExample != "" {
2832
return t.vetGoExample()
2933
}
30-
c := exec.Command("bash", "-e", "-o", "pipefail")
31-
c.Dir = t.Dir
32-
c.Stdin = strings.NewReader(t.Command)
34+
var c *exec.Cmd
35+
if t.SPQ != "" {
36+
c = exec.Command("super", "-z", "-c", t.SPQ, "-")
37+
c.Stdin = strings.NewReader(t.Input)
38+
} else {
39+
c = exec.Command("bash", "-e", "-o", "pipefail")
40+
c.Dir = t.Dir
41+
c.Stdin = strings.NewReader(t.Command)
42+
}
3343
outBytes, err := c.CombinedOutput()
3444
out := string(outBytes)
3545
if t.Fails {

runtime/compiler.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,6 @@ type DeleteQuery interface {
2929
DeletionSet() []ksuid.KSUID
3030
}
3131

32-
func AsReader(q Query) zio.Reader {
33-
return zbuf.PullerReader(q)
34-
}
35-
3632
func CompileQuery(ctx context.Context, zctx *super.Context, c Compiler, ast *parser.AST, readers []zio.Reader) (Query, error) {
3733
rctx := NewContext(ctx, zctx)
3834
q, err := c.NewQuery(rctx, ast, readers, 0)

runtime/sam/expr/agg/collect.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,9 @@ type Collect struct {
1616
var _ Function = (*Collect)(nil)
1717

1818
func (c *Collect) Consume(val super.Value) {
19-
if !val.IsNull() {
20-
c.update(val)
19+
if val.IsNull() {
20+
return
2121
}
22-
}
23-
24-
func (c *Collect) update(val super.Value) {
2522
c.values = append(c.values, val.Under().Copy())
2623
c.size += len(val.Bytes())
2724
for c.size > MaxValueSize {
@@ -75,7 +72,7 @@ func (c *Collect) ConsumeAsPartial(val super.Value) {
7572
}
7673
typ := arrayType.Type
7774
for it := val.Iter(); !it.Done(); {
78-
c.update(super.NewValue(typ, it.Next()))
75+
c.Consume(super.NewValue(typ, it.Next()))
7976
}
8077
}
8178

runtime/sam/expr/agg/ztests/collect-union.yaml

Lines changed: 0 additions & 9 deletions
This file was deleted.

runtime/sam/expr/dot.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,11 @@ func (d *DotExpr) Eval(ectx Context, this super.Value) super.Value {
4747
if !ok {
4848
return d.zctx.Missing()
4949
}
50-
return super.NewValue(typ.Fields[i].Type, getNthFromContainer(val.Bytes(), i))
50+
bytes, ok := getNthFromContainer(val.Bytes(), i)
51+
if !ok {
52+
return d.zctx.Missing()
53+
}
54+
return super.NewValue(typ.Fields[i].Type, bytes)
5155
case *super.TypeMap:
5256
return indexMap(d.zctx, ectx, typ, val.Bytes(), super.NewString(d.field))
5357
case *super.TypeOfType:

runtime/sam/expr/eval.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -601,24 +601,24 @@ func (u *UnaryMinus) Eval(ectx Context, this super.Value) super.Value {
601601
return u.zctx.WrapError("type incompatible with unary '-' operator", val)
602602
}
603603

604-
func getNthFromContainer(container zcode.Bytes, idx int) zcode.Bytes {
604+
func getNthFromContainer(container zcode.Bytes, idx int) (zcode.Bytes, bool) {
605605
if idx < 0 {
606606
var length int
607607
for it := container.Iter(); !it.Done(); it.Next() {
608608
length++
609609
}
610610
idx = length + idx
611611
if idx < 0 || idx >= length {
612-
return nil
612+
return nil, false
613613
}
614614
}
615615
for i, it := 0, container.Iter(); !it.Done(); i++ {
616616
zv := it.Next()
617617
if i == idx {
618-
return zv
618+
return zv, true
619619
}
620620
}
621-
return nil
621+
return nil, false
622622
}
623623

624624
func lookupKey(mapBytes, target zcode.Bytes) (zcode.Bytes, bool) {
@@ -673,11 +673,11 @@ func indexVector(zctx *super.Context, ectx Context, inner super.Type, vector zco
673673
} else {
674674
idx = int(index.Uint())
675675
}
676-
zv := getNthFromContainer(vector, idx)
677-
if zv == nil {
676+
bytes, ok := getNthFromContainer(vector, idx)
677+
if !ok {
678678
return zctx.Missing()
679679
}
680-
return deunion(ectx, inner, zv)
680+
return deunion(ectx, inner, bytes)
681681
}
682682

683683
func indexRecord(zctx *super.Context, ectx Context, typ *super.TypeRecord, record zcode.Bytes, index super.Value) super.Value {

runtime/sam/expr/shaper.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ func (s *step) buildRecord(zctx *super.Context, ectx Context, in zcode.Bytes, b
527527
// reordering) would be make direct use of a
528528
// zcode.Iter along with keeping track of our
529529
// position.
530-
bytes := getNthFromContainer(in, child.fromIndex)
530+
bytes, _ := getNthFromContainer(in, child.fromIndex)
531531
typ := child.build(zctx, ectx, bytes, b)
532532
if super.TypeUnder(typ) == super.TypeUnder(child.toType) {
533533
// Prefer child.toType in case it's a named type.

0 commit comments

Comments
 (0)