Skip to content

Commit 801910a

Browse files
authored
big docs update primarily SQL (#6569)
This commit adds SQL to the mdbook docs and makes a few other changes. The pipe form of "from" has been unified with SQL from and updated with a new style that better works with the left sidebar. Here the main topic of an md file is a single # at the top and each section begins with ##. We should do the rest of the docs in this style. The SQL docs follow this style. We also removed some trailing whitespace in a few places.
1 parent 7823e32 commit 801910a

File tree

25 files changed

+1889
-201
lines changed

25 files changed

+1889
-201
lines changed

book/src/SUMMARY.md

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -102,20 +102,18 @@
102102
- [unnest](super-sql/operators/unnest.md)
103103
- [values](super-sql/operators/values.md)
104104
- [where](super-sql/operators/where.md)
105-
- [SQL Clauses](super-sql/sql/intro.md)
106-
- [FROM](super-sql/sql/from.md)
105+
- [SQL](super-sql/sql/intro.md)
107106
- [SELECT](super-sql/sql/select.md)
107+
- [FROM](super-sql/sql/from.md)
108108
- [WHERE](super-sql/sql/where.md)
109109
- [GROUP BY](super-sql/sql/group-by.md)
110110
- [HAVING](super-sql/sql/having.md)
111-
- [FILTER](super-sql/sql/filter.md)
112111
- [VALUES](super-sql/sql/values.md)
113-
- [ORDER](super-sql/sql/order.md)
112+
- [ORDER BY](super-sql/sql/order-by.md)
114113
- [LIMIT](super-sql/sql/limit.md)
115-
- [JOIN](super-sql/sql/join.md)
116114
- [WITH](super-sql/sql/with.md)
117-
- [UNION](super-sql/sql/union.md)
118-
- [INTERSECT](super-sql/sql/intersect.md)
115+
- [JOIN](super-sql/sql/join.md)
116+
- [Set Operators](super-sql/sql/set-ops.md)
119117
- [Functions](super-sql/functions/intro.md)
120118
- [Generics](super-sql/functions/generics/intro.md)
121119
- [coalesce](super-sql/functions/generics/coalesce.md)

book/src/super-sql/aggregates/intro.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ with the particular function, and
1515
Aggregate functions may appear in
1616
* the [aggregate](../operators/aggregate.md) operator,
1717
* an aggregate [shortcut](../operators/intro.md#shortcuts), or
18-
* in [SQL operators](../sql/intro.md) when performing aggregations.
18+
* in [SQL expressions](../sql/intro.md) when performing aggregations.
1919

2020
When aggregate functions appear in context of grouping
2121
(e.g., the `by` clause of an [aggregate](../operators/aggregate.md) operator or a
22-
[SQL operator](../sql/intro.md) with a [GROUP BY](../sql/group-by.md) clause),
22+
[SELECT](../sql/select.md) query with a [GROUP BY](../sql/group-by.md) clause),
2323
then the aggregate function produces one output value for each
2424
unique combination of grouping expressions.
2525

book/src/super-sql/declarations/functions.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ fn stats(numbers): (
140140
| sort this
141141
| avg(this),min(this),max(this),mode:=collect(this)
142142
| mode:=mode[len(mode)/2]
143-
)
143+
)
144144
values stats(a)
145145
# input
146146
{a:[3,1,2]}

book/src/super-sql/expressions/inputs.md

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@ is always referenced as the special value `this`.
88

99
In [relational scoping](../intro.md#relational-scoping), input data
1010
is referenced by specifying the columns of one or more tables.
11-
See the [SQL section](../sql/intro.md#input-references) for
12-
details on how columns are bound to [identifiers](../queries.md#identifiers), how table references
13-
are resolved, and how `this` behaves in a SQL expression.
11+
See the [SQL section](../sql/intro.md) for
12+
details on how columns are [bound](../sql/intro.md#relational-bindings)
13+
to [identifiers](../queries.md#identifiers), how table references
14+
are resolved, and how [`this`](../sql/intro.md#this) behaves in a SQL expression.
1415

1516
The type of `this` may be any [type](../types/intro.md).
1617
When `this` is a [record](../types/record.md), references
@@ -29,12 +30,9 @@ tables or columns are referenced.
2930
In a SQL operator, if the input is not a record (i.e., not relational),
3031
then the input data can still be referred to as the value `this` and placed
3132
into an output relation using [SELECT](../sql/select.md).
32-
When referring to non-relational inputs with `*`, there are no columns and
33-
thus the select value is empty, i.e., the value `{}`.
34-
35-
When non-record data is referenced in a SQL operator and the input
36-
schema is dynamic and unknown, runtime [errors](../types/error.md) like `error("missing")`
37-
will generally arise and be present in the output data.
33+
Otherwise, column references to non-record data in dynamic inputs
34+
generally cause runtime [errors](../types/error.md)
35+
like `error("missing")`.
3836

3937
### Examples
4038

book/src/super-sql/expressions/intro.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ used by pipe operators.
2121

2222
While SQL expressions and pipe expressions share an identical syntax,
2323
their semantics diverge in some key ways:
24-
* SQL expressions that reference `this` have [semantics](../sql/intro.md#accessing-this)
24+
* SQL expressions that reference `this` have [semantics](../sql/intro.md#this)
2525
that depend on the SQL clause that expression appears in,
2626
* relational tables and/or columns cannot be referenced using aliases in pipe scoping,
2727
* double-quoted string [literals](literals.md) may be used in pipe expressions but are interpreted
@@ -52,7 +52,7 @@ Operators include
5252
an array, set, record, [map](../types/map.md), string, or [bytes](../types/bytes.md),
5353
* [logic](logic.md) to combine predicates using Boolean logic, and
5454
* [slices](slices.md) to extract subsequences from arrays, sets, strings, and bytes.
55-
55+
5656
### Identifier Resolution
5757

5858
An identifier that appears as an operand in an expression is resolved to

book/src/super-sql/expressions/subqueries.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ _Independent subqueries in SQL operators are supported while correlated subqueri
221221
let input = (values {x:1},{x:2},{x:3})
222222
select x
223223
from input
224-
where x >= (select avg(x) from input)
224+
where x >= (select avg(x) from input)
225225
# input
226226
227227
# expected output

book/src/super-sql/intro.md

Lines changed: 36 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -20,27 +20,16 @@ and the SuperSQL compiler often optimizes a query into an implementation
2020
different from the [dataflow](https://en.wikipedia.org/wiki/Dataflow) implied by the pipeline to achieve the
2121
same semantics with better performance.
2222

23-
While SuperSQL at its core is a pipe-oriented language, it is also
24-
[backward compatible](../intro.md#supersql) with relational SQL in that any
25-
arbitrarily complex SQL query may appear as a single pipe operator
26-
anywhere in a SuperSQL pipe query.
27-
28-
In other words, a single pipe operator that happens to be a standalone SQL query
29-
is also a SuperSQL pipe query.
30-
For example, these are all valid SuperSQL queries:
31-
```
32-
SELECT 'hello, world'
33-
SELECT * FROM table
34-
SELECT * FROM f1.json JOIN f2.json ON f1.id=f2.id
35-
SELECT watchers FROM https://api.github.com/repos/brimdata/super
36-
```
37-
38-
## Interactive UX
23+
## Friendly Syntax
3924

40-
To support an interactive pattern of usage, SuperSQL includes
41-
[search](operators/search.md) syntax
42-
reminiscent of Web or email keyword search along with
43-
[_operator shortcuts_](operators/intro.md#shortcuts).
25+
In addition to its user-friendly pipe syntax,
26+
SuperSQL embraces two key design patterns that simplify
27+
query editing for interactive usage:
28+
* [shortcuts](operators/intro.md#shortcuts) that reduce
29+
typing overhead and provide a concise syntax for common query patterns, and
30+
* [search](operators/search.md)
31+
reminiscent of Web or email keyword search, which is otherwise hard
32+
to carry out with traditional SQL syntax.
4433

4534
With shortcuts, verbose queries can be typed in a shorthand facilitating
4635
rapid data exploration. For example, the query
@@ -49,7 +38,10 @@ SELECT count(), key
4938
FROM source
5039
GROUP BY key
5140
```
52-
can be simplified as `from source | count() by key`.
41+
can be simplified to
42+
```
43+
from source | count() by key
44+
```
5345

5446
With search, all of the string fields in a value can easily be searched for
5547
patterns, e.g., this query
@@ -60,6 +52,23 @@ from source
6052
searches for the strings "example.com" and "urgent" in all of the string values in
6153
the input and also includes a numeric comparison regarding the field `message_length`.
6254

55+
## SQL Compatibility
56+
57+
While SuperSQL at its core is a pipe-oriented language, it is also
58+
[backward compatible](sql/intro.md) with relational SQL in that any
59+
arbitrarily complex SQL query may appear as a single pipe operator
60+
anywhere in a SuperSQL pipe query.
61+
62+
In other words, a single pipe operator that happens to be a standalone SQL query
63+
is also a SuperSQL pipe query.
64+
For example, these are all valid SuperSQL queries:
65+
```
66+
SELECT 'hello, world'
67+
SELECT * FROM table
68+
SELECT * FROM f1.json JOIN f2.json ON f1.id=f2.id
69+
SELECT watchers FROM https://api.github.com/repos/brimdata/super
70+
```
71+
6372
## Pipe Queries
6473

6574
The entities that transform data within a SuperSQL pipeline are called
@@ -109,7 +118,7 @@ fork
109118

110119
## Pipe Sources
111120

112-
Like SQL, input data for a query is typically sourced with the
121+
Like SQL, input data for a pipe query is typically sourced with the
113122
[from](operators/from.md) operator.
114123

115124
When `from` is not present, the file arguments to the
@@ -331,12 +340,12 @@ The array subquery produces an array value so it is often desirable to
331340
[unnest](operators/unnest.md) this array with respect to the outer
332341
values as in
333342
```
334-
from f1.json | unnest {outer:this,inner:[from f2.json | ...]} into ( <scope> )
343+
from f1.json | unnest {outer:this,inner:[from f2.json | ...]} into ( <query> )
335344
```
336-
where `<scope>` can be an arbitrary pipe query that processes each
345+
where `<query>` is an arbitrary pipe query that processes each
337346
collection of unnested values separately as a unit for each outer value.
338-
The `into ( <scope> )` body is an optional component of `unnest`, and if absent,
339-
the unnested collection boundaries are ignored and all of the unnested data is output.
347+
The `into ( <query> )` body is an optional component of `unnest`, and if absent,
348+
the unnested collection boundaries are ignored and all of the unnested data is output as a combined sequence.
340349

341350
With the `unnest` operator, we can now consider how a [correlated subquery](https://en.wikipedia.org/wiki/Correlated_subquery) from
342351
SQL can be implemented purely as a pipe query with pipe scoping.
@@ -363,7 +372,7 @@ giving the same result
363372
{s:21}
364373
```
365374

366-
## Strong Typing
375+
## Type Checking
367376

368377
Data in SuperSQL is always strongly typed.
369378

0 commit comments

Comments
 (0)