-
Notifications
You must be signed in to change notification settings - Fork 29.3k
[SPARK-49073][SQL][DOCS] Improve the doc sql-ref-syntax-qry-select.md
#47552
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
5ae01ad
5eea5f2
7b93004
9c7f49e
43c7c0a
a122134
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -41,14 +41,23 @@ select_statement [ { UNION | INTERSECT | EXCEPT } [ ALL | DISTINCT ] select_stat | |
|
|
||
| While `select_statement` is defined as | ||
| ```sql | ||
| SELECT [ hints , ... ] [ ALL | DISTINCT ] { [ [ named_expression | regex_column_names | star ] [ , ... ] | TRANSFORM (...) ] } | ||
| SELECT [ hints , ... ] [ ALL | DISTINCT ] { [ [ named_expression | regex_column_names | star_clause ] [ , ... ] | TRANSFORM (...) ] } | ||
| FROM { from_item [ , ... ] } | ||
| [ PIVOT clause ] | ||
| [ UNPIVOT clause ] | ||
| [ LATERAL VIEW clause ] [ ... ] | ||
| [ WHERE boolean_expression ] | ||
| [ GROUP BY expression [ , ... ] ] | ||
| [ HAVING boolean_expression ] | ||
|
|
||
| named_expression | ||
| expression [[AS] alias] | ||
|
panbingkun marked this conversation as resolved.
Outdated
|
||
|
|
||
| star_clause | ||
| [ { table_name | view_name } . ] * [ except_clause ] | ||
|
|
||
| except_clause | ||
| EXCEPT ( { column_name | field_name } [, ...] ) | ||
| ``` | ||
|
|
||
| ### Parameters | ||
|
|
@@ -59,7 +68,7 @@ SELECT [ hints , ... ] [ ALL | DISTINCT ] { [ [ named_expression | regex_column_ | |
| These table expressions are allowed to be referenced later in the FROM clause. This is useful to abstract | ||
| out repeated subquery blocks in the FROM clause and improves readability of the query. | ||
|
|
||
| * **hints** | ||
| * **[hints](sql-ref-syntax-qry-select-hints.html)** | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we go ahead with this, we should probably do it for all? I would separate the PR
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay,
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
|
|
||
| Hints can be specified to help spark optimizer make better planning decisions. Currently spark supports hints | ||
| that influence selection of join strategies and repartitioning of the data. | ||
|
|
@@ -76,11 +85,9 @@ SELECT [ hints , ... ] [ ALL | DISTINCT ] { [ [ named_expression | regex_column_ | |
|
|
||
| An expression with an assigned name. In general, it denotes a column expression. | ||
|
|
||
| **Syntax:** `expression [[AS] alias]` | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have already moved this up. |
||
|
|
||
| * **star** | ||
| * **[star_clause](sql-ref-syntax-qry-star.html)** | ||
|
|
||
| The `*` (star) clause is used to select all or most columns from one or all relations in a FROM clause. | ||
| A shorthand to name all the referenceable columns in the FROM clause or a specific table reference’s columns or fields in the FROM clause. | ||
|
|
||
| * **from_item** | ||
|
|
||
|
|
@@ -94,56 +101,56 @@ SELECT [ hints , ... ] [ ALL | DISTINCT ] { [ [ named_expression | regex_column_ | |
| * [ [LATERAL](sql-ref-syntax-qry-select-lateral-subquery.html) ] ( Subquery ) | ||
| * [File](sql-ref-syntax-qry-select-file.html) | ||
|
|
||
| * **PIVOT** | ||
| * **[PIVOT](sql-ref-syntax-qry-select-pivot.html)** | ||
|
|
||
| The `PIVOT` clause is used for data perspective; We can get the aggregated values based on specific column value. | ||
|
|
||
| * **UNPIVOT** | ||
| * **[UNPIVOT](sql-ref-syntax-qry-select-unpivot.html)** | ||
|
|
||
| The `UNPIVOT` clause transforms columns into rows. It is the reverse of `PIVOT`, except for aggregation of values. | ||
|
|
||
| * **LATERAL VIEW** | ||
| * **[LATERAL VIEW](sql-ref-syntax-qry-select-lateral-view.html)** | ||
|
|
||
| The `LATERAL VIEW` clause is used in conjunction with generator functions such as `EXPLODE`, which will generate a virtual table containing one or more rows. `LATERAL VIEW` will apply the rows to each original output row. | ||
|
|
||
| * **WHERE** | ||
| * **[WHERE](sql-ref-syntax-qry-select-where.html)** | ||
|
|
||
| Filters the result of the FROM clause based on the supplied predicates. | ||
|
|
||
| * **GROUP BY** | ||
| * **[GROUP BY](sql-ref-syntax-qry-select-groupby.html)** | ||
|
|
||
| Specifies the expressions that are used to group the rows. This is used in conjunction with aggregate functions | ||
| (MIN, MAX, COUNT, SUM, AVG, etc.) to group rows based on the grouping expressions and aggregate values in each group. | ||
| When a FILTER clause is attached to an aggregate function, only the matching rows are passed to that function. | ||
|
|
||
| * **HAVING** | ||
| * **[HAVING](sql-ref-syntax-qry-select-having.html)** | ||
|
|
||
| Specifies the predicates by which the rows produced by GROUP BY are filtered. The HAVING clause is used to | ||
| filter rows after the grouping is performed. If HAVING is specified without GROUP BY, it indicates a GROUP BY | ||
| without grouping expressions (global aggregate). | ||
|
|
||
| * **ORDER BY** | ||
| * **[ORDER BY](sql-ref-syntax-qry-select-orderby.html)** | ||
|
|
||
| Specifies an ordering of the rows of the complete result set of the query. The output rows are ordered | ||
| across the partitions. This parameter is mutually exclusive with `SORT BY`, | ||
| `CLUSTER BY` and `DISTRIBUTE BY` and can not be specified together. | ||
|
|
||
| * **SORT BY** | ||
| * **[SORT BY](sql-ref-syntax-qry-select-sortby.html)** | ||
|
|
||
| Specifies an ordering by which the rows are ordered within each partition. This parameter is mutually | ||
| exclusive with `ORDER BY` and `CLUSTER BY` and can not be specified together. | ||
|
|
||
| * **CLUSTER BY** | ||
| * **[CLUSTER BY](sql-ref-syntax-qry-select-clusterby.html)** | ||
|
|
||
| Specifies a set of expressions that is used to repartition and sort the rows. Using this clause has | ||
| the same effect of using `DISTRIBUTE BY` and `SORT BY` together. | ||
|
|
||
| * **DISTRIBUTE BY** | ||
| * **[DISTRIBUTE BY](sql-ref-syntax-qry-select-distribute-by.html)** | ||
|
|
||
| Specifies a set of expressions by which the result rows are repartitioned. This parameter is mutually | ||
| exclusive with `ORDER BY` and `CLUSTER BY` and can not be specified together. | ||
|
|
||
| * **LIMIT** | ||
| * **[LIMIT](sql-ref-syntax-qry-select-limit.html)** | ||
|
|
||
| Specifies the maximum number of rows that can be returned by a statement or subquery. This clause | ||
| is mostly used in the conjunction with `ORDER BY` to produce a deterministic result. | ||
|
|
@@ -175,7 +182,7 @@ SELECT [ hints , ... ] [ ALL | DISTINCT ] { [ [ named_expression | regex_column_ | |
| ) | ||
| ``` | ||
|
|
||
| * **TRANSFORM** | ||
| * **[TRANSFORM](sql-ref-syntax-qry-select-transform.html)** | ||
|
|
||
| Specifies a hive-style transform query specification to transform the input by forking and running user-specified command or script. | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we should do
star [ except_clause ]instead of having except_clause inside the star_clause.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am referring to this doc https://docs.databricks.com/en/sql/language-manual/sql-ref-syntax-qry-select.html, as follows:

Based on my understanding, I think
one possible reasonis thatEXCEPTcannot exist independently ofSTAR, which seems toemphasizethis relationship.