Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
maropu committed Apr 8, 2020
1 parent c7001b7 commit 1abe5b8
Show file tree
Hide file tree
Showing 8 changed files with 155 additions and 117 deletions.
3 changes: 3 additions & 0 deletions docs/sql-ref-syntax-qry-select-distribute-by.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ license: |
See the License for the specific language governing permissions and
limitations under the License.
---

### Description

The <code>DISTRIBUTE BY</code> clause is used to repartition the data based
on the input expressions. Unlike the [CLUSTER BY](sql-ref-syntax-qry-select-clusterby.html)
clause, this does not sort the data within each partition.
Expand Down
3 changes: 3 additions & 0 deletions docs/sql-ref-syntax-qry-select-groupby.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ license: |
See the License for the specific language governing permissions and
limitations under the License.
---

### Description

The <code>GROUP BY</code> clause is used to group the rows based on a set of specified grouping expressions and compute aggregations on
the group of rows based on one or more specified aggregate functions. Spark also supports advanced aggregations to do multiple
aggregations for the same input record set via `GROUPING SETS`, `CUBE`, `ROLLUP` clauses.
Expand Down
3 changes: 3 additions & 0 deletions docs/sql-ref-syntax-qry-select-having.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ license: |
See the License for the specific language governing permissions and
limitations under the License.
---

### Description

The <code>HAVING</code> clause is used to filter the results produced by
<code>GROUP BY</code> based on the specified condition. It is often used
in conjunction with a [GROUP BY](sql-ref-syntax-qry-select-groupby.html)
Expand Down
3 changes: 3 additions & 0 deletions docs/sql-ref-syntax-qry-select-limit.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ license: |
See the License for the specific language governing permissions and
limitations under the License.
---

### Description

The <code>LIMIT</code> clause is used to constrain the number of rows returned by
the [SELECT](sql-ref-syntax-qry-select.html) statement. In general, this clause
is used in conjunction with [ORDER BY](sql-ref-syntax-qry-select-orderby.html) to
Expand Down
3 changes: 3 additions & 0 deletions docs/sql-ref-syntax-qry-select-orderby.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ license: |
See the License for the specific language governing permissions and
limitations under the License.
---

### Description

The <code>ORDER BY</code> clause is used to return the result rows in a sorted manner
in the user specified order. Unlike the [SORT BY](sql-ref-syntax-qry-select-sortby.html)
clause, this clause guarantees a total order in the output.
Expand Down
251 changes: 134 additions & 117 deletions docs/sql-ref-syntax-qry-select-setops.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,159 +19,176 @@ license: |
limitations under the License.
---

### Description

Set operators are used to combine two input relations into a single one. Spark SQL supports three types of set operators:
- `EXCEPT` or `MINUS`
- `INTERSECT`
- `UNION`

- `EXCEPT` or `MINUS`
- `INTERSECT`
- `UNION`

Note that input relations must have the same number of columns and compatible data types for the respective columns.

### EXCEPT

`EXCEPT` and `EXCEPT ALL` return the rows that are found in one relation but not the other. `EXCEPT` (alternatively, `EXCEPT DISTINCT`) takes only distinct rows while `EXCEPT ALL` does not remove duplicates from the result rows. Note that `MINUS` is an alias for `EXCEPT`.

#### Syntax

{% highlight sql %}
[ ( ] relation [ ) ] EXCEPT | MINUS [ ALL | DISTINCT ] [ ( ] relation [ ) ]
{% endhighlight %}

### INTERSECT
`INTERSECT` and `INTERSECT ALL` return the rows that are found in both relations. `INTERSECT` (alternatively, `INTERSECT DISTINCT`) takes only distinct rows while `INTERSECT ALL` does not remove duplicates from the result rows.
#### Examples

#### Syntax
{% highlight sql %}
[ ( ] relation [ ) ] INTERSECT [ ALL | DISTINCT ] [ ( ] relation [ ) ]
{% endhighlight %}

### UNION
`UNION` and `UNION ALL` return the rows that are found in either relation. `UNION` (alternatively, `UNION DISTINCT`) takes only distinct rows while `UNION ALL` does not remove duplicates from the result rows.

#### Syntax
{% highlight sql %}
[ ( ] relation [ ) ] UNION [ ALL | DISTINCT ] [ ( ] relation [ ) ]
{% endhighlight %}

### Examples
{% highlight sql %}
-- Use number1 and number2 tables to demonstrate set operators.
-- Use number1 and number2 tables to demonstrate set operators in this page.
SELECT * FROM number1;
+---+
| c|
+---+
| 3|
| 1|
| 2|
| 2|
| 3|
| 4|
+---+

+---+
| c|
+---+
| 3|
| 1|
| 2|
| 2|
| 3|
| 4|
+---+
SELECT * FROM number2;
+---+
| c|
+---+
| 5|
| 1|
| 2|
| 2|
+---+
+---+
| c|
+---+
| 5|
| 1|
| 2|
| 2|
+---+

SELECT c FROM number1 EXCEPT SELECT c FROM number2;
+---+
| c|
+---+
| 3|
| 4|
+---+
+---+
| c|
+---+
| 3|
| 4|
+---+

SELECT c FROM number1 MINUS SELECT c FROM number2;
+---+
| c|
+---+
| 3|
| 4|
+---+
+---+
| c|
+---+
| 3|
| 4|
+---+

SELECT c FROM number1 EXCEPT ALL (SELECT c FROM number2);
+---+
| c|
+---+
| 3|
| 3|
| 4|
+---+
+---+
| c|
+---+
| 3|
| 3|
| 4|
+---+

SELECT c FROM number1 MINUS ALL (SELECT c FROM number2);
+---+
| c|
+---+
| 3|
| 3|
| 4|
+---+
+---+
| c|
+---+
| 3|
| 3|
| 4|
+---+
{% endhighlight %}

### INTERSECT

`INTERSECT` and `INTERSECT ALL` return the rows that are found in both relations. `INTERSECT` (alternatively, `INTERSECT DISTINCT`) takes only distinct rows while `INTERSECT ALL` does not remove duplicates from the result rows.

#### Syntax

{% highlight sql %}
[ ( ] relation [ ) ] INTERSECT [ ALL | DISTINCT ] [ ( ] relation [ ) ]
{% endhighlight %}

#### Examples

{% highlight sql %}
(SELECT c FROM number1) INTERSECT (SELECT c FROM number2);
+---+
| c|
+---+
| 1|
| 2|
+---+
+---+
| c|
+---+
| 1|
| 2|
+---+

(SELECT c FROM number1) INTERSECT DISTINCT (SELECT c FROM number2);
+---+
| c|
+---+
| 1|
| 2|
+---+
+---+
| c|
+---+
| 1|
| 2|
+---+

(SELECT c FROM number1) INTERSECT ALL (SELECT c FROM number2);
+---+
| c|
+---+
| 1|
| 2|
| 2|
+---+
+---+
| c|
+---+
| 1|
| 2|
| 2|
+---+
{% endhighlight %}

### UNION

`UNION` and `UNION ALL` return the rows that are found in either relation. `UNION` (alternatively, `UNION DISTINCT`) takes only distinct rows while `UNION ALL` does not remove duplicates from the result rows.

#### Syntax

{% highlight sql %}
[ ( ] relation [ ) ] UNION [ ALL | DISTINCT ] [ ( ] relation [ ) ]
{% endhighlight %}

### Examples

{% highlight sql %}
(SELECT c FROM number1) UNION (SELECT c FROM number2);
+---+
| c|
+---+
| 1|
| 3|
| 5|
| 4|
| 2|
+---+
+---+
| c|
+---+
| 1|
| 3|
| 5|
| 4|
| 2|
+---+

(SELECT c FROM number1) UNION DISTINCT (SELECT c FROM number2);
+---+
| c|
+---+
| 1|
| 3|
| 5|
| 4|
| 2|
+---+
+---+
| c|
+---+
| 1|
| 3|
| 5|
| 4|
| 2|
+---+

SELECT c FROM number1 UNION ALL (SELECT c FROM number2);
+---+
| c|
+---+
| 3|
| 1|
| 2|
| 2|
| 3|
| 4|
| 5|
| 1|
| 2|
| 2|
+---+

+---+
| c|
+---+
| 3|
| 1|
| 2|
| 2|
| 3|
| 4|
| 5|
| 1|
| 2|
| 2|
+---+
{% endhighlight %}

### Related Statements
Expand Down
3 changes: 3 additions & 0 deletions docs/sql-ref-syntax-qry-select-sortby.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ license: |
See the License for the specific language governing permissions and
limitations under the License.
---

### Description

The <code>SORT BY</code> clause is used to return the result rows sorted
within each partition in the user specified order. When there is more than one partition
<code>SORT BY</code> may return result that is partially ordered. This is different
Expand Down
3 changes: 3 additions & 0 deletions docs/sql-ref-syntax-qry-select-where.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ license: |
See the License for the specific language governing permissions and
limitations under the License.
---

### Description

The <code>WHERE</code> clause is used to limit the results of the <code>FROM</code>
clause of a query or a subquery based on the specified condition.

Expand Down

0 comments on commit 1abe5b8

Please sign in to comment.