Skip to content

Commit

Permalink
Convert more operator examples to mdtest-spq
Browse files Browse the repository at this point in the history
  • Loading branch information
philrz committed Jan 24, 2025
1 parent 5f67a82 commit ac9f349
Show file tree
Hide file tree
Showing 11 changed files with 310 additions and 203 deletions.
2 changes: 1 addition & 1 deletion docs/language/operators/get.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@

### Synopsis

`get` is a shorthand notation for `from`. See the [from operator](from.md) documentation for details.
`get` is a shorthand notation for `from`. See the [`from` operator](from.md) documentation for details.
37 changes: 22 additions & 15 deletions docs/language/operators/head.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,30 +17,37 @@ is not provided, the value of N defaults to `1`.
### Examples

_Grab first two values of arbitrary sequence_
```mdtest-command
echo '1 "foo" [1,2,3]' | super -z -c 'head 2' -
```

```mdtest-output
```mdtest-spq
# spq
head 2
# input
1
"foo"
[1,2,3]
# expected output
1
"foo"
```

_Grab first two values of arbitrary sequence, using a different representation of two_
```mdtest-command
echo '1 "foo" [1,2,3]' | super -z -c 'head 1+1' -
```

```mdtest-output
```mdtest-spq
# spq
head 1+1
# input
1
"foo"
[1,2,3]
# expected output
1
"foo"
```

_Grab the first record of a record sequence_
```mdtest-command
echo '{a:"hello"}{b:"world"}' | super -z -c head -
```

```mdtest-output
```mdtest-spq
# spq
head
# input
{a:"hello"}
# expected output
{a:"hello"}
```
12 changes: 8 additions & 4 deletions docs/language/operators/join.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

The first `join` syntax shown above was more recently introduced and is in some
ways similar to other languages such as SQL. The second was the original `join`
syntax in SuperPipe. Most joins can be expressed using either syntax. See the
syntax in the language. Most joins can be expressed using either syntax. See the
[join tutorial](../../tutorials/join.md)
for details.

Expand All @@ -40,9 +40,13 @@ The available join types are:

For anti join, the `<right-expr>` is undefined and thus cannot be specified.

> Currently, only exact equi-join is supported and join keys must be field
> expressions. A future version of join will have more flexible join
> expressions.
{{% tip "Note" %}}

Currently, only exact equi-join is supported and join keys must be field
expressions. A future version of `join` will have more flexible join
expressions.

{{% /tip %}}

### Examples

Expand Down
12 changes: 6 additions & 6 deletions docs/language/operators/load.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ echo '{flip:1,result:"heads"} {flip:2,result:"tails"}' |
super db -q create -orderby flip:asc bigflips
super db query -f text '
from :branches
|> yield pool.name + "@" + branch.name
|> sort'
| yield pool.name + "@" + branch.name
| sort'
```

The lake then contains the two pools:
Expand All @@ -62,8 +62,8 @@ _Modify some values, load them into the `main` branch of our empty `bigflips` po
```mdtest-command
super db -lake example query '
from coinflips
|> result:=upper(result)
|> load bigflips
| result:=upper(result)
| load bigflips
' > /dev/null
super db -lake example query -z 'from bigflips'
Expand All @@ -78,8 +78,8 @@ _Add a filtered subset of records to our `onlytails` branch, while also adding m
```mdtest-command
super db -lake example query '
from coinflips
|> result=="tails"
|> load coinflips@onlytails
| result=="tails"
| load coinflips@onlytails
author "Steve"
message "A subset"
meta "\"Additional metadata\""
Expand Down
16 changes: 11 additions & 5 deletions docs/language/operators/merge.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,17 @@ where the values from the upstream pipeline branches are forwarded based on thes
### Examples

_Copy input to two pipeline branches and merge_
```mdtest-command
echo '1 2' | super -z -c 'fork (=>pass =>pass) |> merge this' -
```

```mdtest-output
```mdtest-spq
# spq
fork (
=>pass
=>pass
)
| merge this
# input
1
2
# expected output
1
1
2
Expand Down
117 changes: 68 additions & 49 deletions docs/language/operators/over.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,94 +31,113 @@ The nested subquery depicted as `<lateral>` is called a [lateral subquery](../la
### Examples

_Over evaluates each expression and emits it_
```mdtest-command
echo null | super -z -c 'over 1,2,"foo"' -
```

```mdtest-output
```mdtest-spq
# spq
over 1,2,"foo"
# input
null
# expected output
1
2
"foo"
```
_The over clause is evaluated once per each input value_
```mdtest-command
echo "null null" | super -z -c 'over 1,2' -
```

```mdtest-output
_The over clause is evaluated once per each input value_
```mdtest-spq
# spq
over 1,2
# input
null
null
# expected output
1
2
1
2
```
_Array elements are enumerated_
```mdtest-command
echo null | super -z -c 'over [1,2],[3,4,5]' -
```

```mdtest-output
_Array elements are enumerated_
```mdtest-spq
# spq
over [1,2],[3,4,5]
# input
null
# expected output
1
2
3
4
5
```
_Over traversing an array_
```mdtest-command
echo '{a:[1,2,3]}' | super -z -c 'over a' -
```

```mdtest-output
_Over traversing an array_
```mdtest-spq
# spq
over a
# input
{a:[1,2,3]}
# expected output
1
2
3
```
_Filter the traversed values_

```mdtest-command
echo '{a:[6,5,4]} {a:[3,2,1]}' | super -z -c 'over a |> this % 2 == 0' -
```

```mdtest-output
_Filter the traversed values_
```mdtest-spq
# spq
over a | this % 2 == 0
# input
{a:[6,5,4]}
{a:[3,2,1]}
# expected output
6
4
2
```
_Aggregate the traversed values_

```mdtest-command
echo '{a:[1,2]} {a:[3,4,5]}' | super -z -c 'over a |> sum(this)' -
```

```mdtest-output
_Aggregate the traversed values_
```mdtest-spq
# spq
over a | sum(this)
# input
{a:[1,2]}
{a:[3,4,5]}
# expected output
15
```
_Aggregate the traversed values in a lateral query_
```mdtest-command
echo '{a:[1,2]} {a:[3,4,5]}' | super -z -c 'over a => ( sum(this) )' -
```

```mdtest-output
_Aggregate the traversed values in a lateral query_
```mdtest-spq
# spq
over a => ( sum(this) )
# input
{a:[1,2]}
{a:[3,4,5]}
# expected output
3
12
```
_Access the outer values in a lateral query_
```mdtest-command
echo '{a:[1,2],s:"foo"} {a:[3,4,5],s:"bar"}' |
super -z -c 'over a with s => (sum(this) |> yield {s,sum:this})' -
```

```mdtest-output
_Access the outer values in a lateral query_
```mdtest-spq
# spq
over a with s => (sum(this) | yield {s,sum:this})
# input
{a:[1,2],s:"foo"}
{a:[3,4,5],s:"bar"}
# expected output
{s:"foo",sum:3}
{s:"bar",sum:12}
```
_Traverse a record by flattening it_
```mdtest-command
echo '{s:"foo",r:{a:1,b:2}} {s:"bar",r:{a:3,b:4}} ' |
super -z -c 'over flatten(r) with s => (yield {s,key:key[0],value})' -
```

```mdtest-output
_Traverse a record by flattening it_
```mdtest-spq
# spq
over flatten(r) with s => (yield {s,key:key[0],value})
# input
{s:"foo",r:{a:1,b:2}}
{s:"bar",r:{a:3,b:4}}
# expected output
{s:"foo",key:"a",value:1}
{s:"foo",key:"b",value:2}
{s:"bar",key:"a",value:3}
Expand Down
34 changes: 19 additions & 15 deletions docs/language/operators/pass.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,31 @@ with operators that handle multiple branches of the pipeline such as
### Examples

_Copy input to output_
```mdtest-command
echo '1 2 3' | super -z -c pass -
```

```mdtest-output
```mdtest-spq
# spq
pass
# input
1
2
3
# expected output
1
2
3
```

_Copy each input value to three parallel pipeline branches and leave the values unmodified on one of them_
```mdtest-command
echo '"HeLlo, WoRlD!"' | super -z -c '
fork (
=> pass
=> upper(this)
=> lower(this)
) |> sort' -
```

```mdtest-output
```mdtest-spq
# spq
fork (
=> pass
=> upper(this)
=> lower(this)
)
| sort
# input
"HeLlo, WoRlD!"
# expected output
"HELLO, WORLD!"
"HeLlo, WoRlD!"
"hello, world!"
Expand Down
Loading

0 comments on commit ac9f349

Please sign in to comment.