Skip to content

Commit 5f67a82

Browse files
committed
Convert several operator examples to mdtest-spq
1 parent 28ffd95 commit 5f67a82

File tree

8 files changed

+137
-101
lines changed

8 files changed

+137
-101
lines changed

docs/language/operators/assert.md

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,20 @@ structured error if it does not.
1515

1616
### Examples
1717

18-
```mdtest-command
19-
echo {a:1} | super -z -c 'assert a > 0' -
20-
```
21-
22-
```mdtest-output
18+
```mdtest-spq
19+
# spq
20+
assert a > 0
21+
# input
22+
{a:1}
23+
# expected output
2324
{a:1}
2425
```
2526

26-
```mdtest-command
27-
echo {a:-1} | super -z -c 'assert a > 0' -
28-
```
29-
30-
```mdtest-output
27+
```mdtest-spq {data-layout="stacked"}
28+
# spq
29+
assert a > 0
30+
# input
31+
{a:-1}
32+
# expected output
3133
error({message:"assertion failed",expr:"a > 0",on:{a:-1}})
3234
```

docs/language/operators/combine.md

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
### Synopsis
66

77
```
8-
( => ... => ...) |> ...
8+
( => ... => ...) | ...
99
```
1010
### Description
1111

@@ -20,11 +20,16 @@ and its semantics of undefined merge order.
2020
### Examples
2121

2222
_Copy input to two pipeline branches and combine with the implied operator_
23-
```mdtest-command
24-
echo '1 2' | super -z -c 'fork (=>pass =>pass) |> sort this' -
25-
```
26-
27-
```mdtest-output
23+
```mdtest-spq
24+
# spq
25+
fork (
26+
=>pass
27+
=>pass
28+
)
29+
| sort this
30+
# input
31+
1 2
32+
# expected output
2833
1
2934
1
3035
2

docs/language/operators/cut.md

Lines changed: 37 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Each right-hand side `<expr>` can be any Zed expression and is optional.
2323
When the right-hand side expressions are omitted,
2424
the _cut_ operation resembles the Unix shell command, e.g.,
2525
```
26-
... |> cut a,c |> ...
26+
... | cut a,c | ...
2727
```
2828
If an expression results in `error("quiet")`, the corresponding field is omitted
2929
from the output. This allows you to wrap expressions in a `quiet()` function
@@ -42,38 +42,47 @@ yield {<field>:<expr> [, <field>:<expr>...]}
4242
### Examples
4343

4444
_A simple Unix-like cut_
45-
```mdtest-command
46-
echo '{a:1,b:2,c:3}' | super -z -c 'cut a,c' -
47-
```
48-
49-
```mdtest-output
45+
```mdtest-spq
46+
# spq
47+
cut a,c
48+
# input
49+
{a:1,b:2,c:3}
50+
# expected output
5051
{a:1,c:3}
5152
```
52-
_Missing fields show up as missing errors_
53-
```mdtest-command
54-
echo '{a:1,b:2,c:3}' | super -z -c 'cut a,d' -
55-
```
5653

57-
```mdtest-output
54+
_Missing fields show up as missing errors_
55+
```mdtest-spq
56+
# spq
57+
cut a,d
58+
# input
59+
{a:1,b:2,c:3}
60+
# expected output
5861
{a:1,d:error("missing")}
5962
```
60-
_The missing fields can be ignored with quiet_
61-
```mdtest-command
62-
echo '{a:1,b:2,c:3}' | super -z -c 'cut a:=quiet(a),d:=quiet(d)' -
63-
```
6463

65-
```mdtest-output
64+
_The missing fields can be ignored with quiet_
65+
```mdtest-spq
66+
# spq
67+
cut a:=quiet(a),d:=quiet(d)
68+
# input
69+
{a:1,b:2,c:3}
70+
# expected output
6671
{a:1}
6772
```
68-
_Non-record values generate missing errors for fields not present in a non-record `this`_
69-
```mdtest-command
70-
echo '1 {a:1,b:2,c:3}' | super -z -c 'cut a,b' -
71-
```
7273

73-
```mdtest-output
74+
_Non-record values generate missing errors for fields not present in a non-record `this`_
75+
```mdtest-spq {data-layout="stacked"}
76+
# spq
77+
cut a,b
78+
# input
79+
1
80+
{a:1,b:2,c:3}
81+
# expected output
7482
{a:error("missing"),b:error("missing")}
7583
{a:1,b:2}
7684
```
85+
7786
_Invoke a function while cutting to set a default value for a field_
7887

7988
{{% tip "Tip" %}}
@@ -84,11 +93,13 @@ the output will be exported in formats such as `csv` or `parquet` (see also:
8493

8594
{{% /tip %}}
8695

87-
```mdtest-command
88-
echo '{a:1,b:null}{a:1,b:2}' | super -z -c 'cut a,b:=coalesce(b, 0)' -
89-
```
90-
91-
```mdtest-output
96+
```mdtest-spq
97+
# spq
98+
cut a,b:=coalesce(b, 0)
99+
# input
100+
{a:1,b:null}
101+
{a:1,b:2}
102+
# expected output
92103
{a:1,b:0}
93104
{a:1,b:2}
94105
```

docs/language/operators/drop.md

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,23 @@ non-record values are copied unmodified.
1717
### Examples
1818

1919
_Drop of a field_
20-
```mdtest-command
21-
echo '{a:1,b:2,c:3}' | super -z -c 'drop b' -
22-
```
23-
24-
```mdtest-output
20+
```mdtest-spq
21+
# spq
22+
drop b
23+
# input
24+
{a:1,b:2,c:3}
25+
# expected output
2526
{a:1,c:3}
2627
```
27-
_Non-record values are copied to output_
28-
```mdtest-command
29-
echo '1 {a:1,b:2,c:3}' | super -z -c 'drop a,b' -
30-
```
3128

32-
```mdtest-output
29+
_Non-record values are copied to output_
30+
```mdtest-spq
31+
# spq
32+
drop a,b
33+
# input
34+
1
35+
{a:1,b:2,c:3}
36+
# expected output
3337
1
3438
{c:3}
3539
```

docs/language/operators/file.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,10 @@
44

55
### Synopsis
66

7-
`file` is a shorthand notation for `from`. See the [from operator](from.md) documentation for details.
7+
`file` is a shorthand notation for `from`. See the [`from` operator](from.md) documentation for details.
88

99
{{% tip "Note" %}}
1010

11-
The `file` shorthand is exclusively for working with inputs to
12-
[`super`](../../commands/super.md) and is not available for use with [SuperDB data lakes](../../commands/super-db.md).
11+
The `file` shorthand is not available for use with [SuperDB data lakes](../../commands/super-db.md).
1312

1413
{{% /tip %}}

docs/language/operators/fork.md

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,17 @@ merged with an automatically inserted [combine operator](combine.md).
2323
### Examples
2424

2525
_Copy input to two pipeline branches and merge_
26-
```mdtest-command
27-
echo '1 2' | super -z -c 'fork (=>pass =>pass) |> sort this' -
28-
```
29-
30-
```mdtest-output
26+
```mdtest-spq
27+
# spq
28+
fork (
29+
=>pass
30+
=>pass
31+
)
32+
| sort this
33+
# input
34+
1
35+
2
36+
# expected output
3137
1
3238
1
3339
2

docs/language/operators/from.md

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -49,28 +49,28 @@ In the fifth form, multiple sources are accessed in parallel and may be
4949

5050
A pipeline can be split with the [`fork` operator](fork.md) as in
5151
```
52-
from PoolOne |> fork (
53-
=> op1 |> op2 | ...
54-
=> op1 |> op2 | ...
55-
) |> merge ts | ...
52+
from PoolOne | fork (
53+
=> op1 | op2 | ...
54+
=> op1 | op2 | ...
55+
) | merge ts | ...
5656
```
5757

5858
Or multiple pools can be accessed and, for example, joined:
5959
```
6060
from (
61-
pool PoolOne => op1 |> op2 | ...
62-
pool PoolTwo => op1 |> op2 | ...
63-
) |> join on key=key | ...
61+
pool PoolOne => op1 | op2 | ...
62+
pool PoolTwo => op1 | op2 | ...
63+
) | join on key=key | ...
6464
```
6565

6666
Similarly, data can be routed to different pipeline branches with replication
6767
using the [`switch` operator](switch.md):
6868
```
69-
from ... |> switch color (
70-
case "red" => op1 |> op2 | ...
71-
case "blue" => op1 |> op2 | ...
72-
default => op1 |> op2 | ...
73-
) |> ...
69+
from ... | switch color (
70+
case "red" => op1 | op2 | ...
71+
case "blue" => op1 | op2 | ...
72+
default => op1 | op2 | ...
73+
) | ...
7474
```
7575

7676
### Input Data
@@ -91,8 +91,8 @@ echo '{number:1,word:"one"} {number:2,word:"two"} {number:3,word:"three"}' |
9191
super db load -q -use numbers -
9292
super db query -f text '
9393
from :branches
94-
|> yield pool.name + "@" + branch.name
95-
|> sort'
94+
| yield pool.name + "@" + branch.name
95+
| sort'
9696
```
9797

9898
The lake then contains the two pools:
@@ -114,7 +114,7 @@ The following file `hello.jsup` is also used.
114114
_Source structured data from a local file_
115115

116116
```mdtest-command
117-
super -z -c 'file hello.jsup |> yield greeting'
117+
super -z -c 'file hello.jsup | yield greeting'
118118
```
119119

120120
```mdtest-output
@@ -133,7 +133,7 @@ super -z -c 'file hello.jsup format line'
133133
_Source structured data from a URI_
134134
```
135135
super -z -c 'get https://raw.githubusercontent.com/brimdata/zui-insiders/main/package.json
136-
|> yield productName'
136+
| yield productName'
137137
```
138138
=>
139139
```
@@ -163,7 +163,7 @@ super db -lake example query -z 'from coinflips@trial'
163163

164164
_Count the number of values in the `main` branch of all pools_
165165
```mdtest-command
166-
super db -lake example query -f text 'from * |> count()'
166+
super db -lake example query -f text 'from * | count()'
167167
```
168168

169169
```mdtest-output
@@ -172,9 +172,9 @@ super db -lake example query -f text 'from * |> count()'
172172
_Join the data from multiple pools_
173173
```mdtest-command
174174
super db -lake example query -z '
175-
from coinflips |> sort flip
176-
|> join (
177-
from numbers |> sort number
175+
from coinflips | sort flip
176+
| join (
177+
from numbers | sort number
178178
) on flip=number word'
179179
```
180180

@@ -186,16 +186,16 @@ super db -lake example query -z '
186186
_Use `pass` to combine our join output with data from yet another source_
187187
```mdtest-command
188188
super db -lake example query -z '
189-
from coinflips |> sort flip
190-
|> join (
191-
from numbers |> sort number
189+
from coinflips | sort flip
190+
| join (
191+
from numbers | sort number
192192
) on flip=number word
193-
|> from (
193+
| from (
194194
pass
195195
pool coinflips@trial =>
196196
c:=count()
197-
|> yield f"There were {int64(c)} flips"
198-
) |> sort this'
197+
| yield f"There were {int64(c)} flips"
198+
) | sort this'
199199
```
200200

201201
```mdtest-output

0 commit comments

Comments
 (0)