From 5f5c0c43ed4958f054f351c565332e122659e97a Mon Sep 17 00:00:00 2001 From: Huaxin Gao Date: Mon, 4 May 2020 13:31:22 -0700 Subject: [PATCH 01/10] rebase --- docs/_data/menu-sql.yaml | 20 +- docs/sql-ref-ansi-compliance.md | 8 +- docs/sql-ref-datatypes.md | 4 +- docs/sql-ref-functions-udf-aggregate.md | 101 +++---- docs/sql-ref-functions-udf-hive.md | 12 +- docs/sql-ref-functions-udf-scalar.md | 28 +- docs/sql-ref-identifier.md | 43 ++- docs/sql-ref-literals.md | 256 ++++++++--------- docs/sql-ref-null-semantics.md | 44 +-- docs/sql-ref-syntax-aux-analyze-table.md | 64 ++--- docs/sql-ref-syntax-aux-cache-cache-table.md | 98 +++---- docs/sql-ref-syntax-aux-cache-clear-cache.md | 16 +- docs/sql-ref-syntax-aux-cache-refresh.md | 24 +- .../sql-ref-syntax-aux-cache-uncache-table.md | 31 +-- docs/sql-ref-syntax-aux-conf-mgmt-reset.md | 10 +- docs/sql-ref-syntax-aux-conf-mgmt-set.md | 31 +-- docs/sql-ref-syntax-aux-describe-database.md | 21 +- docs/sql-ref-syntax-aux-describe-function.md | 30 +- docs/sql-ref-syntax-aux-describe-query.md | 44 ++- docs/sql-ref-syntax-aux-describe-table.md | 62 ++--- docs/sql-ref-syntax-aux-refresh-table.md | 31 +-- ...l-ref-syntax-aux-resource-mgmt-add-file.md | 21 +- ...ql-ref-syntax-aux-resource-mgmt-add-jar.md | 20 +- ...-ref-syntax-aux-resource-mgmt-list-file.md | 14 +- ...l-ref-syntax-aux-resource-mgmt-list-jar.md | 14 +- docs/sql-ref-syntax-aux-show-columns.md | 2 +- docs/sql-ref-syntax-aux-show-create-table.md | 27 +- docs/sql-ref-syntax-aux-show-databases.md | 32 +-- docs/sql-ref-syntax-aux-show-functions.md | 59 ++-- docs/sql-ref-syntax-aux-show-partitions.md | 47 ++-- docs/sql-ref-syntax-aux-show-table.md | 56 ++-- docs/sql-ref-syntax-aux-show-tables.md | 41 ++- docs/sql-ref-syntax-aux-show-tblproperties.md | 51 ++-- docs/sql-ref-syntax-aux-show-views.md | 45 ++- docs/sql-ref-syntax-ddl-alter-database.md | 17 +- docs/sql-ref-syntax-ddl-alter-table.md | 249 +++++++---------- docs/sql-ref-syntax-ddl-alter-view.md | 124 ++++----- docs/sql-ref-syntax-ddl-create-database.md | 39 +-- docs/sql-ref-syntax-ddl-create-function.md | 87 +++--- ...-ref-syntax-ddl-create-table-datasource.md | 100 +++---- ...-ref-syntax-ddl-create-table-hiveformat.md | 99 +++---- docs/sql-ref-syntax-ddl-create-table-like.md | 73 +++-- docs/sql-ref-syntax-ddl-create-table.md | 10 +- docs/sql-ref-syntax-ddl-create-view.md | 82 +++--- docs/sql-ref-syntax-ddl-drop-database.md | 42 ++- docs/sql-ref-syntax-ddl-drop-function.md | 49 ++-- docs/sql-ref-syntax-ddl-drop-table.md | 37 ++- docs/sql-ref-syntax-ddl-drop-view.md | 41 ++- docs/sql-ref-syntax-ddl-repair-table.md | 25 +- docs/sql-ref-syntax-ddl-truncate-table.md | 43 ++- docs/sql-ref-syntax-dml-insert-into.md | 90 +++--- ...tax-dml-insert-overwrite-directory-hive.md | 75 ++--- ...f-syntax-dml-insert-overwrite-directory.md | 74 +++-- ...l-ref-syntax-dml-insert-overwrite-table.md | 87 +++--- docs/sql-ref-syntax-dml-insert.md | 8 +- docs/sql-ref-syntax-dml-load.md | 67 ++--- docs/sql-ref-syntax-dml.md | 4 +- docs/sql-ref-syntax-qry-explain.md | 58 ++-- docs/sql-ref-syntax-qry-sampling.md | 18 +- docs/sql-ref-syntax-qry-select-clusterby.md | 33 +-- docs/sql-ref-syntax-qry-select-cte.md | 35 +-- ...sql-ref-syntax-qry-select-distribute-by.md | 33 +-- docs/sql-ref-syntax-qry-select-groupby.md | 261 +++++++++--------- docs/sql-ref-syntax-qry-select-having.md | 54 ++-- docs/sql-ref-syntax-qry-select-hints.md | 56 ++-- .../sql-ref-syntax-qry-select-inline-table.md | 32 +-- docs/sql-ref-syntax-qry-select-join.md | 185 ++++++------- docs/sql-ref-syntax-qry-select-like.md | 51 ++-- docs/sql-ref-syntax-qry-select-limit.md | 39 ++- docs/sql-ref-syntax-qry-select-orderby.md | 82 +++--- docs/sql-ref-syntax-qry-select-setops.md | 26 +- docs/sql-ref-syntax-qry-select-sortby.md | 84 +++--- docs/sql-ref-syntax-qry-select-tvf.md | 66 +++-- docs/sql-ref-syntax-qry-select-usedb.md | 23 +- docs/sql-ref-syntax-qry-select-where.md | 37 ++- docs/sql-ref-syntax-qry-select.md | 209 +++++++------- docs/sql-ref-syntax-qry-window.md | 89 +++--- docs/sql-ref-syntax-qry.md | 35 +-- 78 files changed, 1960 insertions(+), 2475 deletions(-) diff --git a/docs/_data/menu-sql.yaml b/docs/_data/menu-sql.yaml index dfe4cfab2a2ab..57fc493dad2f2 100644 --- a/docs/_data/menu-sql.yaml +++ b/docs/_data/menu-sql.yaml @@ -156,22 +156,22 @@ url: sql-ref-syntax-qry-select-distribute-by.html - text: LIMIT Clause url: sql-ref-syntax-qry-select-limit.html + - text: Common Table Expression + url: sql-ref-syntax-qry-select-cte.html + - text: Inline Table + url: sql-ref-syntax-qry-select-inline-table.html - text: JOIN url: sql-ref-syntax-qry-select-join.html - text: Join Hints url: sql-ref-syntax-qry-select-hints.html + - text: LIKE Predicate + url: sql-ref-syntax-qry-select-like.html - text: Set Operators url: sql-ref-syntax-qry-select-setops.html - text: TABLESAMPLE url: sql-ref-syntax-qry-sampling.html - text: Table-valued Function url: sql-ref-syntax-qry-select-tvf.html - - text: Inline Table - url: sql-ref-syntax-qry-select-inline-table.html - - text: Common Table Expression - url: sql-ref-syntax-qry-select-cte.html - - text: LIKE Predicate - url: sql-ref-syntax-qry-select-like.html - text: Window Function url: sql-ref-syntax-qry-window.html - text: EXPLAIN @@ -213,20 +213,20 @@ subitems: - text: SHOW COLUMNS url: sql-ref-syntax-aux-show-columns.html + - text: SHOW CREATE TABLE + url: sql-ref-syntax-aux-show-create-table.html - text: SHOW DATABASES url: sql-ref-syntax-aux-show-databases.html - text: SHOW FUNCTIONS url: sql-ref-syntax-aux-show-functions.html + - text: SHOW PARTITIONS + url: sql-ref-syntax-aux-show-partitions.html - text: SHOW TABLE url: sql-ref-syntax-aux-show-table.html - text: SHOW TABLES url: sql-ref-syntax-aux-show-tables.html - text: SHOW TBLPROPERTIES url: sql-ref-syntax-aux-show-tblproperties.html - - text: SHOW PARTITIONS - url: sql-ref-syntax-aux-show-partitions.html - - text: SHOW CREATE TABLE - url: sql-ref-syntax-aux-show-create-table.html - text: SHOW VIEWS url: sql-ref-syntax-aux-show-views.html - text: CONFIGURATION MANAGEMENT diff --git a/docs/sql-ref-ansi-compliance.md b/docs/sql-ref-ansi-compliance.md index 93fb10b24e99f..a9c91473c7dd8 100644 --- a/docs/sql-ref-ansi-compliance.md +++ b/docs/sql-ref-ansi-compliance.md @@ -41,7 +41,7 @@ This means that in case an operation causes overflows, the result is the same wi On the other hand, Spark SQL returns null for decimal overflows. When `spark.sql.ansi.enabled` is set to `true` and an overflow occurs in numeric and interval arithmetic operations, it throws an arithmetic exception at runtime. -{% highlight sql %} +```sql -- `spark.sql.ansi.enabled=true` SELECT 2147483647 + 1; java.lang.ArithmeticException: integer overflow @@ -53,7 +53,7 @@ SELECT 2147483647 + 1; +----------------+ | -2147483648| +----------------+ -{% endhighlight %} +``` ### Type Conversion @@ -64,7 +64,7 @@ On the other hand, `INSERT INTO` syntax throws an analysis exception when the AN Currently, the ANSI mode affects explicit casting and assignment casting only. In future releases, the behaviour of type coercion might change along with the other two type conversion rules. -{% highlight sql %} +```sql -- Examples of explicit casting -- `spark.sql.ansi.enabled=true` @@ -105,7 +105,7 @@ SELECT * FROM t; +---+ | 1| +---+ -{% endhighlight %} +``` ### SQL Functions diff --git a/docs/sql-ref-datatypes.md b/docs/sql-ref-datatypes.md index 3f6b6b590f843..f27f1a0ca967f 100644 --- a/docs/sql-ref-datatypes.md +++ b/docs/sql-ref-datatypes.md @@ -240,7 +240,7 @@ Specifically: #### Examples -{% highlight sql %} +```sql SELECT double('infinity') AS col; +--------+ | col| @@ -313,4 +313,4 @@ SELECT COUNT(*), c2 FROM test GROUP BY c2; | 2|-Infinity| | 3| Infinity| +---------+---------+ -{% endhighlight %} \ No newline at end of file +``` diff --git a/docs/sql-ref-functions-udf-aggregate.md b/docs/sql-ref-functions-udf-aggregate.md index 3fde94d6bc4bf..da3182149410b 100644 --- a/docs/sql-ref-functions-udf-aggregate.md +++ b/docs/sql-ref-functions-udf-aggregate.md @@ -27,46 +27,35 @@ User-Defined Aggregate Functions (UDAFs) are user-programmable routines that act A base class for user-defined aggregations, which can be used in Dataset operations to take all of the elements of a group and reduce them to a single value. - * IN - The input type for the aggregation. - * BUF - The type of the intermediate value of the reduction. - * OUT - The type of the final output result. + ***IN*** - The input type for the aggregation. + + ***BUF*** - The type of the intermediate value of the reduction. + + ***OUT*** - The type of the final output result. + +* **bufferEncoder: Encoder[BUF]** -
-
bufferEncoder: Encoder[BUF]
-
Specifies the Encoder for the intermediate value type. -
-
-
-
finish(reduction: BUF): OUT
-
+ +* **finish(reduction: BUF): OUT** + Transform the output of the reduction. -
-
-
-
merge(b1: BUF, b2: BUF): BUF
-
+ +* **merge(b1: BUF, b2: BUF): BUF** + Merge two intermediate values. -
-
-
-
outputEncoder: Encoder[OUT]
-
+ +* **outputEncoder: Encoder[OUT]** + Specifies the Encoder for the final output value type. -
-
-
-
reduce(b: BUF, a: IN): BUF
-
- Aggregate input value a into current intermediate value. For performance, the function may modify b and return it instead of constructing new object for b. -
-
-
-
zero: BUF
-
+ +* **reduce(b: BUF, a: IN): BUF** + + Aggregate input value `a` into current intermediate value. For performance, the function may modify `b` and return it instead of constructing new object for `b`. + +* **zero: BUF** + The initial value of the intermediate result for this aggregation. -
-
### Examples @@ -95,16 +84,16 @@ For example, a user-defined average for untyped DataFrames can look like: {% include_example untyped_custom_aggregation java/org/apache/spark/examples/sql/JavaUserDefinedUntypedAggregation.java%}
-{% highlight sql %} +```sql -- Compile and place UDAF MyAverage in a JAR file called `MyAverage.jar` in /tmp. CREATE FUNCTION myAverage AS 'MyAverage' USING JAR '/tmp/MyAverage.jar'; SHOW USER FUNCTIONS; --- +------------------+ --- | function| --- +------------------+ --- | default.myAverage| --- +------------------+ ++------------------+ +| function| ++------------------+ +| default.myAverage| ++------------------+ CREATE TEMPORARY VIEW employees USING org.apache.spark.sql.json @@ -113,26 +102,26 @@ OPTIONS ( ); SELECT * FROM employees; --- +-------+------+ --- | name|salary| --- +-------+------+ --- |Michael| 3000| --- | Andy| 4500| --- | Justin| 3500| --- | Berta| 4000| --- +-------+------+ ++-------+------+ +| name|salary| ++-------+------+ +|Michael| 3000| +| Andy| 4500| +| Justin| 3500| +| Berta| 4000| ++-------+------+ SELECT myAverage(salary) as average_salary FROM employees; --- +--------------+ --- |average_salary| --- +--------------+ --- | 3750.0| --- +--------------+ -{% endhighlight %} ++--------------+ +|average_salary| ++--------------+ +| 3750.0| ++--------------+ +```
### Related Statements - * [Scalar User Defined Functions (UDFs)](sql-ref-functions-udf-scalar.html) - * [Integration with Hive UDFs/UDAFs/UDTFs](sql-ref-functions-udf-hive.html) +* [Scalar User Defined Functions (UDFs)](sql-ref-functions-udf-scalar.html) +* [Integration with Hive UDFs/UDAFs/UDTFs](sql-ref-functions-udf-hive.html) diff --git a/docs/sql-ref-functions-udf-hive.md b/docs/sql-ref-functions-udf-hive.md index 7a7129de23836..819c446c411d2 100644 --- a/docs/sql-ref-functions-udf-hive.md +++ b/docs/sql-ref-functions-udf-hive.md @@ -28,7 +28,7 @@ Spark SQL supports integration of Hive UDFs, UDAFs and UDTFs. Similar to Spark U Hive has two UDF interfaces: [UDF](https://github.com/apache/hive/blob/master/udf/src/java/org/apache/hadoop/hive/ql/exec/UDF.java) and [GenericUDF](https://github.com/apache/hive/blob/master/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDF.java). An example below uses [GenericUDFAbs](https://github.com/apache/hive/blob/master/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFAbs.java) derived from `GenericUDF`. -{% highlight sql %} +```sql -- Register `GenericUDFAbs` and use it in Spark SQL. -- Note that, if you use your own programmed one, you need to add a JAR containing it -- into a classpath, @@ -52,12 +52,12 @@ SELECT testUDF(value) FROM t; | 2.0| | 3.0| +--------------+ -{% endhighlight %} +``` An example below uses [GenericUDTFExplode](https://github.com/apache/hive/blob/master/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDTFExplode.java) derived from [GenericUDTF](https://github.com/apache/hive/blob/master/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDF.java). -{% highlight sql %} +```sql -- Register `GenericUDTFExplode` and use it in Spark SQL CREATE TEMPORARY FUNCTION hiveUDTF AS 'org.apache.hadoop.hive.ql.udf.generic.GenericUDTFExplode'; @@ -79,12 +79,12 @@ SELECT hiveUDTF(value) FROM t; | 3| | 4| +---+ -{% endhighlight %} +``` Hive has two UDAF interfaces: [UDAF](https://github.com/apache/hive/blob/master/udf/src/java/org/apache/hadoop/hive/ql/exec/UDAF.java) and [GenericUDAFResolver](https://github.com/apache/hive/blob/master/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDAFResolver.java). An example below uses [GenericUDAFSum](https://github.com/apache/hive/blob/master/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDAFSum.java) derived from `GenericUDAFResolver`. -{% highlight sql %} +```sql -- Register `GenericUDAFSum` and use it in Spark SQL CREATE TEMPORARY FUNCTION hiveUDAF AS 'org.apache.hadoop.hive.ql.udf.generic.GenericUDAFSum'; @@ -105,4 +105,4 @@ SELECT key, hiveUDAF(value) FROM t GROUP BY key; | b| 3| | a| 3| +---+---------------+ -{% endhighlight %} +``` \ No newline at end of file diff --git a/docs/sql-ref-functions-udf-scalar.md b/docs/sql-ref-functions-udf-scalar.md index 2cb25f275cb59..97f5a89d3fb19 100644 --- a/docs/sql-ref-functions-udf-scalar.md +++ b/docs/sql-ref-functions-udf-scalar.md @@ -26,24 +26,18 @@ User-Defined Functions (UDFs) are user-programmable routines that act on one row ### UserDefinedFunction To define the properties of a user-defined function, the user can use some of the methods defined in this class. -
-
asNonNullable(): UserDefinedFunction
-
+ +* **asNonNullable(): UserDefinedFunction** + Updates UserDefinedFunction to non-nullable. -
-
-
-
asNondeterministic(): UserDefinedFunction
-
+ +* **asNondeterministic(): UserDefinedFunction** + Updates UserDefinedFunction to nondeterministic. -
-
-
-
withName(name: String): UserDefinedFunction
-
+ +* **withName(name: String): UserDefinedFunction** + Updates UserDefinedFunction with a given name. -
-
### Examples @@ -57,5 +51,5 @@ To define the properties of a user-defined function, the user can use some of th ### Related Statements - * [User Defined Aggregate Functions (UDAFs)](sql-ref-functions-udf-aggregate.html) - * [Integration with Hive UDFs/UDAFs/UDTFs](sql-ref-functions-udf-hive.html) +* [User Defined Aggregate Functions (UDAFs)](sql-ref-functions-udf-aggregate.html) +* [Integration with Hive UDFs/UDAFs/UDTFs](sql-ref-functions-udf-hive.html) diff --git a/docs/sql-ref-identifier.md b/docs/sql-ref-identifier.md index 89cde21e6fdb6..5b48ece19fb07 100644 --- a/docs/sql-ref-identifier.md +++ b/docs/sql-ref-identifier.md @@ -27,54 +27,47 @@ An identifier is a string used to identify a database object such as a table, vi #### Regular Identifier -{% highlight sql %} +```sql { letter | digit | '_' } [ , ... ] -{% endhighlight %} +``` Note: If `spark.sql.ansi.enabled` is set to true, ANSI SQL reserved keywords cannot be used as identifiers. For more details, please refer to [ANSI Compliance](sql-ref-ansi-compliance.html). #### Delimited Identifier -{% highlight sql %} +```sql `c [ ... ]` -{% endhighlight %} +``` ### Parameters -
-
letter
-
+* **letter** + Any letter from A-Z or a-z. -
-
-
-
digit
-
+ +* **digit** + Any numeral from 0 to 9. -
-
-
-
c
-
+ +* **c** + Any character from the character set. Use ` to escape special characters (e.g., `). -
-
### Examples -{% highlight sql %} +```sql -- This CREATE TABLE fails with ParseException because of the illegal identifier name a.b CREATE TABLE test (a.b int); -org.apache.spark.sql.catalyst.parser.ParseException: -no viable alternative at input 'CREATE TABLE test (a.'(line 1, pos 20) + org.apache.spark.sql.catalyst.parser.ParseException: + no viable alternative at input 'CREATE TABLE test (a.'(line 1, pos 20) -- This CREATE TABLE works CREATE TABLE test (`a.b` int); -- This CREATE TABLE fails with ParseException because special character ` is not escaped CREATE TABLE test1 (`a`b` int); -org.apache.spark.sql.catalyst.parser.ParseException: -no viable alternative at input 'CREATE TABLE test (`a`b`'(line 1, pos 23) + org.apache.spark.sql.catalyst.parser.ParseException: + no viable alternative at input 'CREATE TABLE test (`a`b`'(line 1, pos 23) -- This CREATE TABLE works CREATE TABLE test (`a``b` int); -{% endhighlight %} +``` diff --git a/docs/sql-ref-literals.md b/docs/sql-ref-literals.md index 0088f79cb7007..d203f3503ef87 100644 --- a/docs/sql-ref-literals.md +++ b/docs/sql-ref-literals.md @@ -35,22 +35,19 @@ A string literal is used to specify a character string value. #### Syntax -{% highlight sql %} +```sql 'c [ ... ]' | "c [ ... ]" -{% endhighlight %} +``` -#### Parameters +#### Parameters + +* **c** -
-
c
-
- One character from the character set. Use \ to escape special characters (e.g., ' or \). -
-
+ One character from the character set. Use `\` to escape special characters (e.g., `'` or `\`). -#### Examples +#### Examples -{% highlight sql %} +```sql SELECT 'Hello, World!' AS col; +-------------+ | col| @@ -71,7 +68,7 @@ SELECT 'it\'s $10.' AS col; +---------+ |It's $10.| +---------+ -{% endhighlight %} +``` ### Binary Literal @@ -79,29 +76,26 @@ A binary literal is used to specify a byte sequence value. #### Syntax -{% highlight sql %} +```sql X { 'c [ ... ]' | "c [ ... ]" } -{% endhighlight %} +``` + +#### Parameters -#### Parameters +* **c** -
-
c
-
One character from the character set. -
-
-#### Examples +#### Examples -{% highlight sql %} +```sql SELECT X'123456' AS col; +----------+ | col| +----------+ |[12 34 56]| +----------+ -{% endhighlight %} +``` ### Null Literal @@ -109,20 +103,20 @@ A null literal is used to specify a null value. #### Syntax -{% highlight sql %} +```sql NULL -{% endhighlight %} +``` #### Examples -{% highlight sql %} +```sql SELECT NULL AS col; +----+ | col| +----+ |NULL| +----+ -{% endhighlight %} +``` ### Boolean Literal @@ -130,20 +124,20 @@ A boolean literal is used to specify a boolean value. #### Syntax -{% highlight sql %} +```sql TRUE | FALSE -{% endhighlight %} +``` #### Examples -{% highlight sql %} +```sql SELECT TRUE AS col; +----+ | col| +----+ |true| +----+ -{% endhighlight %} +``` ### Numeric Literal @@ -153,46 +147,35 @@ A numeric literal is used to specify a fixed or floating-point number. #### Syntax -{% highlight sql %} +```sql [ + | - ] digit [ ... ] [ L | S | Y ] -{% endhighlight %} +``` #### Parameters -
-
digit
-
+* **digit** + Any numeral from 0 to 9. -
-
-
-
L
-
- Case insensitive, indicates BIGINT, which is a 8-byte signed integer number. -
-
-
-
S
-
- Case insensitive, indicates SMALLINT, which is a 2-byte signed integer number. -
-
-
-
Y
-
- Case insensitive, indicates TINYINT, which is a 1-byte signed integer number. -
-
-
-
default (no postfix)
-
+ +* **L** + + Case insensitive, indicates `BIGINT`, which is a 8-byte signed integer number. + +* **S** + + Case insensitive, indicates `SMALLINT`, which is a 2-byte signed integer number. + +* **Y** + + Case insensitive, indicates `TINYINT`, which is a 1-byte signed integer number. + +* **default (no postfix)** + Indicates a 4-byte signed integer number. -
-
#### Examples -{% highlight sql %} +```sql SELECT -2147483648 AS col; +-----------+ | col| @@ -220,56 +203,49 @@ SELECT 482S AS col; +---+ |482| +---+ -{% endhighlight %} +``` #### Fractional Literals #### Syntax decimal literals: -{% highlight sql %} +```sql decimal_digits { [ BD ] | [ exponent BD ] } | digit [ ... ] [ exponent ] BD -{% endhighlight %} +``` double literals: -{% highlight sql %} +```sql decimal_digits { D | exponent [ D ] } | digit [ ... ] { exponent [ D ] | [ exponent ] D } -{% endhighlight %} +``` While decimal_digits is defined as -{% highlight sql %} +```sql [ + | - ] { digit [ ... ] . [ digit [ ... ] ] | . digit [ ... ] } -{% endhighlight %} +``` and exponent is defined as -{% highlight sql %} +```sql E [ + | - ] digit [ ... ] -{% endhighlight %} +``` #### Parameters -
-
digit
-
+* **digit** + Any numeral from 0 to 9. -
-
-
-
D
-
- Case insensitive, indicates DOUBLE, which is a 8-byte double-precision floating point number. -
-
-
-
BD
-
- Case insensitive, indicates DECIMAL, with the total number of digits as precision and the number of digits to right of decimal point as scale. -
-
+ +* **D** + + Case insensitive, indicates `DOUBLE`, which is a 8-byte double-precision floating point number. + +* **BD** + + Case insensitive, indicates `DECIMAL`, with the total number of digits as precision and the number of digits to right of decimal point as scale. #### Examples -{% highlight sql %} +```sql SELECT 12.578 AS col; +------+ | col| @@ -353,7 +329,7 @@ SELECT -3.E-3D AS col; +------+ |-0.003| +------+ -{% endhighlight %} +``` ### Datetime Literal @@ -363,17 +339,17 @@ A Datetime literal is used to specify a datetime value. #### Syntax -{% highlight sql %} +```sql DATE { 'yyyy' | 'yyyy-[m]m' | 'yyyy-[m]m-[d]d' | 'yyyy-[m]m-[d]d[T]' } -{% endhighlight %} -Note: defaults to 01 if month or day is not specified. +``` +Note: defaults to `01` if month or day is not specified. #### Examples -{% highlight sql %} +```sql SELECT DATE '1997' AS col; +----------+ | col| @@ -394,13 +370,13 @@ SELECT DATE '2011-11-11' AS col; +----------+ |2011-11-11| +----------+ -{% endhighlight %} +``` #### Timestamp Literal #### Syntax -{% highlight sql %} +```sql TIMESTAMP { 'yyyy' | 'yyyy-[m]m' | 'yyyy-[m]m-[d]d' | @@ -409,27 +385,23 @@ TIMESTAMP { 'yyyy' | 'yyyy-[m]m-[d]d[T][h]h:[m]m[:]' | 'yyyy-[m]m-[d]d[T][h]h:[m]m:[s]s[.]' | 'yyyy-[m]m-[d]d[T][h]h:[m]m:[s]s.[ms][ms][ms][us][us][us][zone_id]'} -{% endhighlight %} -Note: defaults to 00 if hour, minute or second is not specified.

+``` +Note: defaults to `00` if hour, minute or second is not specified. `zone_id` should have one of the forms: - -Note: defaults to the session local timezone (set via spark.sql.session.timeZone) if zone_id is not specified. +* Z - Zulu time zone UTC+0 +* `+|-[h]h:[m]m` +* An id with one of the prefixes UTC+, UTC-, GMT+, GMT-, UT+ or UT-, and a suffix in the formats: + * `+|-h[h]` + * `+|-hh[:]mm` + * `+|-hh:mm:ss` + * `+|-hhmmss` +* Region-based zone IDs in the form `area/city`, such as `Europe/Paris` + +Note: defaults to the session local timezone (set via `spark.sql.session.timeZone`) if `zone_id` is not specified. #### Examples -{% highlight sql %} +```sql SELECT TIMESTAMP '1997-01-31 09:26:56.123' AS col; +-----------------------+ | col| @@ -450,50 +422,40 @@ SELECT TIMESTAMP '1997-01' AS col; +-------------------+ |1997-01-01 00:00:00| +-------------------+ -{% endhighlight %} +``` ### Interval Literal An interval literal is used to specify a fixed period of time. -#### Syntax -{% highlight sql %} -{ INTERVAL interval_value interval_unit [ interval_value interval_unit ... ] | - INTERVAL 'interval_value interval_unit [ interval_value interval_unit ... ]' | - INTERVAL interval_string_value interval_unit TO interval_unit } -{% endhighlight %} +```sql +INTERVAL interval_value interval_unit [ interval_value interval_unit ... ] | +INTERVAL 'interval_value interval_unit [ interval_value interval_unit ... ]' | +INTERVAL interval_string_value interval_unit TO interval_unit +``` #### Parameters -
-
interval_value
-
- Syntax: - - [ + | - ] number_value | '[ + | - ] number_value' -
-
-
-
-
interval_string_value
-
- year-month/day-time interval string. -
-
-
-
interval_unit
-
- Syntax:
- - YEAR[S] | MONTH[S] | WEEK[S] | DAY[S] | HOUR[S] | MINUTE[S] | SECOND[S] |
- MILLISECOND[S] | MICROSECOND[S] -
-
-
+* **interval_value** + + **Syntax:** + + [ + | - ] number_value | '[ + | - ] number_value' + +* **interval_string_value** + + year-month/day-time interval string. + +* **interval_unit** + + **Syntax:** + + YEAR[S] | MONTH[S] | WEEK[S] | DAY[S] | HOUR[S] | MINUTE[S] | SECOND[S] | + MILLISECOND[S] | MICROSECOND[S] #### Examples -{% highlight sql %} +```sql SELECT INTERVAL 3 YEAR AS col; +-------+ | col| @@ -536,4 +498,4 @@ SELECT INTERVAL '20 15:40:32.99899999' DAY TO SECOND AS col; +---------------------------------------------+ |20 days 15 hours 40 minutes 32.998999 seconds| +---------------------------------------------+ -{% endhighlight %} +``` diff --git a/docs/sql-ref-null-semantics.md b/docs/sql-ref-null-semantics.md index 56b5cde630eaf..fb5d2a312d0e1 100644 --- a/docs/sql-ref-null-semantics.md +++ b/docs/sql-ref-null-semantics.md @@ -79,7 +79,7 @@ one or both operands are `NULL`: ### Examples -{% highlight sql %} +```sql -- Normal comparison operators return `NULL` when one of the operand is `NULL`. SELECT 5 > null AS expression_output; +-----------------+ @@ -111,7 +111,7 @@ SELECT NULL <=> NULL; +-----------------+ | true| +-----------------+ -{% endhighlight %} +``` ### Logical Operators @@ -134,7 +134,7 @@ The following tables illustrate the behavior of logical operators when one or bo ### Examples -{% highlight sql %} +```sql -- Normal comparison operators return `NULL` when one of the operands is `NULL`. SELECT (true OR null) AS expression_output; +-----------------+ @@ -158,7 +158,7 @@ SELECT NOT(null) AS expression_output; +-----------------+ | null| +-----------------+ -{% endhighlight %} +``` ### Expressions @@ -177,7 +177,7 @@ expression are `NULL` and most of the expressions fall in this category. ##### Examples -{% highlight sql %} +```sql SELECT concat('John', null) AS expression_output; +-----------------+ |expression_output| @@ -198,7 +198,7 @@ SELECT to_date(null) AS expression_output; +-----------------+ | null| +-----------------+ -{% endhighlight %} +``` #### Expressions That Can Process Null Value Operands @@ -221,7 +221,7 @@ returns the first non `NULL` value in its list of operands. However, `coalesce` ##### Examples -{% highlight sql %} +```sql SELECT isnull(null) AS expression_output; +-----------------+ |expression_output| @@ -251,7 +251,7 @@ SELECT isnan(null) AS expression_output; +-----------------+ | false| +-----------------+ -{% endhighlight %} +``` #### Builtin Aggregate Expressions @@ -271,7 +271,7 @@ the rules of how `NULL` values are handled by aggregate functions. #### Examples -{% highlight sql %} +```sql -- `count(*)` does not skip `NULL` values. SELECT count(*) FROM person; +--------+ @@ -312,7 +312,7 @@ SELECT max(age) FROM person where 1 = 0; +--------+ | null| +--------+ -{% endhighlight %} +``` ### Condition Expressions in WHERE, HAVING and JOIN Clauses @@ -323,7 +323,7 @@ For all the three operators, a condition expression is a boolean expression and #### Examples -{% highlight sql %} +```sql -- Persons whose age is unknown (`NULL`) are filtered out from the result set. SELECT * FROM person WHERE age > 0; +--------+---+ @@ -391,7 +391,7 @@ SELECT * FROM person p1, person p2 | Marry|null| Marry|null| | Joe| 30| Joe| 30| +--------+----+--------+----+ -{% endhighlight %} +``` ### Aggregate Operator (GROUP BY, DISTINCT) @@ -402,7 +402,7 @@ standard and with other enterprise database management systems. #### Examples -{% highlight sql %} +```sql -- `NULL` values are put in one bucket in `GROUP BY` processing. SELECT age, count(*) FROM person GROUP BY age; +----+--------+ @@ -424,7 +424,7 @@ SELECT DISTINCT age FROM person; | 30| | 18| +----+ -{% endhighlight %} +``` ### Sort Operator (ORDER BY Clause) @@ -434,7 +434,7 @@ the `NULL` values are placed at first. #### Examples -{% highlight sql %} +```sql -- `NULL` values are shown at first and other values -- are sorted in ascending way. SELECT age, name FROM person ORDER BY age; @@ -479,7 +479,7 @@ SELECT age, name FROM person ORDER BY age DESC NULLS LAST; |null| Marry| |null| Albert| +----+--------+ -{% endhighlight %} +``` ### Set Operators (UNION, INTERSECT, EXCEPT) @@ -489,7 +489,7 @@ equal unlike the regular `EqualTo`(`=`) operator. #### Examples -{% highlight sql %} +```sql CREATE VIEW unknown_age SELECT * FROM person WHERE age IS NULL; -- Only common rows between two legs of `INTERSECT` are in the @@ -537,7 +537,7 @@ SELECT name, age FROM person | Mike| 18| | Dan| 50| +--------+----+ -{% endhighlight %} +``` ### EXISTS/NOT EXISTS Subquery @@ -554,7 +554,7 @@ semijoins / anti-semijoins without special provisions for null awareness. #### Examples -{% highlight sql %} +```sql -- Even if subquery produces rows with `NULL` values, the `EXISTS` expression -- evaluates to `TRUE` as the subquery produces 1 row. SELECT * FROM person WHERE EXISTS (SELECT null); @@ -591,7 +591,7 @@ SELECT * FROM person WHERE NOT EXISTS (SELECT 1 WHERE 1 = 0); | Marry|null| | Joe| 30| +--------+----+ -{% endhighlight %} +``` ### IN/NOT IN Subquery @@ -617,7 +617,7 @@ and because NOT UNKNOWN is again UNKNOWN. #### Examples -{% highlight sql %} +```sql -- The subquery has only `NULL` value in its result set. Therefore, -- the result of `IN` predicate is UNKNOWN. SELECT * FROM person WHERE age IN (SELECT null); @@ -646,4 +646,4 @@ SELECT * FROM person |name|age| +----+---+ +----+---+ -{% endhighlight %} +``` diff --git a/docs/sql-ref-syntax-aux-analyze-table.md b/docs/sql-ref-syntax-aux-analyze-table.md index f6a6c5f4bc555..a8e11303432ba 100644 --- a/docs/sql-ref-syntax-aux-analyze-table.md +++ b/docs/sql-ref-syntax-aux-analyze-table.md @@ -25,53 +25,39 @@ The `ANALYZE TABLE` statement collects statistics about the table to be used by ### Syntax -{% highlight sql %} +```sql ANALYZE TABLE table_identifier [ partition_spec ] COMPUTE STATISTICS [ NOSCAN | FOR COLUMNS col [ , ... ] | FOR ALL COLUMNS ] -{% endhighlight %} +``` ### Parameters -
-
table_identifier
-
- Specifies a table name, which may be optionally qualified with a database name.

- Syntax: - - [ database_name. ] table_name - -
-
- -
-
partition_spec
-
+* **table_identifier** + + Specifies a table name, which may be optionally qualified with a database name. + + **Syntax:** `[ database_name. ] table_name` + +* **partition_spec** + An optional parameter that specifies a comma separated list of key and value pairs - for partitions. When specified, partition statistics is returned.

- Syntax: - - PARTITION ( partition_col_name [ = partition_col_val ] [ , ... ] ) - -
-
- -
-
[ NOSCAN | FOR COLUMNS col [ , ... ] | FOR ALL COLUMNS ]
-
-
    -
  • If no analyze option is specified, ANALYZE TABLE collects the table's number of rows and size in bytes.
  • -
  • NOSCAN -
    Collect only the table's size in bytes ( which does not require scanning the entire table ).
  • -
  • FOR COLUMNS col [ , ... ] | FOR ALL COLUMNS -
    Collect column statistics for each column specified, or alternatively for every column, as well as table statistics. -
  • -
-
-
+ for partitions. When specified, partition statistics is returned. + + **Syntax:** `PARTITION ( partition_col_name [ = partition_col_val ] [ , ... ] )` + +* **[ NOSCAN `|` FOR COLUMNS col [ , ... ] `|` FOR ALL COLUMNS ]** + + * If no analyze option is specified, `ANALYZE TABLE` collects the table's number of rows and size in bytes. + * **NOSCAN** + + Collects only the table's size in bytes ( which does not require scanning the entire table ). + * **FOR COLUMNS col [ , ... ] `|` FOR ALL COLUMNS** + + Collects column statistics for each column specified, or alternatively for every column, as well as table statistics. ### Examples -{% highlight sql %} +```sql CREATE TABLE students (name STRING, student_id INT) PARTITIONED BY (student_id); INSERT INTO students PARTITION (student_id = 111111) VALUES ('Mark'); INSERT INTO students PARTITION (student_id = 222222) VALUES ('John'); @@ -135,4 +121,4 @@ DESC EXTENDED students name; | max_col_len| 4| | histogram| NULL| +--------------+----------+ -{% endhighlight %} +``` diff --git a/docs/sql-ref-syntax-aux-cache-cache-table.md b/docs/sql-ref-syntax-aux-cache-cache-table.md index 11f682cc10891..193e209d792b3 100644 --- a/docs/sql-ref-syntax-aux-cache-cache-table.md +++ b/docs/sql-ref-syntax-aux-cache-cache-table.md @@ -26,71 +26,57 @@ This reduces scanning of the original files in future queries. ### Syntax -{% highlight sql %} +```sql CACHE [ LAZY ] TABLE table_identifier [ OPTIONS ( 'storageLevel' [ = ] value ) ] [ [ AS ] query ] -{% endhighlight %} +``` ### Parameters -
-
LAZY
-
Only cache the table when it is first used, instead of immediately.
-
- -
-
table_identifier
-
- Specifies the table or view name to be cached. The table or view name may be optionally qualified with a database name.

- Syntax: - - [ database_name. ] table_name - -
-
- -
-
OPTIONS ( 'storageLevel' [ = ] value )
-
- OPTIONS clause with storageLevel key and value pair. A Warning is issued when a key other than storageLevel is used. The valid options for storageLevel are: -
    -
  • NONE
  • -
  • DISK_ONLY
  • -
  • DISK_ONLY_2
  • -
  • MEMORY_ONLY
  • -
  • MEMORY_ONLY_2
  • -
  • MEMORY_ONLY_SER
  • -
  • MEMORY_ONLY_SER_2
  • -
  • MEMORY_AND_DISK
  • -
  • MEMORY_AND_DISK_2
  • -
  • MEMORY_AND_DISK_SER
  • -
  • MEMORY_AND_DISK_SER_2
  • -
  • OFF_HEAP
  • -
- An Exception is thrown when an invalid value is set for storageLevel. If storageLevel is not explicitly set using OPTIONS clause, the default storageLevel is set to MEMORY_AND_DISK. -
-
- -
-
query
-
A query that produces the rows to be cached. It can be in one of following formats: -
    -
  • a SELECT statement
  • -
  • a TABLE statement
  • -
  • a FROM statement
  • -
-
-
+* **LAZY** + + Only cache the table when it is first used, instead of immediately. + +* **table_identifier** + + Specifies the table or view name to be cached. The table or view name may be optionally qualified with a database name. + + **Syntax:** `[ database_name. ] table_name` + +* **OPTIONS ( 'storageLevel' [ = ] value )** + + `OPTIONS` clause with `storageLevel` key and value pair. A Warning is issued when a key other than `storageLevel` is used. The valid options for `storageLevel` are: + * `NONE` + * `DISK_ONLY` + * `DISK_ONLY_2` + * `MEMORY_ONLY` + * `MEMORY_ONLY_2` + * `MEMORY_ONLY_SER` + * `MEMORY_ONLY_SER_2` + * `MEMORY_AND_DISK` + * `MEMORY_AND_DISK_2` + * `MEMORY_AND_DISK_SER` + * `MEMORY_AND_DISK_SER_2` + * `OFF_HEAP` + + An Exception is thrown when an invalid value is set for `storageLevel`. If `storageLevel` is not explicitly set using `OPTIONS` clause, the default `storageLevel` is set to `MEMORY_AND_DISK`. + +* **query** + + A query that produces the rows to be cached. It can be in one of following formats: + * a `SELECT` statement + * a `TABLE` statement + * a `FROM` statement ### Examples -{% highlight sql %} +```sql CACHE TABLE testCache OPTIONS ('storageLevel' 'DISK_ONLY') SELECT * FROM testData; -{% endhighlight %} +``` ### Related Statements - * [CLEAR CACHE](sql-ref-syntax-aux-cache-clear-cache.html) - * [UNCACHE TABLE](sql-ref-syntax-aux-cache-uncache-table.html) - * [REFRESH TABLE](sql-ref-syntax-aux-refresh-table.html) - * [REFRESH](sql-ref-syntax-aux-cache-refresh.html) +* [CLEAR CACHE](sql-ref-syntax-aux-cache-clear-cache.html) +* [UNCACHE TABLE](sql-ref-syntax-aux-cache-uncache-table.html) +* [REFRESH TABLE](sql-ref-syntax-aux-refresh-table.html) +* [REFRESH](sql-ref-syntax-aux-cache-refresh.html) diff --git a/docs/sql-ref-syntax-aux-cache-clear-cache.md b/docs/sql-ref-syntax-aux-cache-clear-cache.md index 47889691148b7..ee33e6a98296d 100644 --- a/docs/sql-ref-syntax-aux-cache-clear-cache.md +++ b/docs/sql-ref-syntax-aux-cache-clear-cache.md @@ -25,19 +25,19 @@ license: | ### Syntax -{% highlight sql %} +```sql CLEAR CACHE -{% endhighlight %} +``` ### Examples -{% highlight sql %} +```sql CLEAR CACHE; -{% endhighlight %} +``` ### Related Statements - * [CACHE TABLE](sql-ref-syntax-aux-cache-cache-table.html) - * [UNCACHE TABLE](sql-ref-syntax-aux-cache-uncache-table.html) - * [REFRESH TABLE](sql-ref-syntax-aux-refresh-table.html) - * [REFRESH](sql-ref-syntax-aux-cache-refresh.html) +* [CACHE TABLE](sql-ref-syntax-aux-cache-cache-table.html) +* [UNCACHE TABLE](sql-ref-syntax-aux-cache-uncache-table.html) +* [REFRESH TABLE](sql-ref-syntax-aux-refresh-table.html) +* [REFRESH](sql-ref-syntax-aux-cache-refresh.html) diff --git a/docs/sql-ref-syntax-aux-cache-refresh.md b/docs/sql-ref-syntax-aux-cache-refresh.md index 25f7ede1d324e..82bc12da5d1ac 100644 --- a/docs/sql-ref-syntax-aux-cache-refresh.md +++ b/docs/sql-ref-syntax-aux-cache-refresh.md @@ -27,32 +27,30 @@ invalidate everything that is cached. ### Syntax -{% highlight sql %} +```sql REFRESH resource_path -{% endhighlight %} +``` ### Parameters -
-
resource_path
-
The path of the resource that is to be refreshed.
-
+* **resource_path** + + The path of the resource that is to be refreshed. ### Examples -{% highlight sql %} +```sql -- The Path is resolved using the datasource's File Index. - CREATE TABLE test(ID INT) using parquet; INSERT INTO test SELECT 1000; CACHE TABLE test; INSERT INTO test SELECT 100; REFRESH "hdfs://path/to/table"; -{% endhighlight %} +``` ### Related Statements - * [CACHE TABLE](sql-ref-syntax-aux-cache-cache-table.html) - * [CLEAR CACHE](sql-ref-syntax-aux-cache-clear-cache.html) - * [UNCACHE TABLE](sql-ref-syntax-aux-cache-uncache-table.html) - * [REFRESH TABLE](sql-ref-syntax-aux-refresh-table.html) +* [CACHE TABLE](sql-ref-syntax-aux-cache-cache-table.html) +* [CLEAR CACHE](sql-ref-syntax-aux-cache-clear-cache.html) +* [UNCACHE TABLE](sql-ref-syntax-aux-cache-uncache-table.html) +* [REFRESH TABLE](sql-ref-syntax-aux-refresh-table.html) diff --git a/docs/sql-ref-syntax-aux-cache-uncache-table.md b/docs/sql-ref-syntax-aux-cache-uncache-table.md index 95fd91c3c4807..c5a8fbbe08281 100644 --- a/docs/sql-ref-syntax-aux-cache-uncache-table.md +++ b/docs/sql-ref-syntax-aux-cache-uncache-table.md @@ -26,32 +26,27 @@ underlying entries should already have been brought to cache by previous `CACHE ### Syntax -{% highlight sql %} +```sql UNCACHE TABLE [ IF EXISTS ] table_identifier -{% endhighlight %} +``` ### Parameters -
-
table_identifier
-
- Specifies the table or view name to be uncached. The table or view name may be optionally qualified with a database name.

- Syntax: - - [ database_name. ] table_name - -
-
+* **table_identifier** + + Specifies the table or view name to be uncached. The table or view name may be optionally qualified with a database name. + + **Syntax:** `[ database_name. ] table_name` ### Examples -{% highlight sql %} +```sql UNCACHE TABLE t1; -{% endhighlight %} +``` ### Related Statements - * [CACHE TABLE](sql-ref-syntax-aux-cache-cache-table.html) - * [CLEAR CACHE](sql-ref-syntax-aux-cache-clear-cache.html) - * [REFRESH TABLE](sql-ref-syntax-aux-refresh-table.html) - * [REFRESH](sql-ref-syntax-aux-cache-refresh.html) +* [CACHE TABLE](sql-ref-syntax-aux-cache-cache-table.html) +* [CLEAR CACHE](sql-ref-syntax-aux-cache-clear-cache.html) +* [REFRESH TABLE](sql-ref-syntax-aux-refresh-table.html) +* [REFRESH](sql-ref-syntax-aux-cache-refresh.html) diff --git a/docs/sql-ref-syntax-aux-conf-mgmt-reset.md b/docs/sql-ref-syntax-aux-conf-mgmt-reset.md index e7e6dda4e25ee..4caf57a232f89 100644 --- a/docs/sql-ref-syntax-aux-conf-mgmt-reset.md +++ b/docs/sql-ref-syntax-aux-conf-mgmt-reset.md @@ -25,17 +25,17 @@ Reset any runtime configurations specific to the current session which were set ### Syntax -{% highlight sql %} +```sql RESET -{% endhighlight %} +``` ### Examples -{% highlight sql %} +```sql -- Reset any runtime configurations specific to the current session which were set via the SET command to their default values. RESET; -{% endhighlight %} +``` ### Related Statements - * [SET](sql-ref-syntax-aux-conf-mgmt-set.html) +* [SET](sql-ref-syntax-aux-conf-mgmt-set.html) diff --git a/docs/sql-ref-syntax-aux-conf-mgmt-set.md b/docs/sql-ref-syntax-aux-conf-mgmt-set.md index 330a1a6a399ff..f97b7f2a8efed 100644 --- a/docs/sql-ref-syntax-aux-conf-mgmt-set.md +++ b/docs/sql-ref-syntax-aux-conf-mgmt-set.md @@ -25,32 +25,29 @@ The SET command sets a property, returns the value of an existing property or re ### Syntax -{% highlight sql %} +```sql SET SET [ -v ] SET property_key[ = property_value ] -{% endhighlight %} +``` ### Parameters -
-
-v
-
Outputs the key, value and meaning of existing SQLConf properties.
-
+* **-v** -
-
property_key
-
Returns the value of specified property key.
-
+ Outputs the key, value and meaning of existing SQLConf properties. -
-
property_key=property_value
-
Sets the value for a given property key. If an old value exists for a given property key, then it gets overridden by the new value.
-
+* **property_key** + + Returns the value of specified property key. + +* **property_key=property_value** + + Sets the value for a given property key. If an old value exists for a given property key, then it gets overridden by the new value. ### Examples -{% highlight sql %} +```sql -- Set a property. SET spark.sql.variable.substitute=false; @@ -67,8 +64,8 @@ SET spark.sql.variable.substitute; +-----------------------------+-----+ |spark.sql.variable.substitute|false| +-----------------------------+-----+ -{% endhighlight %} +``` ### Related Statements - * [RESET](sql-ref-syntax-aux-conf-mgmt-reset.html) +* [RESET](sql-ref-syntax-aux-conf-mgmt-reset.html) diff --git a/docs/sql-ref-syntax-aux-describe-database.md b/docs/sql-ref-syntax-aux-describe-database.md index 39a40ddac800f..143fa78b205ca 100644 --- a/docs/sql-ref-syntax-aux-describe-database.md +++ b/docs/sql-ref-syntax-aux-describe-database.md @@ -28,23 +28,20 @@ interchangeable. ### Syntax -{% highlight sql %} +```sql { DESC | DESCRIBE } DATABASE [ EXTENDED ] db_name -{% endhighlight %} +``` ### Parameters -
-
db_name
-
+* **db_name** + Specifies a name of an existing database or an existing schema in the system. If the name does not exist, an exception is thrown. -
-
### Examples -{% highlight sql %} +```sql -- Create employees DATABASE CREATE DATABASE employees COMMENT 'For software companies'; @@ -89,10 +86,10 @@ DESC DATABASE deployment; | Description| Deployment environment| | Location|file:/Users/Temp/deployment.db| +-------------------------+------------------------------+ -{% endhighlight %} +``` ### Related Statements - * [DESCRIBE FUNCTION](sql-ref-syntax-aux-describe-function.html) - * [DESCRIBE TABLE](sql-ref-syntax-aux-describe-table.html) - * [DESCRIBE QUERY](sql-ref-syntax-aux-describe-query.html) +* [DESCRIBE FUNCTION](sql-ref-syntax-aux-describe-function.html) +* [DESCRIBE TABLE](sql-ref-syntax-aux-describe-table.html) +* [DESCRIBE QUERY](sql-ref-syntax-aux-describe-query.html) diff --git a/docs/sql-ref-syntax-aux-describe-function.md b/docs/sql-ref-syntax-aux-describe-function.md index 76c9efad2fa7d..a871fb5bfd406 100644 --- a/docs/sql-ref-syntax-aux-describe-function.md +++ b/docs/sql-ref-syntax-aux-describe-function.md @@ -28,29 +28,24 @@ metadata information is returned along with the extended usage information. ### Syntax -{% highlight sql %} +```sql { DESC | DESCRIBE } FUNCTION [ EXTENDED ] function_name -{% endhighlight %} +``` ### Parameters -
-
function_name
-
+* **function_name** + Specifies a name of an existing function in the system. The function name may be optionally qualified with a database name. If `function_name` is qualified with a database then the function is resolved from the user specified database, otherwise - it is resolved from the current database.

- Syntax: - - [ database_name. ] function_name - -
-
+ it is resolved from the current database. + + **Syntax:** `[ database_name. ] function_name` ### Examples -{% highlight sql %} +```sql -- Describe a builtin scalar function. -- Returns function name, implementing class and usage DESC FUNCTION abs; @@ -107,11 +102,10 @@ DESC FUNCTION EXTENDED explode | 10 | | 20 | +---------------------------------------------------------------+ - -{% endhighlight %} +``` ### Related Statements - * [DESCRIBE DATABASE](sql-ref-syntax-aux-describe-database.html) - * [DESCRIBE TABLE](sql-ref-syntax-aux-describe-table.html) - * [DESCRIBE QUERY](sql-ref-syntax-aux-describe-query.html) +* [DESCRIBE DATABASE](sql-ref-syntax-aux-describe-database.html) +* [DESCRIBE TABLE](sql-ref-syntax-aux-describe-table.html) +* [DESCRIBE QUERY](sql-ref-syntax-aux-describe-query.html) diff --git a/docs/sql-ref-syntax-aux-describe-query.md b/docs/sql-ref-syntax-aux-describe-query.md index 41e66dcb2e316..b2a74cbd06078 100644 --- a/docs/sql-ref-syntax-aux-describe-query.md +++ b/docs/sql-ref-syntax-aux-describe-query.md @@ -27,38 +27,36 @@ describe the query output. ### Syntax -{% highlight sql %} +```sql { DESC | DESCRIBE } [ QUERY ] input_statement -{% endhighlight %} +``` ### Parameters -
-
QUERY
-
This clause is optional and may be omitted.
-
input_statement
-
+* **QUERY** + This clause is optional and may be omitted. + +* **input_statement** + Specifies a result set producing statement and may be one of the following: -
    -
  • a SELECT statement
  • -
  • a CTE(Common table expression) statement
  • -
  • an INLINE TABLE statement
  • -
  • a TABLE statement
  • -
  • a FROM statement
  • -
- Please refer to select-statement + + * a `SELECT` statement + * a `CTE(Common table expression)` statement + * an `INLINE TABLE` statement + * a `TABLE` statement + * a `FROM` statement` + + Please refer to [select-statement](sql-ref-syntax-qry-select.html) for a detailed syntax of the query parameter. -
-
### Examples -{% highlight sql %} +```sql -- Create table `person` CREATE TABLE person (name STRING , age INT COMMENT 'Age column', address STRING); -- Returns column metadata information for a simple select query -DESCRIBE QUERY select age, sum(age) FROM person GROUP BY age; +DESCRIBE QUERY SELECT age, sum(age) FROM person GROUP BY age; +--------+---------+----------+ |col_name|data_type| comment| +--------+---------+----------+ @@ -103,10 +101,10 @@ DESCRIBE FROM person SELECT age; +--------+---------+----------+ | age| int| Agecolumn| +--------+---------+----------+ -{% endhighlight %} +``` ### Related Statements - * [DESCRIBE DATABASE](sql-ref-syntax-aux-describe-database.html) - * [DESCRIBE TABLE](sql-ref-syntax-aux-describe-table.html) - * [DESCRIBE FUNCTION](sql-ref-syntax-aux-describe-function.html) +* [DESCRIBE DATABASE](sql-ref-syntax-aux-describe-database.html) +* [DESCRIBE TABLE](sql-ref-syntax-aux-describe-table.html) +* [DESCRIBE FUNCTION](sql-ref-syntax-aux-describe-function.html) diff --git a/docs/sql-ref-syntax-aux-describe-table.md b/docs/sql-ref-syntax-aux-describe-table.md index 63bf056d785cc..4b6e1e8c3461e 100644 --- a/docs/sql-ref-syntax-aux-describe-table.md +++ b/docs/sql-ref-syntax-aux-describe-table.md @@ -28,53 +28,43 @@ to return the metadata pertaining to a partition or column respectively. ### Syntax -{% highlight sql %} +```sql { DESC | DESCRIBE } [ TABLE ] [ format ] table_identifier [ partition_spec ] [ col_name ] -{% endhighlight %} +``` ### Parameters -
-
format
-
+* **format** + Specifies the optional format of describe output. If `EXTENDED` is specified then additional metadata information (such as parent database, owner, and access time) is returned. -
-
table_identifier
-
- Specifies a table name, which may be optionally qualified with a database name.

- Syntax: - - [ database_name. ] table_name - -
-
partition_spec
-
+ +* **table_identifier** + + Specifies a table name, which may be optionally qualified with a database name. + + **Syntax:** `[ database_name. ] table_name` + +* **partition_spec** + An optional parameter that specifies a comma separated list of key and value pairs - for partitions. When specified, additional partition metadata is returned.

- Syntax: - - PARTITION ( partition_col_name = partition_col_val [ , ... ] ) - -
-
col_name
-
+ for partitions. When specified, additional partition metadata is returned. + + **Syntax:** `PARTITION ( partition_col_name = partition_col_val [ , ... ] )` + +* **col_name** + An optional parameter that specifies the column name that needs to be described. The supplied column name may be optionally qualified. Parameters `partition_spec` and `col_name` are mutually exclusive and can not be specified together. Currently - nested columns are not allowed to be specified.

+ nested columns are not allowed to be specified. - Syntax: - - [ database_name. ] [ table_name. ] column_name - -
-
+ **Syntax:** `[ database_name. ] [ table_name. ] column_name` ### Examples -{% highlight sql %} +```sql -- Creates a table `customer`. Assumes current database is `salesdb`. CREATE TABLE customer( cust_id INT, @@ -183,10 +173,10 @@ DESCRIBE customer salesdb.customer.name; |data_type| string| | comment|Short name| +---------+----------+ -{% endhighlight %} +``` ### Related Statements - * [DESCRIBE DATABASE](sql-ref-syntax-aux-describe-database.html) - * [DESCRIBE QUERY](sql-ref-syntax-aux-describe-query.html) - * [DESCRIBE FUNCTION](sql-ref-syntax-aux-describe-function.html) +* [DESCRIBE DATABASE](sql-ref-syntax-aux-describe-database.html) +* [DESCRIBE QUERY](sql-ref-syntax-aux-describe-query.html) +* [DESCRIBE FUNCTION](sql-ref-syntax-aux-describe-function.html) diff --git a/docs/sql-ref-syntax-aux-refresh-table.md b/docs/sql-ref-syntax-aux-refresh-table.md index 165ca68309f4a..8d4a804f88671 100644 --- a/docs/sql-ref-syntax-aux-refresh-table.md +++ b/docs/sql-ref-syntax-aux-refresh-table.md @@ -27,26 +27,21 @@ lazy manner when the cached table or the query associated with it is executed ag ### Syntax -{% highlight sql %} +```sql REFRESH [TABLE] table_identifier -{% endhighlight %} +``` ### Parameters -
-
table_identifier
-
- Specifies a table name, which is either a qualified or unqualified name that designates a table/view. If no database identifier is provided, it refers to a temporary view or a table/view in the current database.

- Syntax: - - [ database_name. ] table_name - -
-
+* **table_identifier** + + Specifies a table name, which is either a qualified or unqualified name that designates a table/view. If no database identifier is provided, it refers to a temporary view or a table/view in the current database. + + **Syntax:** `[ database_name. ] table_name` ### Examples -{% highlight sql %} +```sql -- The cached entries of the table will be refreshed -- The table is resolved from the current database as the table name is unqualified. REFRESH TABLE tbl1; @@ -54,11 +49,11 @@ REFRESH TABLE tbl1; -- The cached entries of the view will be refreshed or invalidated -- The view is resolved from tempDB database, as the view name is qualified. REFRESH TABLE tempDB.view1; -{% endhighlight %} +``` ### Related Statements - * [CACHE TABLE](sql-ref-syntax-aux-cache-cache-table.html) - * [CLEAR CACHE](sql-ref-syntax-aux-cache-clear-cache.html) - * [UNCACHE TABLE](sql-ref-syntax-aux-cache-uncache-table.html) - * [REFRESH](sql-ref-syntax-aux-cache-refresh.html) +* [CACHE TABLE](sql-ref-syntax-aux-cache-cache-table.html) +* [CLEAR CACHE](sql-ref-syntax-aux-cache-clear-cache.html) +* [UNCACHE TABLE](sql-ref-syntax-aux-cache-uncache-table.html) +* [REFRESH](sql-ref-syntax-aux-cache-refresh.html) diff --git a/docs/sql-ref-syntax-aux-resource-mgmt-add-file.md b/docs/sql-ref-syntax-aux-resource-mgmt-add-file.md index 0028884308890..9203293d0c981 100644 --- a/docs/sql-ref-syntax-aux-resource-mgmt-add-file.md +++ b/docs/sql-ref-syntax-aux-resource-mgmt-add-file.md @@ -25,30 +25,29 @@ license: | ### Syntax -{% highlight sql %} +```sql ADD FILE resource_name -{% endhighlight %} +``` ### Parameters -
-
resource_name
-
The name of the file or directory to be added.
-
+* **resource_name** + + The name of the file or directory to be added. ### Examples -{% highlight sql %} +```sql ADD FILE /tmp/test; ADD FILE "/path/to/file/abc.txt"; ADD FILE '/another/test.txt'; ADD FILE "/path with space/abc.txt"; ADD FILE "/path/to/some/directory"; -{% endhighlight %} +``` ### Related Statements - * [LIST FILE](sql-ref-syntax-aux-resource-mgmt-list-file.html) - * [LIST JAR](sql-ref-syntax-aux-resource-mgmt-list-jar.html) - * [ADD JAR](sql-ref-syntax-aux-resource-mgmt-add-jar.html) +* [LIST FILE](sql-ref-syntax-aux-resource-mgmt-list-file.html) +* [LIST JAR](sql-ref-syntax-aux-resource-mgmt-list-jar.html) +* [ADD JAR](sql-ref-syntax-aux-resource-mgmt-add-jar.html) diff --git a/docs/sql-ref-syntax-aux-resource-mgmt-add-jar.md b/docs/sql-ref-syntax-aux-resource-mgmt-add-jar.md index c4020347c1be0..264c50a87ea55 100644 --- a/docs/sql-ref-syntax-aux-resource-mgmt-add-jar.md +++ b/docs/sql-ref-syntax-aux-resource-mgmt-add-jar.md @@ -25,28 +25,26 @@ license: | ### Syntax -{% highlight sql %} +```sql ADD JAR file_name -{% endhighlight %} +``` ### Parameters -
-
file_name
-
The name of the JAR file to be added. It could be either on a local file system or a distributed file system.
-
+* **file_name** + The name of the JAR file to be added. It could be either on a local file system or a distributed file system. ### Examples -{% highlight sql %} +```sql ADD JAR /tmp/test.jar; ADD JAR "/path/to/some.jar"; ADD JAR '/some/other.jar'; ADD JAR "/path with space/abc.jar"; -{% endhighlight %} +``` ### Related Statements - * [LIST JAR](sql-ref-syntax-aux-resource-mgmt-list-jar.html) - * [ADD FILE](sql-ref-syntax-aux-resource-mgmt-add-file.html) - * [LIST FILE](sql-ref-syntax-aux-resource-mgmt-list-file.html) +* [LIST JAR](sql-ref-syntax-aux-resource-mgmt-list-jar.html) +* [ADD FILE](sql-ref-syntax-aux-resource-mgmt-add-file.html) +* [LIST FILE](sql-ref-syntax-aux-resource-mgmt-list-file.html) diff --git a/docs/sql-ref-syntax-aux-resource-mgmt-list-file.md b/docs/sql-ref-syntax-aux-resource-mgmt-list-file.md index eec98e1fbffb5..9b9a7df7f612f 100644 --- a/docs/sql-ref-syntax-aux-resource-mgmt-list-file.md +++ b/docs/sql-ref-syntax-aux-resource-mgmt-list-file.md @@ -25,13 +25,13 @@ license: | ### Syntax -{% highlight sql %} +```sql LIST FILE -{% endhighlight %} +``` ### Examples -{% highlight sql %} +```sql ADD FILE /tmp/test; ADD FILE /tmp/test_2; LIST FILE; @@ -42,11 +42,11 @@ file:/private/tmp/test_2 LIST FILE /tmp/test /some/random/file /another/random/file --output file:/private/tmp/test -{% endhighlight %} +``` ### Related Statements - * [ADD FILE](sql-ref-syntax-aux-resource-mgmt-add-file.html) - * [ADD JAR](sql-ref-syntax-aux-resource-mgmt-add-jar.html) - * [LIST JAR](sql-ref-syntax-aux-resource-mgmt-list-jar.html) +* [ADD FILE](sql-ref-syntax-aux-resource-mgmt-add-file.html) +* [ADD JAR](sql-ref-syntax-aux-resource-mgmt-add-jar.html) +* [LIST JAR](sql-ref-syntax-aux-resource-mgmt-list-jar.html) diff --git a/docs/sql-ref-syntax-aux-resource-mgmt-list-jar.md b/docs/sql-ref-syntax-aux-resource-mgmt-list-jar.md index dca4252c90ef2..04aa52c2ad8af 100644 --- a/docs/sql-ref-syntax-aux-resource-mgmt-list-jar.md +++ b/docs/sql-ref-syntax-aux-resource-mgmt-list-jar.md @@ -25,13 +25,13 @@ license: | ### Syntax -{% highlight sql %} +```sql LIST JAR -{% endhighlight %} +``` ### Examples -{% highlight sql %} +```sql ADD JAR /tmp/test.jar; ADD JAR /tmp/test_2.jar; LIST JAR; @@ -42,11 +42,11 @@ spark://192.168.1.112:62859/jars/test_2.jar LIST JAR /tmp/test.jar /some/random.jar /another/random.jar; -- output spark://192.168.1.112:62859/jars/test.jar -{% endhighlight %} +``` ### Related Statements - * [ADD JAR](sql-ref-syntax-aux-resource-mgmt-add-jar.html) - * [ADD FILE](sql-ref-syntax-aux-resource-mgmt-add-file.html) - * [LIST FILE](sql-ref-syntax-aux-resource-mgmt-list-file.html) +* [ADD JAR](sql-ref-syntax-aux-resource-mgmt-add-jar.html) +* [ADD FILE](sql-ref-syntax-aux-resource-mgmt-add-file.html) +* [LIST FILE](sql-ref-syntax-aux-resource-mgmt-list-file.html) diff --git a/docs/sql-ref-syntax-aux-show-columns.md b/docs/sql-ref-syntax-aux-show-columns.md index 7229bba23d2bf..b76db252f1a0f 100644 --- a/docs/sql-ref-syntax-aux-show-columns.md +++ b/docs/sql-ref-syntax-aux-show-columns.md @@ -21,7 +21,7 @@ license: | ### Description -Return the list of columns in a table. If the table does not exist, an exception is thrown. +Returns the list of columns in a table. If the table does not exist, an exception is thrown. ### Syntax diff --git a/docs/sql-ref-syntax-aux-show-create-table.md b/docs/sql-ref-syntax-aux-show-create-table.md index 47a5290f1d022..ae8c10e2d0178 100644 --- a/docs/sql-ref-syntax-aux-show-create-table.md +++ b/docs/sql-ref-syntax-aux-show-create-table.md @@ -25,26 +25,21 @@ license: | ### Syntax -{% highlight sql %} +```sql SHOW CREATE TABLE table_identifier -{% endhighlight %} +``` ### Parameters -
-
table_identifier
-
- Specifies a table or view name, which may be optionally qualified with a database name.

- Syntax: - - [ database_name. ] table_name - -
-
+* **table_identifier** + + Specifies a table or view name, which may be optionally qualified with a database name. + + **Syntax:** `[ database_name. ] table_name` ### Examples -{% highlight sql %} +```sql CREATE TABLE test (c INT) ROW FORMAT DELIMITED FIELDS TERMINATED BY ',' STORED AS TEXTFILE TBLPROPERTIES ('prop1' = 'value1', 'prop2' = 'value2'); @@ -60,9 +55,9 @@ SHOW CREATE TABLE test; 'prop1' = 'value1', 'prop2' = 'value2') +----------------------------------------------------+ -{% endhighlight %} +``` ### Related Statements - * [CREATE TABLE](sql-ref-syntax-ddl-create-table.html) - * [CREATE VIEW](sql-ref-syntax-ddl-create-view.html) +* [CREATE TABLE](sql-ref-syntax-ddl-create-table.html) +* [CREATE VIEW](sql-ref-syntax-ddl-create-view.html) diff --git a/docs/sql-ref-syntax-aux-show-databases.md b/docs/sql-ref-syntax-aux-show-databases.md index c84898aa81459..44c0fbbef3929 100644 --- a/docs/sql-ref-syntax-aux-show-databases.md +++ b/docs/sql-ref-syntax-aux-show-databases.md @@ -21,35 +21,31 @@ license: | ### Description -Lists the databases that match an optionally supplied string pattern. If no +Lists the databases that match an optionally supplied regular expression pattern. If no pattern is supplied then the command lists all the databases in the system. Please note that the usage of `SCHEMAS` and `DATABASES` are interchangeable and mean the same thing. ### Syntax -{% highlight sql %} +```sql SHOW { DATABASES | SCHEMAS } [ LIKE regex_pattern ] -{% endhighlight %} +``` ### Parameters -
-
regex_pattern
-
+* **regex_pattern** + Specifies a regular expression pattern that is used to filter the results of the statement. -
    -
  • Only * and | are allowed as wildcard pattern.
  • -
  • Excluding * and |, the remaining pattern follows the regular expression semantics.
  • -
  • The leading and trailing blanks are trimmed in the input pattern before processing. The pattern match is case-insensitive.
  • -
-
-
+ * Except for `*` and `|` character, the pattern works like a regular expression. + * `*` alone matches 0 or more characters and `|` is used to separate multiple different regular expressions, + any of which can match. + * The leading and trailing blanks are trimmed in the input pattern before processing. The pattern match is case-insensitive. ### Examples -{% highlight sql %} +```sql -- Create database. Assumes a database named `default` already exists in -- the system. CREATE DATABASE payroll_db; @@ -83,10 +79,10 @@ SHOW SCHEMAS; | payments_db| | payroll_db| +------------+ -{% endhighlight %} +``` ### Related Statements - * [DESCRIBE DATABASE](sql-ref-syntax-aux-describe-database.html) - * [CREATE DATABASE](sql-ref-syntax-ddl-create-database.html) - * [ALTER DATABASE](sql-ref-syntax-ddl-alter-database.html) +* [DESCRIBE DATABASE](sql-ref-syntax-aux-describe-database.html) +* [CREATE DATABASE](sql-ref-syntax-ddl-create-database.html) +* [ALTER DATABASE](sql-ref-syntax-ddl-alter-database.html) diff --git a/docs/sql-ref-syntax-aux-show-functions.md b/docs/sql-ref-syntax-aux-show-functions.md index 8a6de402c7f20..2cfca0f34bf77 100644 --- a/docs/sql-ref-syntax-aux-show-functions.md +++ b/docs/sql-ref-syntax-aux-show-functions.md @@ -9,7 +9,6 @@ license: | The ASF licenses this file to You under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at - http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software @@ -29,48 +28,42 @@ clause is optional and supported only for compatibility with other systems. ### Syntax -{% highlight sql %} -SHOW [ function_kind ] FUNCTIONS ( [ LIKE ] function_name | regex_pattern ) -{% endhighlight %} +```sql +SHOW [ function_kind ] FUNCTIONS [ [ LIKE ] { function_name | regex_pattern } ] +``` ### Parameters -
-
function_kind
-
+* **function_kind** + Specifies the name space of the function to be searched upon. The valid name spaces are : -
    -
  • USER - Looks up the function(s) among the user defined functions.
  • -
  • SYSTEM - Looks up the function(s) among the system defined functions.
  • -
  • ALL - Looks up the function(s) among both user and system defined functions.
  • -
-
-
function_name
-
+ + * **USER** - Looks up the function(s) among the user defined functions. + * **SYSTEM** - Looks up the function(s) among the system defined functions. + * **ALL** - Looks up the function(s) among both user and system defined functions. + +* **function_name** + Specifies a name of an existing function in the system. The function name may be optionally qualified with a database name. If `function_name` is qualified with a database then the function is resolved from the user specified database, otherwise - it is resolved from the current database.

- Syntax: - - [database_name.]function_name - -
-
regex_pattern
-
+ it is resolved from the current database. + + **Syntax:** `[database_name.]function_name` + +* **regex_pattern** + Specifies a regular expression pattern that is used to filter the results of the statement. -
    -
  • Only * and | are allowed as wildcard pattern.
  • -
  • Excluding * and |, the remaining pattern follows the regular expression semantics.
  • -
  • The leading and trailing blanks are trimmed in the input pattern before processing. The pattern match is case-insensitive.
  • -
-
-
+ + * Except for `*` and `|` character, the pattern works like a regular expression. + * `*` alone matches 0 or more characters and `|` is used to separate multiple different regular expressions, + any of which can match. + * The leading and trailing blanks are trimmed in the input pattern before processing. The pattern match is case-insensitive. ### Examples -{% highlight sql %} +```sql -- List a system function `trim` by searching both user defined and system -- defined functions. SHOW FUNCTIONS trim; @@ -138,8 +131,8 @@ SHOW FUNCTIONS LIKE 't[a-z][a-z][a-z]'; | tanh| | trim| +--------+ -{% endhighlight %} +``` ### Related Statements - * [DESCRIBE FUNCTION](sql-ref-syntax-aux-describe-function.html) +* [DESCRIBE FUNCTION](sql-ref-syntax-aux-describe-function.html) diff --git a/docs/sql-ref-syntax-aux-show-partitions.md b/docs/sql-ref-syntax-aux-show-partitions.md index 592833b23eb09..f937f8f524342 100644 --- a/docs/sql-ref-syntax-aux-show-partitions.md +++ b/docs/sql-ref-syntax-aux-show-partitions.md @@ -27,37 +27,28 @@ partition spec. ### Syntax -{% highlight sql %} +```sql SHOW PARTITIONS table_identifier [ partition_spec ] -{% endhighlight %} +``` ### Parameters -
-
table_identifier
-
- Specifies a table name, which may be optionally qualified with a database name.

- Syntax: - - [ database_name. ] table_name - -
-
-
-
partition_spec
-
+* **table_identifier** + + Specifies a table name, which may be optionally qualified with a database name. + + **Syntax:** `[ database_name. ] table_name` + +* **partition_spec** + An optional parameter that specifies a comma separated list of key and value pairs - for partitions. When specified, the partitions that match the partition spec are returned.

- Syntax: - - PARTITION ( partition_col_name [ = partition_col_val ] [ , ... ] ) - -
-
+ for partitions. When specified, the partitions that match the partition spec are returned. + + **Syntax:** `PARTITION ( partition_col_name = partition_col_val [ , ... ] )` ### Examples -{% highlight sql %} +```sql -- create a partitioned table and insert a few rows. USE salesdb; CREATE TABLE customer(id INT, name STRING) PARTITIONED BY (state STRING, city STRING); @@ -109,11 +100,11 @@ SHOW PARTITIONS customer PARTITION (city = 'San Jose'); +----------------------+ |state=CA/city=San Jose| +----------------------+ -{% endhighlight %} +``` ### Related Statements - * [CREATE TABLE](sql-ref-syntax-ddl-create-table.html) - * [INSERT STATEMENT](sql-ref-syntax-dml-insert.html) - * [DESCRIBE TABLE](sql-ref-syntax-aux-describe-table.html) - * [SHOW TABLE](sql-ref-syntax-aux-show-table.html) +* [CREATE TABLE](sql-ref-syntax-ddl-create-table.html) +* [INSERT STATEMENT](sql-ref-syntax-dml-insert.html) +* [DESCRIBE TABLE](sql-ref-syntax-aux-describe-table.html) +* [SHOW TABLE](sql-ref-syntax-aux-show-table.html) diff --git a/docs/sql-ref-syntax-aux-show-table.md b/docs/sql-ref-syntax-aux-show-table.md index 3f588045790b2..6be6e7eff79ca 100644 --- a/docs/sql-ref-syntax-aux-show-table.md +++ b/docs/sql-ref-syntax-aux-show-table.md @@ -32,42 +32,36 @@ cannot be used with a partition specification. ### Syntax -{% highlight sql %} -SHOW TABLE EXTENDED [ IN | FROM database_name ] LIKE regex_pattern +```sql +SHOW TABLE EXTENDED [ { IN | FROM } database_name ] LIKE regex_pattern [ partition_spec ] -{% endhighlight %} +``` ### Parameters -
-
IN|FROM database_name
-
+* **{ IN`|`FROM } database_name** + Specifies database name. If not provided, will use the current database. -
-
regex_pattern
-
+ +* **regex_pattern** + Specifies the regular expression pattern that is used to filter out unwanted tables. -
    -
  • Except for * and | character, the pattern works like a regular expression.
  • -
  • * alone matches 0 or more characters and | is used to separate multiple different regular expressions, - any of which can match.
  • -
  • The leading and trailing blanks are trimmed in the input pattern before processing. The pattern match is case-insensitive.
  • -
-
-
partition_spec
-
+ + * Except for `*` and `|` character, the pattern works like a regular expression. + * `*` alone matches 0 or more characters and `|` is used to separate multiple different regular expressions, + any of which can match. + * The leading and trailing blanks are trimmed in the input pattern before processing. The pattern match is case-insensitive. + +* **partition_spec** + An optional parameter that specifies a comma separated list of key and value pairs - for partitions. Note that a table regex cannot be used with a partition specification.

- Syntax: - - PARTITION ( partition_col_name [ = partition_col_val ] [ , ... ] ) - -
-
+ for partitions. Note that a table regex cannot be used with a partition specification. + + **Syntax:** `PARTITION ( partition_col_name = partition_col_val [ , ... ] )` ### Examples -{% highlight sql %} +```sql -- Assumes `employee` table created with partitioned by column `grade` CREATE TABLE employee(name STRING, grade INT) PARTITIONED BY (grade); INSERT INTO employee PARTITION (grade = 1) VALUES ('sam'); @@ -152,7 +146,7 @@ SHOW TABLE EXTENDED LIKE `employe*`; +--------+---------+----------+---------------------------------------------------------------+ -- show partition file system details -SHOW TABLE EXTENDED IN `default` LIKE `employee` PARTITION (`grade=1`); +SHOW TABLE EXTENDED IN default LIKE `employee` PARTITION (`grade=1`); +--------+---------+-----------+--------------------------------------------------------------+ |database|tableName|isTemporary| information | +--------+---------+-----------+--------------------------------------------------------------+ @@ -175,12 +169,12 @@ SHOW TABLE EXTENDED IN `default` LIKE `employee` PARTITION (`grade=1`); +--------+---------+-----------+--------------------------------------------------------------+ -- show partition file system details with regex fails as shown below -SHOW TABLE EXTENDED IN `default` LIKE `empl*` PARTITION (`grade=1`); +SHOW TABLE EXTENDED IN default LIKE `empl*` PARTITION (`grade=1`); Error: Error running query: org.apache.spark.sql.catalyst.analysis.NoSuchTableException: Table or view 'emplo*' not found in database 'default'; (state=,code=0) -{% endhighlight %} +``` ### Related Statements - * [CREATE TABLE](sql-ref-syntax-ddl-create-table.html) - * [DESCRIBE TABLE](sql-ref-syntax-aux-describe-table.html) +* [CREATE TABLE](sql-ref-syntax-ddl-create-table.html) +* [DESCRIBE TABLE](sql-ref-syntax-aux-describe-table.html) diff --git a/docs/sql-ref-syntax-aux-show-tables.md b/docs/sql-ref-syntax-aux-show-tables.md index 62eb3ddb18b5c..fef9722a444f8 100644 --- a/docs/sql-ref-syntax-aux-show-tables.md +++ b/docs/sql-ref-syntax-aux-show-tables.md @@ -28,33 +28,28 @@ current database. ### Syntax -{% highlight sql %} +```sql SHOW TABLES [ { FROM | IN } database_name ] [ LIKE regex_pattern ] -{% endhighlight %} +``` ### Parameters -
-
{ FROM | IN } database_name
-
+* **{ FROM `|` IN } database_name** + Specifies the database name from which tables are listed. -
-
regex_pattern
-
+ +* **regex_pattern** + Specifies the regular expression pattern that is used to filter out unwanted tables. -
    -
  • Except for * and | character, the pattern works like a regular expression.
  • -
  • * alone matches 0 or more characters and | is used to separate multiple different regular expressions, - any of which can match.
  • -
  • The leading and trailing blanks are trimmed in the input pattern before processing. The pattern match is case-insensitive.
  • -
- -
-
+ + * Except for `*` and `|` character, the pattern works like a regular expression. + * `*` alone matches 0 or more characters and `|` is used to separate multiple different regular expressions, + any of which can match. + * The leading and trailing blanks are trimmed in the input pattern before processing. The pattern match is case-insensitive. ### Examples -{% highlight sql %} +```sql -- List all tables in default database SHOW TABLES; +--------+---------+-----------+ @@ -101,11 +96,11 @@ SHOW TABLES LIKE 'sam*|suj'; | default| sam1| false| | default| suj| false| +--------+---------+-----------+ -{% endhighlight %} +``` ### Related Statements - * [CREATE TABLE](sql-ref-syntax-ddl-create-table.html) - * [DROP TABLE](sql-ref-syntax-ddl-drop-table.html) - * [CREATE DATABASE](sql-ref-syntax-ddl-create-database.html) - * [DROP DATABASE](sql-ref-syntax-ddl-drop-database.html) +* [CREATE TABLE](sql-ref-syntax-ddl-create-table.html) +* [DROP TABLE](sql-ref-syntax-ddl-drop-table.html) +* [CREATE DATABASE](sql-ref-syntax-ddl-create-database.html) +* [DROP DATABASE](sql-ref-syntax-ddl-drop-database.html) diff --git a/docs/sql-ref-syntax-aux-show-tblproperties.md b/docs/sql-ref-syntax-aux-show-tblproperties.md index 662aaad069dd9..5b7ddcbcd9534 100644 --- a/docs/sql-ref-syntax-aux-show-tblproperties.md +++ b/docs/sql-ref-syntax-aux-show-tblproperties.md @@ -26,37 +26,30 @@ a property key. If no key is specified then all the properties are returned. ### Syntax -{% highlight sql %} +```sql SHOW TBLPROPERTIES table_identifier [ ( unquoted_property_key | property_key_as_string_literal ) ] -{% endhighlight %} +``` ### Parameters -
-
table_identifier
-
+* **table_identifier** + Specifies the table name of an existing table. The table may be optionally qualified - with a database name.

- Syntax: - - [ database_name. ] table_name - -
-
unquoted_property_key
-
+ with a database name. + + **Syntax:** `[ database_name. ] table_name` + +* **unquoted_property_key** + Specifies the property key in unquoted form. The key may consists of multiple - parts separated by dot.

- Syntax: - - [ key_part1 ] [ .key_part2 ] [ ... ] - -
-
property_key_as_string_literal
-
+ parts separated by dot. + + **Syntax:** `[ key_part1 ] [ .key_part2 ] [ ... ]` + +* **property_key_as_string_literal** + Specifies a property key value as a string literal. -
-
**Note** - Property value returned by this statement excludes some properties @@ -68,7 +61,7 @@ SHOW TBLPROPERTIES table_identifier ### Examples -{% highlight sql %} +```sql -- create a table `customer` in database `salesdb` USE salesdb; CREATE TABLE customer(cust_code INT, name VARCHAR(100), cust_addr STRING) @@ -110,11 +103,11 @@ SHOW TBLPROPERTIES customer ('created.date'); +----------+ |01-01-2001| +----------+ -{% endhighlight %} +``` ### Related Statements - * [CREATE TABLE](sql-ref-syntax-ddl-create-table.html) - * [ALTER TABLE SET TBLPROPERTIES](sql-ref-syntax-ddl-alter-table.html) - * [SHOW TABLES](sql-ref-syntax-aux-show-tables.html) - * [SHOW TABLE EXTENDED](sql-ref-syntax-aux-show-table.html) +* [CREATE TABLE](sql-ref-syntax-ddl-create-table.html) +* [ALTER TABLE SET TBLPROPERTIES](sql-ref-syntax-ddl-alter-table.html) +* [SHOW TABLES](sql-ref-syntax-aux-show-tables.html) +* [SHOW TABLE EXTENDED](sql-ref-syntax-aux-show-table.html) diff --git a/docs/sql-ref-syntax-aux-show-views.md b/docs/sql-ref-syntax-aux-show-views.md index 29ad6caf140f8..5003c092cabce 100644 --- a/docs/sql-ref-syntax-aux-show-views.md +++ b/docs/sql-ref-syntax-aux-show-views.md @@ -29,30 +29,26 @@ list global temporary views. Note that the command also lists local temporary vi regardless of a given database. ### Syntax -{% highlight sql %} +```sql SHOW VIEWS [ { FROM | IN } database_name ] [ LIKE regex_pattern ] -{% endhighlight %} +``` ### Parameters -
-
{ FROM | IN } database_name
-
+* **{ FROM `|` IN } database_name** + Specifies the database name from which views are listed. -
-
regex_pattern
-
+ +* **regex_pattern** + Specifies the regular expression pattern that is used to filter out unwanted views. -
    -
  • Except for * and | character, the pattern works like a regular expression.
  • -
  • * alone matches 0 or more characters and | is used to separate multiple different regular expressions, - any of which can match.
  • -
  • The leading and trailing blanks are trimmed in the input pattern before processing. The pattern match is case-insensitive.
  • -
-
-
+ + * Except for `*` and `|` character, the pattern works like a regular expression. + * `*` alone matches 0 or more characters and `|` is used to separate multiple different regular expressions, + any of which can match. + * The leading and trailing blanks are trimmed in the input pattern before processing. The pattern match is case-insensitive. ### Examples -{% highlight sql %} +```sql -- Create views in different databases, also create global/local temp views. CREATE VIEW sam AS SELECT id, salary FROM employee WHERE name = 'sam'; CREATE VIEW sam1 AS SELECT id, salary FROM employee WHERE name = 'sam1'; @@ -61,8 +57,8 @@ USE userdb; CREATE VIEW user1 AS SELECT id, salary FROM default.employee WHERE name = 'user1'; CREATE VIEW user2 AS SELECT id, salary FROM default.employee WHERE name = 'user2'; USE default; -CREATE GLOBAL TEMP VIEW temp1 AS SELECT 1 as col1; -CREATE TEMP VIEW temp2 AS SELECT 1 as col1; +CREATE GLOBAL TEMP VIEW temp1 AS SELECT 1 AS col1; +CREATE TEMP VIEW temp2 AS SELECT 1 AS col1; -- List all views in default database SHOW VIEWS; @@ -112,11 +108,10 @@ SHOW VIEWS LIKE 'sam|suj|temp*'; | default | suj | false | | | temp2 | true | +-------------+------------+--------------+ - -{% endhighlight %} +``` ### Related statements -- [CREATE VIEW](sql-ref-syntax-ddl-create-view.html) -- [DROP VIEW](sql-ref-syntax-ddl-drop-view.html) -- [CREATE DATABASE](sql-ref-syntax-ddl-create-database.html) -- [DROP DATABASE](sql-ref-syntax-ddl-drop-database.html) +* [CREATE VIEW](sql-ref-syntax-ddl-create-view.html) +* [DROP VIEW](sql-ref-syntax-ddl-drop-view.html) +* [CREATE DATABASE](sql-ref-syntax-ddl-create-database.html) +* [DROP DATABASE](sql-ref-syntax-ddl-drop-database.html) diff --git a/docs/sql-ref-syntax-ddl-alter-database.md b/docs/sql-ref-syntax-ddl-alter-database.md index 2d5860c2ea920..fbc454e25fb0c 100644 --- a/docs/sql-ref-syntax-ddl-alter-database.md +++ b/docs/sql-ref-syntax-ddl-alter-database.md @@ -29,21 +29,20 @@ for a database and may be used for auditing purposes. ### Syntax -{% highlight sql %} +```sql ALTER { DATABASE | SCHEMA } database_name SET DBPROPERTIES ( property_name = property_value [ , ... ] ) -{% endhighlight %} +``` ### Parameters -
-
database_name
-
Specifies the name of the database to be altered.
-
+* **database_name** + + Specifies the name of the database to be altered. ### Examples -{% highlight sql %} +```sql -- Creates a database named `inventory`. CREATE DATABASE inventory; @@ -60,8 +59,8 @@ DESCRIBE DATABASE EXTENDED inventory; | Location| file:/temp/spark-warehouse/inventory.db| | Properties|((Edit-date,01/01/2001), (Edited-by,John))| +-------------------------+------------------------------------------+ -{% endhighlight %} +``` ### Related Statements - * [DESCRIBE DATABASE](sql-ref-syntax-aux-describe-database.html) +* [DESCRIBE DATABASE](sql-ref-syntax-aux-describe-database.html) diff --git a/docs/sql-ref-syntax-ddl-alter-table.md b/docs/sql-ref-syntax-ddl-alter-table.md index f81585fef3aae..dc3f52344c43a 100644 --- a/docs/sql-ref-syntax-ddl-alter-table.md +++ b/docs/sql-ref-syntax-ddl-alter-table.md @@ -29,35 +29,25 @@ license: | #### Syntax -{% highlight sql %} +```sql ALTER TABLE table_identifier RENAME TO table_identifier ALTER TABLE table_identifier partition_spec RENAME TO partition_spec -{% endhighlight %} +``` #### Parameters -
-
table_identifier
-
- Specifies a table name, which may be optionally qualified with a database name.

- Syntax: - - [ database_name. ] table_name - -
-
- -
-
partition_spec
-
- Partition to be renamed.

- Syntax: - - PARTITION ( partition_col_name = partition_col_val [ , ... ] ) - -
-
+* **table_identifier** + + Specifies a table name, which may be optionally qualified with a database name. + + **Syntax:** `[ database_name. ] table_name` + +* **partition_spec** + + Partition to be renamed. + + **Syntax:** `PARTITION ( partition_col_name = partition_col_val [ , ... ] )` ### ADD COLUMNS @@ -65,27 +55,23 @@ ALTER TABLE table_identifier partition_spec RENAME TO partition_spec #### Syntax -{% highlight sql %} +```sql ALTER TABLE table_identifier ADD COLUMNS ( col_spec [ , ... ] ) -{% endhighlight %} +``` #### Parameters -
-
table_identifier
-
- Specifies a table name, which may be optionally qualified with a database name.

- Syntax: - - [ database_name. ] table_name - -
-
- -
-
COLUMNS ( col_spec )
-
Specifies the columns to be added.
-
+* **table_identifier** + + Specifies a table name, which may be optionally qualified with a database name. + + **Syntax:** `[ database_name. ] table_name` + +* **COLUMNS ( col_spec )** + + Specifies the columns to be added. + + **Syntax:** `PARTITION ( partition_col_name = partition_col_val [ , ... ] )` ### ALTER OR CHANGE COLUMN @@ -93,38 +79,29 @@ ALTER TABLE table_identifier ADD COLUMNS ( col_spec [ , ... ] ) #### Syntax -{% highlight sql %} +```sql ALTER TABLE table_identifier { ALTER | CHANGE } [ COLUMN ] col_spec alterColumnAction -{% endhighlight %} +``` #### Parameters -
-
table_identifier
-
- Specifies a table name, which may be optionally qualified with a database name.

- Syntax: - - [ database_name. ] table_name - -
-
- -
-
COLUMN col_spec
-
Specifies the column to be altered or be changed.
-
- -
-
alterColumnAction
-
- Change the comment string.

- Syntax: - - COMMENT STRING - -
-
+* **table_identifier** + + Specifies a table name, which may be optionally qualified with a database name. + + **Syntax:** `[ database_name. ] table_name` + +* **COLUMNS ( col_spec )** + + Specifies the columns to be added. + + **Syntax:** `PARTITION ( partition_col_name = partition_col_val [ , ... ] )` + +* **alterColumnAction** + + Change the comment string. + + **Syntax:** `COMMENT STRING` ### ADD AND DROP PARTITION @@ -134,34 +111,24 @@ ALTER TABLE table_identifier { ALTER | CHANGE } [ COLUMN ] col_spec alterColumnA ##### Syntax -{% highlight sql %} +```sql ALTER TABLE table_identifier ADD [IF NOT EXISTS] ( partition_spec [ partition_spec ... ] ) -{% endhighlight %} +``` ##### Parameters -
-
table_identifier
-
- Specifies a table name, which may be optionally qualified with a database name.

- Syntax: - - [ database_name. ] table_name - -
-
- -
-
partition_spec
-
- Partition to be added.

- Syntax: - - PARTITION ( partition_col_name = partition_col_val [ , ... ] ) - -
-
+* **table_identifier** + + Specifies a table name, which may be optionally qualified with a database name. + + **Syntax:** `[ database_name. ] table_name` + +* **partition_spec** + + Partition to be added.. + + **Syntax:** `PARTITION ( partition_col_name = partition_col_val [ , ... ] )` #### DROP PARTITION @@ -169,33 +136,23 @@ ALTER TABLE table_identifier ADD [IF NOT EXISTS] ##### Syntax -{% highlight sql %} +```sql ALTER TABLE table_identifier DROP [ IF EXISTS ] partition_spec [PURGE] -{% endhighlight %} +``` ##### Parameters -
-
table_identifier
-
- Specifies a table name, which may be optionally qualified with a database name.

- Syntax: - - [ database_name. ] table_name - -
-
- -
-
partition_spec
-
- Partition to be dropped.

- Syntax: - - PARTITION ( partition_col_name = partition_col_val [ , ... ] ) - -
-
+* **table_identifier** + + Specifies a table name, which may be optionally qualified with a database name. + + **Syntax:** `[ database_name. ] table_name` + +* **partition_spec** + + Partition to be dropped. + + **Syntax:** `PARTITION ( partition_col_name = partition_col_val [ , ... ] )` ### SET AND UNSET @@ -208,30 +165,28 @@ this overrides the old value with the new one. ##### Syntax -{% highlight sql %} +```sql -- Set Table Properties ALTER TABLE table_identifier SET TBLPROPERTIES ( key1 = val1, key2 = val2, ... ) -- Unset Table Properties ALTER TABLE table_identifier UNSET TBLPROPERTIES [ IF EXISTS ] ( key1, key2, ... ) -{% endhighlight %} +``` #### SET SERDE -`ALTER TABLE SET` command is used for setting the SERDE or SERDE properties in Hive tables. If a particular property was already set, -this overrides the old value with the new one. +`ALTER TABLE SET` command is used for setting the SERDE or SERDE properties in Hive tables. If a particular property was already set, this overrides the old value with the new one. ##### Syntax -{% highlight sql %} +```sql -- Set SERDE Properties ALTER TABLE table_identifier [ partition_spec ] SET SERDEPROPERTIES ( key1 = val1, key2 = val2, ... ) ALTER TABLE table_identifier [ partition_spec ] SET SERDE serde_class_name [ WITH SERDEPROPERTIES ( key1 = val1, key2 = val2, ... ) ] - -{% endhighlight %} +``` #### SET LOCATION And SET FILE FORMAT @@ -240,46 +195,34 @@ existing tables. ##### Syntax -{% highlight sql %} +```sql -- Changing File Format ALTER TABLE table_identifier [ partition_spec ] SET FILEFORMAT file_format -- Changing File Location ALTER TABLE table_identifier [ partition_spec ] SET LOCATION 'new_location' -{% endhighlight %} +``` #### Parameters -
-
table_identifier
-
- Specifies a table name, which may be optionally qualified with a database name.

- Syntax: - - [ database_name. ] table_name - -
-
- -
-
partition_spec
-
- Specifies the partition on which the property has to be set.

- Syntax: - - PARTITION ( partition_col_name = partition_col_val [ , ... ] ) - -
-
- -
-
SERDEPROPERTIES ( key1 = val1, key2 = val2, ... )
-
Specifies the SERDE properties to be set.
-
+* **table_identifier** + + Specifies a table name, which may be optionally qualified with a database name. + **Syntax:** `[ database_name. ] table_name` + +* **partition_spec** + + Specifies the partition on which the property has to be set. + + **Syntax:** `PARTITION ( partition_col_name = partition_col_val [ , ... ] )` + +* **SERDEPROPERTIES ( key1 = val1, key2 = val2, ... )** + + Specifies the SERDE properties to be set. ### Examples -{% highlight sql %} +```sql -- RENAME table DESC student; +-----------------------+---------+-------+ @@ -481,9 +424,9 @@ ALTER TABLE dbx.tab1 SET TBLPROPERTIES ('winner' = 'loser') -- DROP TABLE PROPERTIES ALTER TABLE dbx.tab1 UNSET TBLPROPERTIES ('winner') -{% endhighlight %} +``` ### Related Statements - * [CREATE TABLE](sql-ref-syntax-ddl-create-table.html) - * [DROP TABLE](sql-ref-syntax-ddl-drop-table.html) +* [CREATE TABLE](sql-ref-syntax-ddl-create-table.html) +* [DROP TABLE](sql-ref-syntax-ddl-drop-table.html) diff --git a/docs/sql-ref-syntax-ddl-alter-view.md b/docs/sql-ref-syntax-ddl-alter-view.md index c2887692949ea..a34e77decf593 100644 --- a/docs/sql-ref-syntax-ddl-alter-view.md +++ b/docs/sql-ref-syntax-ddl-alter-view.md @@ -29,21 +29,16 @@ Renames the existing view. If the new view name already exists in the source dat does not support moving the views across databases. #### Syntax -{% highlight sql %} +```sql ALTER VIEW view_identifier RENAME TO view_identifier -{% endhighlight %} +``` #### Parameters -
-
view_identifier
-
- Specifies a view name, which may be optionally qualified with a database name.

- Syntax: - - [ database_name. ] view_name - -
-
+* **view_identifier** + + Specifies a view name, which may be optionally qualified with a database name. + + **Syntax:** `[ database_name. ] view_name` #### SET View Properties Set one or more properties of an existing view. The properties are the key value pairs. If the properties' keys exist, @@ -51,89 +46,70 @@ the values are replaced with the new values. If the properties' keys do not exis the properties. #### Syntax -{% highlight sql %} +```sql ALTER VIEW view_identifier SET TBLPROPERTIES ( property_key = property_val [ , ... ] ) -{% endhighlight %} +``` #### Parameters -
-
view_identifier
-
- Specifies a view name, which may be optionally qualified with a database name.

- Syntax: - - [ database_name. ] view_name - -
-
property_key
-
- Specifies the property key. The key may consists of multiple parts separated by dot.

- Syntax: - - [ key_part1 ] [ .key_part2 ] [ ... ] - -
-
+* **view_identifier** + + Specifies a view name, which may be optionally qualified with a database name. + + **Syntax:** `[ database_name. ] view_name` + +* **property_key** + + Specifies the property key. The key may consists of multiple parts separated by dot. + + **Syntax:** `[ key_part1 ] [ .key_part2 ] [ ... ]` #### UNSET View Properties Drop one or more properties of an existing view. If the specified keys do not exist, an exception is thrown. Use `IF EXISTS` to avoid the exception. #### Syntax -{% highlight sql %} +```sql ALTER VIEW view_identifier UNSET TBLPROPERTIES [ IF EXISTS ] ( property_key [ , ... ] ) -{% endhighlight %} +``` #### Parameters -
-
view_identifier
-
- Specifies a view name, which may be optionally qualified with a database name.

- Syntax: - - [ database_name. ] view_name - -
-
property_key
-
- Specifies the property key. The key may consists of multiple parts separated by dot.

- Syntax: - - [ key_part1 ] [ .key_part2 ] [ ... ] - -
-
+* **view_identifier** + + Specifies a view name, which may be optionally qualified with a database name. + + **Syntax:** `[ database_name. ] view_name` + +* **property_key** + + Specifies the property key. The key may consists of multiple parts separated by dot. + + **Syntax:** `[ key_part1 ] [ .key_part2 ] [ ... ]` #### ALTER View AS SELECT `ALTER VIEW view_identifier AS SELECT` statement changes the definition of a view. The `SELECT` statement must be valid, and the `view_identifier` must exist. #### Syntax -{% highlight sql %} +```sql ALTER VIEW view_identifier AS select_statement -{% endhighlight %} +``` Note that `ALTER VIEW` statement does not support `SET SERDE` or `SET SERDEPROPERTIES` properties. #### Parameters -
-
view_identifier
-
- Specifies a view name, which may be optionally qualified with a database name.

- Syntax: - - [ database_name. ] view_name - -
-
select_statement
-
- Specifies the definition of the view. Check select_statement for details. -
-
+* **view_identifier** + + Specifies a view name, which may be optionally qualified with a database name. + + **Syntax:** `[ database_name. ] view_name` + +* **select_statement** + + Specifies the definition of the view. Check [select_statement](sql-ref-syntax-qry-select.html) for details. ### Examples -{% highlight sql %} +```sql -- Rename only changes the view name. -- The source and target databases of the view have to be the same. -- Use qualified or unqualified name for the source and target view. @@ -218,11 +194,11 @@ DESC TABLE EXTENDED tempdb1.v2; | View Text| select * from tempdb1.v1| | | View Original Text| select * from tempdb1.v1| | +----------------------------+---------------------------+-------+ -{% endhighlight %} +``` ### Related Statements - * [describe-table](sql-ref-syntax-aux-describe-table.html) - * [create-view](sql-ref-syntax-ddl-create-view.html) - * [drop-view](sql-ref-syntax-ddl-drop-view.html) - * [show-views](sql-ref-syntax-aux-show-views.html) +* [describe-table](sql-ref-syntax-aux-describe-table.html) +* [create-view](sql-ref-syntax-ddl-create-view.html) +* [drop-view](sql-ref-syntax-ddl-drop-view.html) +* [show-views](sql-ref-syntax-aux-show-views.html) diff --git a/docs/sql-ref-syntax-ddl-create-database.md b/docs/sql-ref-syntax-ddl-create-database.md index 0ef0dfbdaed2b..8c0951253bf37 100644 --- a/docs/sql-ref-syntax-ddl-create-database.md +++ b/docs/sql-ref-syntax-ddl-create-database.md @@ -25,35 +25,38 @@ Creates a database with the specified name. If database with the same name alrea ### Syntax -{% highlight sql %} +```sql CREATE { DATABASE | SCHEMA } [ IF NOT EXISTS ] database_name [ COMMENT database_comment ] [ LOCATION database_directory ] [ WITH DBPROPERTIES ( property_name = property_value [ , ... ] ) ] -{% endhighlight %} +``` ### Parameters -
-
database_name
-
Specifies the name of the database to be created.
+* **database_name** -
IF NOT EXISTS
-
Creates a database with the given name if it doesn't exists. If a database with the same name already exists, nothing will happen.
+ Specifies the name of the database to be created. -
database_directory
-
Path of the file system in which the specified database is to be created. If the specified path does not exist in the underlying file system, this command creates a directory with the path. If the location is not specified, the database will be created in the default warehouse directory, whose path is configured by the static configuration spark.sql.warehouse.dir.
+* **IF NOT EXISTS** -
database_comment
-
Specifies the description for the database.
+ Creates a database with the given name if it doesn't exists. If a database with the same name already exists, nothing will happen. -
WITH DBPROPERTIES ( property_name=property_value [ , ... ] )
-
Specifies the properties for the database in key-value pairs.
-
+* **database_directory** + + Path of the file system in which the specified database is to be created. If the specified path does not exist in the underlying file system, this command creates a directory with the path. If the location is not specified, the database will be created in the default warehouse directory, whose path is configured by the static configuration spark.sql.warehouse.dir. + +* **database_comment** + + Specifies the description for the database. + +* **WITH DBPROPERTIES ( property_name=property_value [ , ... ] )** + + Specifies the properties for the database in key-value pairs. ### Examples -{% highlight sql %} +```sql -- Create database `customer_db`. This throws exception if database with name customer_db -- already exists. CREATE DATABASE customer_db; @@ -76,9 +79,9 @@ DESCRIBE DATABASE EXTENDED customer_db; | Location| hdfs://hacluster/user| | Properties| ((ID,001), (Name,John))| +-------------------------+--------------------------+ -{% endhighlight %} +``` ### Related Statements - * [DESCRIBE DATABASE](sql-ref-syntax-aux-describe-database.html) - * [DROP DATABASE](sql-ref-syntax-ddl-drop-database.html) +* [DESCRIBE DATABASE](sql-ref-syntax-aux-describe-database.html) +* [DROP DATABASE](sql-ref-syntax-ddl-drop-database.html) diff --git a/docs/sql-ref-syntax-ddl-create-function.md b/docs/sql-ref-syntax-ddl-create-function.md index e3f21f70f7c18..e66df5352b1b5 100644 --- a/docs/sql-ref-syntax-ddl-create-function.md +++ b/docs/sql-ref-syntax-ddl-create-function.md @@ -33,68 +33,57 @@ aggregate functions using Scala, Python and Java APIs. Please refer to ### Syntax -{% highlight sql %} +```sql CREATE [ OR REPLACE ] [ TEMPORARY ] FUNCTION [ IF NOT EXISTS ] function_name AS class_name [ resource_locations ] -{% endhighlight %} +``` ### Parameters -
-
OR REPLACE
-
+* **OR REPLACE** + If specified, the resources for the function are reloaded. This is mainly useful to pick up any changes made to the implementation of the function. This - parameter is mutually exclusive to IF NOT EXISTS and can not + parameter is mutually exclusive to `IF NOT EXISTS` and can not be specified together. -
-
TEMPORARY
-
- Indicates the scope of function being created. When TEMPORARY is specified, the + +* **TEMPORARY** + + Indicates the scope of function being created. When `TEMPORARY` is specified, the created function is valid and visible in the current session. No persistent entry is made in the catalog for these kind of functions. -
-
IF NOT EXISTS
-
- If specified, creates the function only when it does not exist. The creation - of function succeeds (no error is thrown) if the specified function already - exists in the system. This parameter is mutually exclusive to OR REPLACE - and can not be specified together. -
-
function_name
-
+ +* **IF NOT EXISTS** + Specifies a name of function to be created. The function name may be - optionally qualified with a database name.

- Syntax: - - [ database_name. ] function_name - -
-
class_name
-
+ optionally qualified with a database name. + +* **function_name** + + Specifies a name of function to be created. The function name may be optionally qualified with a database name. + + **Syntax:** `[ database_name. ] function_name` + +* **class_name** + Specifies the name of the class that provides the implementation for function to be created. The implementing class should extend one of the base classes as follows: -
    -
  • Should extend UDF or UDAF in org.apache.hadoop.hive.ql.exec package.
  • -
  • Should extend AbstractGenericUDAFResolver, GenericUDF, or - GenericUDTF in org.apache.hadoop.hive.ql.udf.generic package.
  • -
  • Should extend UserDefinedAggregateFunction in org.apache.spark.sql.expressions package.
  • -
-
-
resource_locations
-
+ + * Should extend `UDF` or `UDAF` in `org.apache.hadoop.hive.ql.exec` package. + * Should extend `AbstractGenericUDAFResolver`, `GenericUDF`, or + `GenericUDTF` in `org.apache.hadoop.hive.ql.udf.generic` package. + * Should extend `UserDefinedAggregateFunction` in `org.apache.spark.sql.expressions` package. + +* **resource_locations** + Specifies the list of resources that contain the implementation of the function - along with its dependencies.

- Syntax: - - USING { { (JAR | FILE ) resource_uri } , ... } - -
-
+ along with its dependencies. + + **Syntax:** `USING { { (JAR | FILE ) resource_uri } , ... }` ### Examples -{% highlight sql %} +```sql -- 1. Create a simple UDF `SimpleUdf` that increments the supplied integral value by 10. -- import org.apache.hadoop.hive.ql.exec.UDF; -- public class SimpleUdf extends UDF { @@ -166,10 +155,10 @@ SELECT simple_udf(c1) AS function_return_value FROM t1; | 21| | 22| +---------------------+ -{% endhighlight %} +``` ### Related Statements - * [SHOW FUNCTIONS](sql-ref-syntax-aux-show-functions.html) - * [DESCRIBE FUNCTION](sql-ref-syntax-aux-describe-function.html) - * [DROP FUNCTION](sql-ref-syntax-ddl-drop-function.html) +* [SHOW FUNCTIONS](sql-ref-syntax-aux-show-functions.html) +* [DESCRIBE FUNCTION](sql-ref-syntax-aux-describe-function.html) +* [DROP FUNCTION](sql-ref-syntax-ddl-drop-function.html) diff --git a/docs/sql-ref-syntax-ddl-create-table-datasource.md b/docs/sql-ref-syntax-ddl-create-table-datasource.md index 54827fd63568d..b592116c2a9e4 100644 --- a/docs/sql-ref-syntax-ddl-create-table-datasource.md +++ b/docs/sql-ref-syntax-ddl-create-table-datasource.md @@ -25,7 +25,7 @@ The `CREATE TABLE` statement defines a new table using a Data Source. ### Syntax -{% highlight sql %} +```sql CREATE TABLE [ IF NOT EXISTS ] table_identifier [ ( col_name1 col_type1 [ COMMENT col_comment1 ], ... ) ] [ USING data_source ] @@ -38,62 +38,52 @@ CREATE TABLE [ IF NOT EXISTS ] table_identifier [ COMMENT table_comment ] [ TBLPROPERTIES ( key1=val1, key2=val2, ... ) ] [ AS select_statement ] -{% endhighlight %} +``` Note that, the clauses between the USING clause and the AS SELECT clause can come in as any order. For example, you can write COMMENT table_comment after TBLPROPERTIES. ### Parameters -
-
table_identifier
-
- Specifies a table name, which may be optionally qualified with a database name.

- Syntax: - - [ database_name. ] table_name - -
-
-
-
USING data_source
-
Data Source is the input format used to create the table. Data source can be CSV, TXT, ORC, JDBC, PARQUET, etc.
-
- -
-
PARTITIONED BY
-
Partitions are created on the table, based on the columns specified.
-
- -
-
CLUSTERED BY
-
- Partitions created on the table will be bucketed into fixed buckets based on the column specified for bucketing.

- NOTE:Bucketing is an optimization technique that uses buckets (and bucketing columns) to determine data partitioning and avoid data shuffle.
-
SORTED BY
-
Determines the order in which the data is stored in buckets. Default is Ascending order.
- -
- -
-
LOCATION
-
Path to the directory where table data is stored, which could be a path on distributed storage like HDFS, etc.
-
- -
-
COMMENT
-
A string literal to describe the table.
-
- -
-
TBLPROPERTIES
-
A list of key-value pairs that is used to tag the table definition.
-
- -
-
AS select_statement
-
The table is populated using the data from the select statement.
-
+* **table_identifier** + + Specifies a table name, which may be optionally qualified with a database name. + + **Syntax:** `[ database_name. ] table_name` + +* **USING data_source** + + Data Source is the input format used to create the table. Data source can be CSV, TXT, ORC, JDBC, PARQUET, etc. + +* **PARTITIONED BY** + + Partitions are created on the table, based on the columns specified. + +* **CLUSTERED BY** + + Partitions created on the table will be bucketed into fixed buckets based on the column specified for bucketing. + + **NOTE:** Bucketing is an optimization technique that uses buckets (and bucketing columns) to determine data partitioning and avoid data shuffle. + +* **SORTED BY** + + Determines the order in which the data is stored in buckets. Default is Ascending order. + +* **LOCATION** + + Path to the directory where table data is stored, which could be a path on distributed storage like HDFS, etc. + +* **COMMENT** + + A string literal to describe the table. + +* **TBLPROPERTIES** + + A list of key-value pairs that is used to tag the table definition. + +* **AS select_statement** + + The table is populated using the data from the select statement. ### Data Source Interaction @@ -110,7 +100,7 @@ input query, to make sure the table gets created contains exactly the same data ### Examples -{% highlight sql %} +```sql --Use data source CREATE TABLE student (id INT, name STRING, age INT) USING CSV; @@ -137,9 +127,9 @@ CREATE TABLE student (id INT, name STRING, age INT) USING CSV PARTITIONED BY (age) CLUSTERED BY (Id) INTO 4 buckets; -{% endhighlight %} +``` ### Related Statements - * [CREATE TABLE USING HIVE FORMAT](sql-ref-syntax-ddl-create-table-hiveformat.html) - * [CREATE TABLE LIKE](sql-ref-syntax-ddl-create-table-like.html) +* [CREATE TABLE USING HIVE FORMAT](sql-ref-syntax-ddl-create-table-hiveformat.html) +* [CREATE TABLE LIKE](sql-ref-syntax-ddl-create-table-like.html) diff --git a/docs/sql-ref-syntax-ddl-create-table-hiveformat.md b/docs/sql-ref-syntax-ddl-create-table-hiveformat.md index 06f353ad2f103..576d9190f2716 100644 --- a/docs/sql-ref-syntax-ddl-create-table-hiveformat.md +++ b/docs/sql-ref-syntax-ddl-create-table-hiveformat.md @@ -25,7 +25,7 @@ The `CREATE TABLE` statement defines a new table using Hive format. ### Syntax -{% highlight sql %} +```sql CREATE [ EXTERNAL ] TABLE [ IF NOT EXISTS ] table_identifier [ ( col_name1[:] col_type1 [ COMMENT col_comment1 ], ... ) ] [ COMMENT table_comment ] @@ -36,67 +36,54 @@ CREATE [ EXTERNAL ] TABLE [ IF NOT EXISTS ] table_identifier [ LOCATION path ] [ TBLPROPERTIES ( key1=val1, key2=val2, ... ) ] [ AS select_statement ] -{% endhighlight %} +``` Note that, the clauses between the columns definition clause and the AS SELECT clause can come in as any order. For example, you can write COMMENT table_comment after TBLPROPERTIES. ### Parameters -
-
table_identifier
-
- Specifies a table name, which may be optionally qualified with a database name.

- Syntax: - - [ database_name. ] table_name - -
-
- -
-
EXTERNAL
-
Table is defined using the path provided as LOCATION, does not use default location for this table.
-
- -
-
PARTITIONED BY
-
Partitions are created on the table, based on the columns specified.
-
- -
-
ROW FORMAT
-
SERDE is used to specify a custom SerDe or the DELIMITED clause in order to use the native SerDe.
-
- -
-
STORED AS
-
File format for table storage, could be TEXTFILE, ORC, PARQUET,etc.
-
- -
-
LOCATION
-
Path to the directory where table data is stored, Path to the directory where table data is stored, which could be a path on distributed storage like HDFS, etc.
-
- -
-
COMMENT
-
A string literal to describe the table.
-
- -
-
TBLPROPERTIES
-
A list of key-value pairs that is used to tag the table definition.
-
- -
-
AS select_statement
-
The table is populated using the data from the select statement.
-
+* **table_identifier** + + Specifies a table name, which may be optionally qualified with a database name. + + **Syntax:** `[ database_name. ] table_name` + +* **EXTERNAL** + + Table is defined using the path provided as LOCATION, does not use default location for this table. + +* **PARTITIONED BY** + + Partitions are created on the table, based on the columns specified. + +* **ROW FORMAT** + + SERDE is used to specify a custom SerDe or the DELIMITED clause in order to use the native SerDe. + +* **STORED AS** + + File format for table storage, could be TEXTFILE, ORC, PARQUET,etc. + +* **LOCATION** + + Path to the directory where table data is stored, Path to the directory where table data is stored, which could be a path on distributed storage like HDFS, etc. + +* **COMMENT** + + A string literal to describe the table. + +* **TBLPROPERTIES** + + A list of key-value pairs that is used to tag the table definition. + +* **AS select_statement** + + The table is populated using the data from the select statement. ### Examples -{% highlight sql %} +```sql --Use hive format CREATE TABLE student (id INT, name STRING, age INT) STORED AS ORC; @@ -130,9 +117,9 @@ CREATE TABLE student (id INT, name STRING) CREATE TABLE student (id INT,name STRING) ROW FORMAT DELIMITED FIELDS TERMINATED BY ',' STORED AS TEXTFILE; -{% endhighlight %} +``` ### Related Statements - * [CREATE TABLE USING DATASOURCE](sql-ref-syntax-ddl-create-table-datasource.html) - * [CREATE TABLE LIKE](sql-ref-syntax-ddl-create-table-like.html) +* [CREATE TABLE USING DATASOURCE](sql-ref-syntax-ddl-create-table-datasource.html) +* [CREATE TABLE LIKE](sql-ref-syntax-ddl-create-table-like.html) diff --git a/docs/sql-ref-syntax-ddl-create-table-like.md b/docs/sql-ref-syntax-ddl-create-table-like.md index fe1dc4b1ef258..a374c554bd179 100644 --- a/docs/sql-ref-syntax-ddl-create-table-like.md +++ b/docs/sql-ref-syntax-ddl-create-table-like.md @@ -25,57 +25,46 @@ The `CREATE TABLE` statement defines a new table using the definition/metadata o ### Syntax -{% highlight sql %} +```sql CREATE TABLE [IF NOT EXISTS] table_identifier LIKE source_table_identifier USING data_source [ ROW FORMAT row_format ] [ STORED AS file_format ] [ TBLPROPERTIES ( key1=val1, key2=val2, ... ) ] [ LOCATION path ] -{% endhighlight %} +``` ### Parameters -
-
table_identifier
-
- Specifies a table name, which may be optionally qualified with a database name.

- Syntax: [ TBLPROPERTIES ( key1=val1, key2=val2, ... ) ] - - [ database_name. ] table_name - -
-
- -
-
USING data_source
-
Data Source is the input format used to create the table. Data source can be CSV, TXT, ORC, JDBC, PARQUET, etc.
-
- -
-
ROW FORMAT
-
SERDE is used to specify a custom SerDe or the DELIMITED clause in order to use the native SerDe.
-
- -
-
STORED AS
-
File format for table storage, could be TEXTFILE, ORC, PARQUET,etc.
-
- -
-
TBLPROPERTIES
-
Table properties that have to be set are specified, such as `created.by.user`, `owner`, etc. -
-
- -
-
LOCATION
-
Path to the directory where table data is stored,Path to the directory where table data is stored, which could be a path on distributed storage like HDFS, etc. Location to create an external table.
-
+* **table_identifier** + + Specifies a table name, which may be optionally qualified with a database name. + + **Syntax:** `[ database_name. ] table_name` + +* **USING data_source** + + Data Source is the input format used to create the table. Data source can be CSV, TXT, ORC, JDBC, PARQUET, etc. + +* **ROW FORMAT** + + SERDE is used to specify a custom SerDe or the DELIMITED clause in order to use the native SerDe. + +* **STORED AS** + + File format for table storage, could be TEXTFILE, ORC, PARQUET,etc. + +* **TBLPROPERTIES** + + Table properties that have to be set are specified, such as `created.by.user`, `owner`, etc. + +* **LOCATION** + + Path to the directory where table data is stored,Path to the directory where table data is stored, which could be a path on distributed storage like HDFS, etc. Location to create an external table. ### Examples -{% highlight sql %} +```sql -- Create table using an existing table CREATE TABLE Student_Dupli like Student; @@ -90,10 +79,10 @@ CREATE TABLE Student_Dupli like Student ROW FORMAT DELIMITED FIELDS TERMINATED BY ',' STORED AS TEXTFILE TBLPROPERTIES ('owner'='xxxx'); -{% endhighlight %} +``` ### Related Statements - * [CREATE TABLE USING DATASOURCE](sql-ref-syntax-ddl-create-table-datasource.html) - * [CREATE TABLE USING HIVE FORMAT](sql-ref-syntax-ddl-create-table-hiveformat.html) +* [CREATE TABLE USING DATASOURCE](sql-ref-syntax-ddl-create-table-datasource.html) +* [CREATE TABLE USING HIVE FORMAT](sql-ref-syntax-ddl-create-table-hiveformat.html) diff --git a/docs/sql-ref-syntax-ddl-create-table.md b/docs/sql-ref-syntax-ddl-create-table.md index b0388adbc9a38..85dc2020e6585 100644 --- a/docs/sql-ref-syntax-ddl-create-table.md +++ b/docs/sql-ref-syntax-ddl-create-table.md @@ -25,11 +25,11 @@ license: | The CREATE statements: - * [CREATE TABLE USING DATA_SOURCE](sql-ref-syntax-ddl-create-table-datasource.html) - * [CREATE TABLE USING HIVE FORMAT](sql-ref-syntax-ddl-create-table-hiveformat.html) - * [CREATE TABLE LIKE](sql-ref-syntax-ddl-create-table-like.html) +* [CREATE TABLE USING DATA_SOURCE](sql-ref-syntax-ddl-create-table-datasource.html) +* [CREATE TABLE USING HIVE FORMAT](sql-ref-syntax-ddl-create-table-hiveformat.html) +* [CREATE TABLE LIKE](sql-ref-syntax-ddl-create-table-like.html) ### Related Statements - * [ALTER TABLE](sql-ref-syntax-ddl-alter-table.html) - * [DROP TABLE](sql-ref-syntax-ddl-drop-table.html) +* [ALTER TABLE](sql-ref-syntax-ddl-alter-table.html) +* [DROP TABLE](sql-ref-syntax-ddl-drop-table.html) diff --git a/docs/sql-ref-syntax-ddl-create-view.md b/docs/sql-ref-syntax-ddl-create-view.md index ba8c1df1223a3..032bcbcf19ad3 100644 --- a/docs/sql-ref-syntax-ddl-create-view.md +++ b/docs/sql-ref-syntax-ddl-create-view.md @@ -27,55 +27,47 @@ a virtual table that has no physical data therefore other operations like ### Syntax -{% highlight sql %} +```sql CREATE [ OR REPLACE ] [ [ GLOBAL ] TEMPORARY ] VIEW [ IF NOT EXISTS ] view_identifier create_view_clauses AS query -{% endhighlight %} +``` ### Parameters -
-
OR REPLACE
-
If a view of same name already exists, it will be replaced.
-
-
-
[ GLOBAL ] TEMPORARY
-
TEMPORARY views are session-scoped and will be dropped when session ends - because it skips persisting the definition in the underlying metastore, if any. - GLOBAL TEMPORARY views are tied to a system preserved temporary database global_temp.
-
-
-
IF NOT EXISTS
-
Creates a view if it does not exists.
-
-
-
view_identifier
-
- Specifies a view name, which may be optionally qualified with a database name.

- Syntax: - - [ database_name. ] view_name - -
-
-
-
create_view_clauses
-
These clauses are optional and order insensitive. It can be of following formats. -
    -
  • [ ( column_name [ COMMENT column_comment ], ... ) ] to specify column-level comments.
  • -
  • [ COMMENT view_comment ] to specify view-level comments.
  • -
  • [ TBLPROPERTIES ( property_name = property_value [ , ... ] ) ] to add metadata key-value pairs.
  • -
-
-
-
-
query
-
A SELECT statement that constructs the view from base tables or other views.
-
+* **OR REPLACE** + + If a view of same name already exists, it will be replaced. + +* **[ GLOBAL ] TEMPORARY** + + TEMPORARY views are session-scoped and will be dropped when session ends + because it skips persisting the definition in the underlying metastore, if any. + GLOBAL TEMPORARY views are tied to a system preserved temporary database `global_temp`. + +* **IF NOT EXISTS** + + Creates a view if it does not exists. + +* **view_identifier** + + Specifies a view name, which may be optionally qualified with a database name. + + **Syntax:** `[ database_name. ] view_name` + +* **create_view_clauses** + + These clauses are optional and order insensitive. It can be of following formats. + + * `[ ( column_name [ COMMENT column_comment ], ... ) ]` to specify column-level comments. + * `[ COMMENT view_comment ]` to specify view-level comments. + * `[ TBLPROPERTIES ( property_name = property_value [ , ... ] ) ]` to add metadata key-value pairs. + +* **query** + A [SELECT](sql-ref-syntax-qry-select.html) statement that constructs the view from base tables or other views. ### Examples -{% highlight sql %} +```sql -- Create or replace view for `experienced_employee` with comments. CREATE OR REPLACE VIEW experienced_employee (ID COMMENT 'Unique identification number', Name) @@ -88,10 +80,10 @@ CREATE GLOBAL TEMPORARY VIEW IF NOT EXISTS subscribed_movies AS SELECT mo.member_id, mb.full_name, mo.movie_title FROM movies AS mo INNER JOIN members AS mb ON mo.member_id = mb.id; -{% endhighlight %} +``` ### Related Statements - * [ALTER VIEW](sql-ref-syntax-ddl-alter-view.html) - * [DROP VIEW](sql-ref-syntax-ddl-drop-view.html) - * [SHOW VIEWS](sql-ref-syntax-aux-show-views.html) +* [ALTER VIEW](sql-ref-syntax-ddl-alter-view.html) +* [DROP VIEW](sql-ref-syntax-ddl-drop-view.html) +* [SHOW VIEWS](sql-ref-syntax-aux-show-views.html) diff --git a/docs/sql-ref-syntax-ddl-drop-database.md b/docs/sql-ref-syntax-ddl-drop-database.md index 7467e7a4ad6e7..4a3bc0c68b6d4 100644 --- a/docs/sql-ref-syntax-ddl-drop-database.md +++ b/docs/sql-ref-syntax-ddl-drop-database.md @@ -26,35 +26,31 @@ exception will be thrown if the database does not exist in the system. ### Syntax -{% highlight sql %} +```sql DROP { DATABASE | SCHEMA } [ IF EXISTS ] dbname [ RESTRICT | CASCADE ] -{% endhighlight %} +``` ### Parameters -
-
DATABASE | SCHEMA
-
DATABASE and SCHEMA mean the same thing, either of them can be used.
-
+* **DATABASE `|` SCHEMA** -
-
IF EXISTS
-
If specified, no exception is thrown when the database does not exist.
-
+ `DATABASE` and `SCHEMA` mean the same thing, either of them can be used. -
-
RESTRICT
-
If specified, will restrict dropping a non-empty database and is enabled by default.
-
+* **IF EXISTS** -
-
CASCADE
-
If specified, will drop all the associated tables and functions.
-
+ If specified, no exception is thrown when the database does not exist. + +* **RESTRICT** + + If specified, will restrict dropping a non-empty database and is enabled by default. + +* **CASCADE** + + If specified, will drop all the associated tables and functions. ### Examples -{% highlight sql %} +```sql -- Create `inventory_db` Database CREATE DATABASE inventory_db COMMENT 'This database is used to maintain Inventory'; @@ -63,10 +59,10 @@ DROP DATABASE inventory_db CASCADE; -- Drop the database using IF EXISTS DROP DATABASE IF EXISTS inventory_db CASCADE; -{% endhighlight %} +``` ### Related Statements - * [CREATE DATABASE](sql-ref-syntax-ddl-create-database.html) - * [DESCRIBE DATABASE](sql-ref-syntax-aux-describe-database.html) - * [SHOW DATABASES](sql-ref-syntax-aux-show-databases.html) +* [CREATE DATABASE](sql-ref-syntax-ddl-create-database.html) +* [DESCRIBE DATABASE](sql-ref-syntax-aux-describe-database.html) +* [SHOW DATABASES](sql-ref-syntax-aux-show-databases.html) diff --git a/docs/sql-ref-syntax-ddl-drop-function.md b/docs/sql-ref-syntax-ddl-drop-function.md index 66a405c24e413..b1b2ff9b1bb21 100644 --- a/docs/sql-ref-syntax-ddl-drop-function.md +++ b/docs/sql-ref-syntax-ddl-drop-function.md @@ -26,39 +26,32 @@ be thrown if the function does not exist. ### Syntax -{% highlight sql %} +```sql DROP [ TEMPORARY ] FUNCTION [ IF EXISTS ] function_name -{% endhighlight %} +``` ### Parameters -
-
function_name
-
+* **function_name** + Specifies the name of an existing function. The function name may be - optionally qualified with a database name.

- Syntax: - - [ database_name. ] function_name - -
-
- -
-
TEMPORARY
-
Should be used to delete the TEMPORARY function.
-
- -
-
IF EXISTS
-
If specified, no exception is thrown when the function does not exist.
-
+ optionally qualified with a database name. + + **Syntax:** `[ database_name. ] function_name` + +* **TEMPORARY** + + Should be used to delete the `TEMPORARY` function. + +* **IF EXISTS** + + If specified, no exception is thrown when the function does not exist. ### Examples -{% highlight sql %} +```sql -- Create a permanent function `test_avg` -CREATE FUNCTION test_avg as 'org.apache.hadoop.hive.ql.udf.generic.GenericUDAFAverage'; +CREATE FUNCTION test_avg AS 'org.apache.hadoop.hive.ql.udf.generic.GenericUDAFAverage'; -- List user functions SHOW USER FUNCTIONS; @@ -100,10 +93,10 @@ SHOW USER FUNCTIONS; -- Drop Temporary function DROP TEMPORARY FUNCTION IF EXISTS test_avg; -{% endhighlight %} +``` ### Related Statements - * [CREATE FUNCTION](sql-ref-syntax-ddl-create-function.html) - * [DESCRIBE FUNCTION](sql-ref-syntax-aux-describe-function.html) - * [SHOW FUNCTION](sql-ref-syntax-aux-show-functions.html) +* [CREATE FUNCTION](sql-ref-syntax-ddl-create-function.html) +* [DESCRIBE FUNCTION](sql-ref-syntax-aux-describe-function.html) +* [SHOW FUNCTION](sql-ref-syntax-aux-show-functions.html) diff --git a/docs/sql-ref-syntax-ddl-drop-table.md b/docs/sql-ref-syntax-ddl-drop-table.md index c943b922ae812..f2ff89993f2c3 100644 --- a/docs/sql-ref-syntax-ddl-drop-table.md +++ b/docs/sql-ref-syntax-ddl-drop-table.md @@ -28,30 +28,25 @@ In case of an external table, only the associated metadata information is remove ### Syntax -{% highlight sql %} +```sql DROP TABLE [ IF EXISTS ] table_identifier -{% endhighlight %} +``` ### Parameter -
-
IF EXISTS
-
- If specified, no exception is thrown when the table does not exists. -
-
table_identifier
-
- Specifies the table name to be dropped. The table name may be optionally qualified with a database name.

- Syntax: - - [ database_name. ] table_name - -
-
+* **IF EXISTS** + + If specified, no exception is thrown when the table does not exists. + +* **table_identifier** + + Specifies the table name to be dropped. The table name may be optionally qualified with a database name. + + **Syntax:** `[ database_name. ] table_name` ### Examples -{% highlight sql %} +```sql -- Assumes a table named `employeetable` exists. DROP TABLE employeetable; @@ -67,10 +62,10 @@ DROP TABLE employeetable; -- Assumes a table named `employeetable` does not exists,Try with IF EXISTS -- this time it will not throw exception DROP TABLE IF EXISTS employeetable; -{% endhighlight %} +``` ### Related Statements - * [CREATE TABLE](sql-ref-syntax-ddl-create-table.html) - * [CREATE DATABASE](sql-ref-syntax-ddl-create-database.html) - * [DROP DATABASE](sql-ref-syntax-ddl-drop-database.html) +* [CREATE TABLE](sql-ref-syntax-ddl-create-table.html) +* [CREATE DATABASE](sql-ref-syntax-ddl-create-database.html) +* [DROP DATABASE](sql-ref-syntax-ddl-drop-database.html) diff --git a/docs/sql-ref-syntax-ddl-drop-view.md b/docs/sql-ref-syntax-ddl-drop-view.md index ad018b5e6fd5c..0f4a7ca6c9463 100644 --- a/docs/sql-ref-syntax-ddl-drop-view.md +++ b/docs/sql-ref-syntax-ddl-drop-view.md @@ -25,30 +25,25 @@ license: | ### Syntax -{% highlight sql %} +```sql DROP VIEW [ IF EXISTS ] view_identifier -{% endhighlight %} +``` ### Parameter -
-
IF EXISTS
-
- If specified, no exception is thrown when the view does not exists. -
-
view_identifier
-
- Specifies the view name to be dropped. The view name may be optionally qualified with a database name.

- Syntax: - - [ database_name. ] view_name - -
-
+* **IF EXISTS** + + If specified, no exception is thrown when the view does not exists. + +* **view_identifier** + + Specifies the view name to be dropped. The view name may be optionally qualified with a database name. + + **Syntax:** `[ database_name. ] view_name` ### Examples -{% highlight sql %} +```sql -- Assumes a view named `employeeView` exists. DROP VIEW employeeView; @@ -64,12 +59,12 @@ DROP VIEW employeeView; -- Assumes a view named `employeeView` does not exists,Try with IF EXISTS -- this time it will not throw exception DROP VIEW IF EXISTS employeeView; -{% endhighlight %} +``` ### Related Statements - * [CREATE VIEW](sql-ref-syntax-ddl-create-view.html) - * [ALTER VIEW](sql-ref-syntax-ddl-alter-view.html) - * [SHOW VIEWS](sql-ref-syntax-aux-show-views.html) - * [CREATE DATABASE](sql-ref-syntax-ddl-create-database.html) - * [DROP DATABASE](sql-ref-syntax-ddl-drop-database.html) +* [CREATE VIEW](sql-ref-syntax-ddl-create-view.html) +* [ALTER VIEW](sql-ref-syntax-ddl-alter-view.html) +* [SHOW VIEWS](sql-ref-syntax-aux-show-views.html) +* [CREATE DATABASE](sql-ref-syntax-ddl-create-database.html) +* [DROP DATABASE](sql-ref-syntax-ddl-drop-database.html) diff --git a/docs/sql-ref-syntax-ddl-repair-table.md b/docs/sql-ref-syntax-ddl-repair-table.md index c48b731512ad3..c2ef0a7b7fbe9 100644 --- a/docs/sql-ref-syntax-ddl-repair-table.md +++ b/docs/sql-ref-syntax-ddl-repair-table.md @@ -25,26 +25,21 @@ license: | ### Syntax -{% highlight sql %} +```sql MSCK REPAIR TABLE table_identifier -{% endhighlight %} +``` ### Parameters -
-
table_identifier
-
- Specifies the name of the table to be repaired. The table name may be optionally qualified with a database name.

- Syntax: - - [ database_name. ] table_name - -
-
+* **table_identifier** + + Specifies the name of the table to be repaired. The table name may be optionally qualified with a database name. + + **Syntax:** `[ database_name. ] table_name` ### Examples -{% highlight sql %} +```sql -- create a partitioned table from existing data /tmp/namesAndAges.parquet CREATE TABLE t1 (name STRING, age INT) USING parquet PARTITIONED BY (age) LOCATION "/tmp/namesAndAges.parquet"; @@ -66,8 +61,8 @@ SELECT * FROM t1; +-------+---+ | Andy| 30| +-------+---+ -{% endhighlight %} +``` ### Related Statements - * [ALTER TABLE](sql-ref-syntax-ddl-alter-table.html) +* [ALTER TABLE](sql-ref-syntax-ddl-alter-table.html) diff --git a/docs/sql-ref-syntax-ddl-truncate-table.md b/docs/sql-ref-syntax-ddl-truncate-table.md index 820f439f97a4b..6139814a3259a 100644 --- a/docs/sql-ref-syntax-ddl-truncate-table.md +++ b/docs/sql-ref-syntax-ddl-truncate-table.md @@ -27,37 +27,28 @@ in `partition_spec`. If no `partition_spec` is specified it will remove all part ### Syntax -{% highlight sql %} +```sql TRUNCATE TABLE table_identifier [ partition_spec ] -{% endhighlight %} +``` ### Parameters -
-
table_identifier
-
- Specifies a table name, which may be optionally qualified with a database name.

- Syntax: - - [ database_name. ] table_name - -
-
-
-
partition_spec
-
+* **table_identifier** + + Specifies a table name, which may be optionally qualified with a database name. + + **Syntax:** `[ database_name. ] table_name` + +* **partition_spec** + An optional parameter that specifies a comma separated list of key and value pairs - for partitions.

- Syntax: - - PARTITION ( partition_col_name = partition_col_val [ , ... ] ) - -
-
+ for partitions. + + **Syntax:** `PARTITION ( partition_col_name = partition_col_val [ , ... ] )` ### Examples -{% highlight sql %} +```sql -- Create table Student with partition CREATE TABLE Student (name STRING, rollno INT) PARTITIONED BY (age INT); @@ -89,9 +80,9 @@ SELECT * FROM Student; |name|rollno|age| +----+------+---+ +----+------+---+ -{% endhighlight %} +``` ### Related Statements - * [DROP TABLE](sql-ref-syntax-ddl-drop-table.html) - * [ALTER TABLE](sql-ref-syntax-ddl-alter-table.html) +* [DROP TABLE](sql-ref-syntax-ddl-drop-table.html) +* [ALTER TABLE](sql-ref-syntax-ddl-alter-table.html) diff --git a/docs/sql-ref-syntax-dml-insert-into.md b/docs/sql-ref-syntax-dml-insert-into.md index 924831f7feedd..ed5da2b2d28df 100644 --- a/docs/sql-ref-syntax-dml-insert-into.md +++ b/docs/sql-ref-syntax-dml-insert-into.md @@ -25,57 +25,43 @@ The `INSERT INTO` statement inserts new rows into a table. The inserted rows can ### Syntax -{% highlight sql %} +```sql INSERT INTO [ TABLE ] table_identifier [ partition_spec ] { VALUES ( { value | NULL } [ , ... ] ) [ , ( ... ) ] | query } -{% endhighlight %} +``` ### Parameters -
-
table_identifier
-
- Specifies a table name, which may be optionally qualified with a database name.

- Syntax: - - [ database_name. ] table_name - -
-
- -
-
partition_spec
-
+* **table_identifier** + + Specifies a table name, which may be optionally qualified with a database name. + + **Syntax:** `[ database_name. ] table_name` + +* **partition_spec** + An optional parameter that specifies a comma separated list of key and value pairs - for partitions.

- Syntax: - - PARTITION ( partition_col_name = partition_col_val [ , ... ] ) - -
-
- -
-
VALUES ( { value | NULL } [ , ... ] ) [ , ( ... ) ]
-
Specifies the values to be inserted. Either an explicitly specified value or a NULL can be inserted. A comma must be used to separate each value in the clause. More than one set of values can be specified to insert multiple rows.
-
- -
-
query
-
A query that produces the rows to be inserted. It can be in one of following formats: -
    -
  • a SELECT statement
  • -
  • a TABLE statement
  • -
  • a FROM statement
  • -
-
-
+ for partitions. + + **Syntax:** `PARTITION ( partition_col_name = partition_col_val [ , ... ] )` + +* **VALUES ( { value `|` NULL } [ , ... ] ) [ , ( ... ) ]** + + Specifies the values to be inserted. Either an explicitly specified value or a NULL can be inserted. + A comma must be used to separate each value in the clause. More than one set of values can be specified to insert multiple rows. + +* **query** + + A query that produces the rows to be inserted. It can be in one of following formats: + * a `SELECT` statement + * a `TABLE` statement + * a `FROM` statement ### Examples #### Single Row Insert Using a VALUES Clause -{% highlight sql %} +```sql CREATE TABLE students (name VARCHAR(64), address VARCHAR(64), student_id INT) USING PARQUET PARTITIONED BY (student_id); @@ -88,11 +74,11 @@ SELECT * FROM students; +---------+---------------------+----------+ |Amy Smith|123 Park Ave,San Jose| 111111| +---------+---------------------+----------+ -{% endhighlight %} +``` #### Multi-Row Insert Using a VALUES Clause -{% highlight sql %} +```sql INSERT INTO students VALUES ('Bob Brown', '456 Taylor St, Cupertino', 222222), ('Cathy Johnson', '789 Race Ave, Palo Alto', 333333); @@ -107,11 +93,11 @@ SELECT * FROM students; +-------------+------------------------+----------+ |Cathy Johnson| 789 Race Ave, Palo Alto| 333333| +--------------+-----------------------+----------+ -{% endhighlight %} +``` #### Insert Using a SELECT Statement -{% highlight sql %} +```sql -- Assuming the persons table has already been created and populated. SELECT * FROM persons; +-------------+-------------------------+---------+ @@ -137,11 +123,11 @@ SELECT * FROM students; +-------------+-------------------------+----------+ |Dora Williams|134 Forest Ave, Melo Park| 444444| +-------------+-------------------------+----------+ -{% endhighlight %} +``` #### Insert Using a TABLE Statement -{% highlight sql %} +```sql -- Assuming the visiting_students table has already been created and populated. SELECT * FROM visiting_students; +-------------+---------------------+----------+ @@ -170,11 +156,11 @@ SELECT * FROM students; +-------------+-------------------------+----------+ |Gordon Martin| 779 Lake Ave, Oxford| 888888| +-------------+-------------------------+----------+ -{% endhighlight %} +``` #### Insert Using a FROM Statement -{% highlight sql %} +```sql -- Assuming the applicants table has already been created and populated. SELECT * FROM applicants; +-----------+--------------------------+----------+---------+ @@ -210,10 +196,10 @@ SELECT * FROM students; +-------------+-------------------------+----------+ | Jason Wang| 908 Bird St, Saratoga| 121212| +-------------+-------------------------+----------+ -{% endhighlight %} +``` ### Related Statements - * [INSERT OVERWRITE statement](sql-ref-syntax-dml-insert-overwrite-table.html) - * [INSERT OVERWRITE DIRECTORY statement](sql-ref-syntax-dml-insert-overwrite-directory.html) - * [INSERT OVERWRITE DIRECTORY with Hive format statement](sql-ref-syntax-dml-insert-overwrite-directory-hive.html) +* [INSERT OVERWRITE statement](sql-ref-syntax-dml-insert-overwrite-table.html) +* [INSERT OVERWRITE DIRECTORY statement](sql-ref-syntax-dml-insert-overwrite-directory.html) +* [INSERT OVERWRITE DIRECTORY with Hive format statement](sql-ref-syntax-dml-insert-overwrite-directory-hive.html) diff --git a/docs/sql-ref-syntax-dml-insert-overwrite-directory-hive.md b/docs/sql-ref-syntax-dml-insert-overwrite-directory-hive.md index 3cd2107668fbe..8ed6a3cd1be09 100644 --- a/docs/sql-ref-syntax-dml-insert-overwrite-directory-hive.md +++ b/docs/sql-ref-syntax-dml-insert-overwrite-directory-hive.md @@ -26,56 +26,41 @@ Hive support must be enabled to use this command. The inserted rows can be speci ### Syntax -{% highlight sql %} +```sql INSERT OVERWRITE [ LOCAL ] DIRECTORY directory_path [ ROW FORMAT row_format ] [ STORED AS file_format ] { VALUES ( { value | NULL } [ , ... ] ) [ , ( ... ) ] | query } -{% endhighlight %} +``` ### Parameters -
-
directory_path
-
- Specifies the destination directory. The LOCAL keyword is used to specify that the directory is on the local file system. -
-
- -
-
row_format
-
- Specifies the row format for this insert. Valid options are SERDE clause and DELIMITED clause. SERDE clause can be used to specify a custom SerDe for this insert. Alternatively, DELIMITED clause can be used to specify the native SerDe and state the delimiter, escape character, null character, and so on. -
-
- -
-
file_format
-
- Specifies the file format for this insert. Valid options are TEXTFILE, SEQUENCEFILE, RCFILE, ORC, PARQUET, and AVRO. You can also specify your own input and output format using INPUTFORMAT and OUTPUTFORMAT. ROW FORMAT SERDE can only be used with TEXTFILE, SEQUENCEFILE, or RCFILE, while ROW FORMAT DELIMITED can only be used with TEXTFILE. -
-
- -
-
VALUES ( { value | NULL } [ , ... ] ) [ , ( ... ) ]
-
- Specifies the values to be inserted. Either an explicitly specified value or a NULL can be inserted. A comma must be used to separate each value in the clause. More than one set of values can be specified to insert multiple rows. -
-
- -
-
query
-
A query that produces the rows to be inserted. It can be in one of following formats: -
    -
  • a SELECT statement
  • -
  • a TABLE statement
  • -
  • a FROM statement
  • -
-
-
+* **directory_path** + + Specifies the destination directory. The `LOCAL` keyword is used to specify that the directory is on the local file system. + +* **row_format** + + Specifies the row format for this insert. Valid options are `SERDE` clause and `DELIMITED` clause. `SERDE` clause can be used to specify a custom `SerDe` for this insert. Alternatively, `DELIMITED` clause can be used to specify the native `SerDe` and state the delimiter, escape character, null character, and so on. + +* **file_format** + + Specifies the file format for this insert. Valid options are `TEXTFILE`, `SEQUENCEFILE`, `RCFILE`, `ORC`, `PARQUET`, and `AVRO`. You can also specify your own input and output format using `INPUTFORMAT` and `OUTPUTFORMAT`. `ROW FORMAT SERDE` can only be used with `TEXTFILE`, `SEQUENCEFILE`, or `RCFILE`, while `ROW FORMAT DELIMITED` can only be used with `TEXTFILE`. + +* **VALUES ( { value `|` NULL } [ , ... ] ) [ , ( ... ) ]** + + Specifies the values to be inserted. Either an explicitly specified value or a NULL can be inserted. + A comma must be used to separate each value in the clause. More than one set of values can be specified to insert multiple rows. + +* **query** + + A query that produces the rows to be inserted. It can be in one of following formats: + * a `SELECT` statement + * a `TABLE` statement + * a `FROM` statement ### Examples -{% highlight sql %} +```sql INSERT OVERWRITE LOCAL DIRECTORY '/tmp/destination' STORED AS orc SELECT * FROM test_table; @@ -83,10 +68,10 @@ INSERT OVERWRITE LOCAL DIRECTORY '/tmp/destination' INSERT OVERWRITE LOCAL DIRECTORY '/tmp/destination' ROW FORMAT DELIMITED FIELDS TERMINATED BY ',' SELECT * FROM test_table; -{% endhighlight %} +``` ### Related Statements - * [INSERT INTO statement](sql-ref-syntax-dml-insert-into.html) - * [INSERT OVERWRITE statement](sql-ref-syntax-dml-insert-overwrite-table.html) - * [INSERT OVERWRITE DIRECTORY statement](sql-ref-syntax-dml-insert-overwrite-directory.html) +* [INSERT INTO statement](sql-ref-syntax-dml-insert-into.html) +* [INSERT OVERWRITE statement](sql-ref-syntax-dml-insert-overwrite-table.html) +* [INSERT OVERWRITE DIRECTORY statement](sql-ref-syntax-dml-insert-overwrite-directory.html) diff --git a/docs/sql-ref-syntax-dml-insert-overwrite-directory.md b/docs/sql-ref-syntax-dml-insert-overwrite-directory.md index 6ce7f50588e32..fd7437d37c909 100644 --- a/docs/sql-ref-syntax-dml-insert-overwrite-directory.md +++ b/docs/sql-ref-syntax-dml-insert-overwrite-directory.md @@ -25,54 +25,42 @@ The `INSERT OVERWRITE DIRECTORY` statement overwrites the existing data in the d ### Syntax -{% highlight sql %} +```sql INSERT OVERWRITE [ LOCAL ] DIRECTORY [ directory_path ] USING file_format [ OPTIONS ( key = val [ , ... ] ) ] { VALUES ( { value | NULL } [ , ... ] ) [ , ( ... ) ] | query } -{% endhighlight %} +``` ### Parameters -
-
directory_path
-
- Specifies the destination directory. It can also be specified in OPTIONS using path. The LOCAL keyword is used to specify that the directory is on the local file system. -
-
- -
-
file_format
-
- Specifies the file format to use for the insert. Valid options are TEXT, CSV, JSON, JDBC, PARQUET, ORC, HIVE, LIBSVM, or a fully qualified class name of a custom implementation of org.apache.spark.sql.execution.datasources.FileFormat. -
-
- -
-
OPTIONS ( key = val [ , ... ] )
-
Specifies one or more options for the writing of the file format.
-
- -
-
VALUES ( { value | NULL } [ , ... ] ) [ , ( ... ) ]
-
- Specifies the values to be inserted. Either an explicitly specified value or a NULL can be inserted. A comma must be used to separate each value in the clause. More than one set of values can be specified to insert multiple rows. -
-
- -
-
query
-
A query that produces the rows to be inserted. It can be in one of following formats: -
    -
  • a SELECT statement
  • -
  • a TABLE statement
  • -
  • a FROM statement
  • -
-
-
+* **directory_path** + + Specifies the destination directory. It can also be specified in `OPTIONS` using `path`. + The `LOCAL` keyword is used to specify that the directory is on the local file system. + +* **file_format** + + Specifies the file format to use for the insert. Valid options are `TEXT`, `CSV`, `JSON`, `JDBC`, `PARQUET`, `ORC`, `HIVE`, `LIBSVM`, or a fully qualified class name of a custom implementation of `org.apache.spark.sql.execution.datasources.FileFormat`. + +* **OPTIONS ( key = val [ , ... ] )** + + Specifies one or more options for the writing of the file format. + +* **VALUES ( { value `|` NULL } [ , ... ] ) [ , ( ... ) ]** + + Specifies the values to be inserted. Either an explicitly specified value or a NULL can be inserted. + A comma must be used to separate each value in the clause. More than one set of values can be specified to insert multiple rows. + +* **query** + + A query that produces the rows to be inserted. It can be in one of following formats: + * a `SELECT` statement + * a `TABLE` statement + * a `FROM` statement ### Examples -{% highlight sql %} +```sql INSERT OVERWRITE DIRECTORY '/tmp/destination' USING parquet OPTIONS (col1 1, col2 2, col3 'test') @@ -82,10 +70,10 @@ INSERT OVERWRITE DIRECTORY USING parquet OPTIONS ('path' '/tmp/destination', col1 1, col2 2, col3 'test') SELECT * FROM test_table; -{% endhighlight %} +``` ### Related Statements - * [INSERT INTO statement](sql-ref-syntax-dml-insert-into.html) - * [INSERT OVERWRITE statement](sql-ref-syntax-dml-insert-overwrite-table.html) - * [INSERT OVERWRITE DIRECTORY with Hive format statement](sql-ref-syntax-dml-insert-overwrite-directory-hive.html) +* [INSERT INTO statement](sql-ref-syntax-dml-insert-into.html) +* [INSERT OVERWRITE statement](sql-ref-syntax-dml-insert-overwrite-table.html) +* [INSERT OVERWRITE DIRECTORY with Hive format statement](sql-ref-syntax-dml-insert-overwrite-directory-hive.html) diff --git a/docs/sql-ref-syntax-dml-insert-overwrite-table.md b/docs/sql-ref-syntax-dml-insert-overwrite-table.md index 5c760f00ed0c4..ecfd060dfd5ee 100644 --- a/docs/sql-ref-syntax-dml-insert-overwrite-table.md +++ b/docs/sql-ref-syntax-dml-insert-overwrite-table.md @@ -25,57 +25,43 @@ The `INSERT OVERWRITE` statement overwrites the existing data in the table using ### Syntax -{% highlight sql %} +```sql INSERT OVERWRITE [ TABLE ] table_identifier [ partition_spec [ IF NOT EXISTS ] ] { VALUES ( { value | NULL } [ , ... ] ) [ , ( ... ) ] | query } -{% endhighlight %} +``` ### Parameters -
-
table_identifier
-
- Specifies a table name, which may be optionally qualified with a database name.

- Syntax: - - [ database_name. ] table_name - -
-
- -
-
partition_spec
-
+* **table_identifier** + + Specifies a table name, which may be optionally qualified with a database name. + + **Syntax:** `[ database_name. ] table_name` + +* **partition_spec** + An optional parameter that specifies a comma separated list of key and value pairs - for partitions.

- Syntax: - - PARTITION ( partition_col_name [ = partition_col_val ] [ , ... ] ) - -
-
- -
-
VALUES ( { value | NULL } [ , ... ] ) [ , ( ... ) ]
-
Specifies the values to be inserted. Either an explicitly specified value or a NULL can be inserted. A comma must be used to separate each value in the clause. More than one set of values can be specified to insert multiple rows.
-
- -
-
query
-
A query that produces the rows to be inserted. It can be in one of following formats: -
    -
  • a SELECT statement
  • -
  • a TABLE statement
  • -
  • a FROM statement
  • -
-
-
+ for partitions. + + **Syntax:** `PARTITION ( partition_col_name [ = partition_col_val ] [ , ... ] )` + +* **VALUES ( { value `|` NULL } [ , ... ] ) [ , ( ... ) ]** + + Specifies the values to be inserted. Either an explicitly specified value or a NULL can be inserted. + A comma must be used to separate each value in the clause. More than one set of values can be specified to insert multiple rows. + +* **query** + + A query that produces the rows to be inserted. It can be in one of following formats: + * a `SELECT` statement + * a `TABLE` statement + * a `FROM` statement ### Examples #### Insert Using a VALUES Clause -{% highlight sql %} +```sql -- Assuming the students table has already been created and populated. SELECT * FROM students; +-------------+-------------------------+----------+ @@ -102,12 +88,11 @@ SELECT * FROM students; |Ashua Hill|456 Erica Ct, Cupertino| 111111| |Brian Reed|723 Kern Ave, Palo Alto| 222222| +----------+-----------------------+----------+ - -{% endhighlight %} +``` #### Insert Using a SELECT Statement -{% highlight sql %} +```sql -- Assuming the persons table has already been created and populated. SELECT * FROM persons; +-------------+-------------------------+---------+ @@ -129,11 +114,11 @@ SELECT * FROM students; +-------------+-------------------------+----------+ |Dora Williams|134 Forest Ave, Melo Park| 222222| +-------------+-------------------------+----------+ -{% endhighlight %} +``` #### Insert Using a TABLE Statement -{% highlight sql %} +```sql -- Assuming the visiting_students table has already been created and populated. SELECT * FROM visiting_students; +-------------+---------------------+----------+ @@ -154,11 +139,11 @@ SELECT * FROM students; +-------------+---------------------+----------+ |Gordon Martin| 779 Lake Ave, Oxford| 888888| +-------------+---------------------+----------+ -{% endhighlight %} +``` #### Insert Using a FROM Statement -{% highlight sql %} +```sql -- Assuming the applicants table has already been created and populated. SELECT * FROM applicants; +-----------+--------------------------+----------+---------+ @@ -182,10 +167,10 @@ SELECT * FROM students; +-----------+-------------------------+----------+ | Jason Wang| 908 Bird St, Saratoga| 121212| +-----------+-------------------------+----------+ -{% endhighlight %} +``` ### Related Statements - * [INSERT INTO statement](sql-ref-syntax-dml-insert-into.html) - * [INSERT OVERWRITE DIRECTORY statement](sql-ref-syntax-dml-insert-overwrite-directory.html) - * [INSERT OVERWRITE DIRECTORY with Hive format statement](sql-ref-syntax-dml-insert-overwrite-directory-hive.html) +* [INSERT INTO statement](sql-ref-syntax-dml-insert-into.html) +* [INSERT OVERWRITE DIRECTORY statement](sql-ref-syntax-dml-insert-overwrite-directory.html) +* [INSERT OVERWRITE DIRECTORY with Hive format statement](sql-ref-syntax-dml-insert-overwrite-directory-hive.html) diff --git a/docs/sql-ref-syntax-dml-insert.md b/docs/sql-ref-syntax-dml-insert.md index 2345add2460c8..62f6dee876450 100644 --- a/docs/sql-ref-syntax-dml-insert.md +++ b/docs/sql-ref-syntax-dml-insert.md @@ -21,7 +21,7 @@ license: | The INSERT statements: - * [INSERT INTO statement](sql-ref-syntax-dml-insert-into.html) - * [INSERT OVERWRITE statement](sql-ref-syntax-dml-insert-overwrite-table.html) - * [INSERT OVERWRITE DIRECTORY statement](sql-ref-syntax-dml-insert-overwrite-directory.html) - * [INSERT OVERWRITE DIRECTORY with Hive format statement](sql-ref-syntax-dml-insert-overwrite-directory-hive.html) +* [INSERT INTO statement](sql-ref-syntax-dml-insert-into.html) +* [INSERT OVERWRITE statement](sql-ref-syntax-dml-insert-overwrite-table.html) +* [INSERT OVERWRITE DIRECTORY statement](sql-ref-syntax-dml-insert-overwrite-directory.html) +* [INSERT OVERWRITE DIRECTORY with Hive format statement](sql-ref-syntax-dml-insert-overwrite-directory-hive.html) diff --git a/docs/sql-ref-syntax-dml-load.md b/docs/sql-ref-syntax-dml-load.md index 01ece31bd17fa..9381b4267fb24 100644 --- a/docs/sql-ref-syntax-dml-load.md +++ b/docs/sql-ref-syntax-dml-load.md @@ -25,53 +25,40 @@ license: | ### Syntax -{% highlight sql %} +```sql LOAD DATA [ LOCAL ] INPATH path [ OVERWRITE ] INTO TABLE table_identifier [ partition_spec ] -{% endhighlight %} +``` ### Parameters -
-
path
-
Path of the file system. It can be either an absolute or a relative path.
-
- -
-
table_identifier
-
- Specifies a table name, which may be optionally qualified with a database name.

- Syntax: - - [ database_name. ] table_name - -
-
- -
-
partition_spec
-
+* **path** + + Path of the file system. It can be either an absolute or a relative path. + +* **table_identifier** + + Specifies a table name, which may be optionally qualified with a database name. + + **Syntax:** `[ database_name. ] table_name` + +* **partition_spec** + An optional parameter that specifies a comma separated list of key and value pairs - for partitions.

- Syntax: - - PARTITION ( partition_col_name = partition_col_val [ , ... ] ) - -
-
- -
-
LOCAL
-
If specified, it causes the INPATH to be resolved against the local file system, instead of the default file system, which is typically a distributed storage.
-
- -
-
OVERWRITE
-
By default, new data is appended to the table. If OVERWRITE is used, the table is instead overwritten with new data.
-
+ for partitions. + + **Syntax:** `PARTITION ( partition_col_name = partition_col_val [ , ... ] )` + +* **LOCAL** + + If specified, it causes the `INPATH` to be resolved against the local file system, instead of the default file system, which is typically a distributed storage. + +* **OVERWRITE** + + By default, new data is appended to the table. If `OVERWRITE` is used, the table is instead overwritten with new data. ### Examples -{% highlight sql %} +```sql -- Example without partition specification. -- Assuming the students table has already been created and populated. SELECT * FROM students; @@ -123,4 +110,4 @@ SELECT * FROM test_load_partition; +---+---+---+ | 1| 2| 3| +---+---+---+ -{% endhighlight %} +``` diff --git a/docs/sql-ref-syntax-dml.md b/docs/sql-ref-syntax-dml.md index 9f75990555f64..fc408e1d38d26 100644 --- a/docs/sql-ref-syntax-dml.md +++ b/docs/sql-ref-syntax-dml.md @@ -21,5 +21,5 @@ license: | Data Manipulation Statements are used to add, change, or delete data. Spark SQL supports the following Data Manipulation Statements: - * [INSERT](sql-ref-syntax-dml-insert.html) - * [LOAD](sql-ref-syntax-dml-load.html) +* [INSERT](sql-ref-syntax-dml-insert.html) +* [LOAD](sql-ref-syntax-dml-load.html) diff --git a/docs/sql-ref-syntax-qry-explain.md b/docs/sql-ref-syntax-qry-explain.md index 298a2edaea1f2..7b84264a28cca 100644 --- a/docs/sql-ref-syntax-qry-explain.md +++ b/docs/sql-ref-syntax-qry-explain.md @@ -26,46 +26,38 @@ By default, this clause provides information about a physical plan only. ### Syntax -{% highlight sql %} +```sql EXPLAIN [ EXTENDED | CODEGEN | COST | FORMATTED ] statement -{% endhighlight %} +``` ### Parameters -
-
EXTENDED
-
Generates parsed logical plan, analyzed logical plan, optimized logical plan and physical plan. - Parsed Logical plan is a unresolved plan that extracted from the query. - Analyzed logical plans transforms which translates unresolvedAttribute and unresolvedRelation into fully typed objects. - The optimized logical plan transforms through a set of optimization rules, resulting in the physical plan. -
-
- -
-
CODEGEN
-
Generates code for the statement, if any and a physical plan.
-
- -
-
COST
-
If plan node statistics are available, generates a logical plan and the statistics.
-
- -
-
FORMATTED
-
Generates two sections: a physical plan outline and node details.
-
- -
-
statement
-
+* **EXTENDED** + + Generates parsed logical plan, analyzed logical plan, optimized logical plan and physical plan. + Parsed Logical plan is a unresolved plan that extracted from the query. + Analyzed logical plans transforms which translates unresolvedAttribute and unresolvedRelation into fully typed objects. + The optimized logical plan transforms through a set of optimization rules, resulting in the physical plan. + +* **CODEGEN** + + Generates code for the statement, if any and a physical plan. + +* **COST** + + If plan node statistics are available, generates a logical plan and the statistics. + +* **FORMATTED** + + Generates two sections: a physical plan outline and node details. + +* **statement** + Specifies a SQL statement to be explained. -
-
### Examples -{% highlight sql %} +```sql -- Default Output EXPLAIN select k, sum(v) from values (1, 2), (1, 3) t(k, v) group by k; +----------------------------------------------------+ @@ -132,4 +124,4 @@ EXPLAIN FORMATTED select k, sum(v) from values (1, 2), (1, 3) t(k, v) group by k Input: [k#19, sum#24L] | +----------------------------------------------------+ -{% endhighlight %} +``` diff --git a/docs/sql-ref-syntax-qry-sampling.md b/docs/sql-ref-syntax-qry-sampling.md index 82f6588e6c504..28e21e802fe25 100644 --- a/docs/sql-ref-syntax-qry-sampling.md +++ b/docs/sql-ref-syntax-qry-sampling.md @@ -30,15 +30,15 @@ Note: `TABLESAMPLE` returns the approximate number of rows or fraction requested ### Syntax -{% highlight sql %} -TABLESAMPLE ((integer_expression | decimal_expression) PERCENT) - | TABLESAMPLE (integer_expression ROWS) - | TABLESAMPLE (BUCKET integer_expression OUT OF integer_expression) -{% endhighlight %} +```sql +TABLESAMPLE ({ integer_expression | decimal_expression } PERCENT) + | TABLESAMPLE ( integer_expression ROWS ) + | TABLESAMPLE ( BUCKET integer_expression OUT OF integer_expression ) +``` ### Examples -{% highlight sql %} +```sql SELECT * FROM test; +--+----+ |id|name| @@ -87,8 +87,8 @@ SELECT * FROM test TABLESAMPLE (BUCKET 4 OUT OF 10); | 9|Eric| | 6|Mark| +--+----+ -{% endhighlight %} +``` -### Related Statement +### Related Statements - * [SELECT](sql-ref-syntax-qry-select.html) \ No newline at end of file +* [SELECT](sql-ref-syntax-qry-select.html) \ No newline at end of file diff --git a/docs/sql-ref-syntax-qry-select-clusterby.md b/docs/sql-ref-syntax-qry-select-clusterby.md index ac1e1ccb00ac9..e3bd2ed926ecc 100644 --- a/docs/sql-ref-syntax-qry-select-clusterby.md +++ b/docs/sql-ref-syntax-qry-select-clusterby.md @@ -21,7 +21,7 @@ license: | ### Description -The CLUSTER BY clause is used to first repartition the data based +The `CLUSTER BY` clause is used to first repartition the data based on the input expressions and then sort the data within each partition. This is semantically equivalent to performing a [DISTRIBUTE BY](sql-ref-syntax-qry-select-distribute-by.html) followed by a @@ -30,22 +30,19 @@ resultant rows are sorted within each partition and does not guarantee a total o ### Syntax -{% highlight sql %} +```sql CLUSTER BY { expression [ , ... ] } -{% endhighlight %} +``` ### Parameters -
-
expression
-
+* **expression** + Specifies combination of one or more values, operators and SQL functions that results in a value. -
-
### Examples -{% highlight sql %} +```sql CREATE TABLE person (name STRING, age INT); INSERT INTO person VALUES ('Zen Hui', 25), @@ -90,15 +87,15 @@ SELECT age, name FROM person CLUSTER BY age; | 16|Shone S| | 16| Jack N| +---+-------+ -{% endhighlight %} +``` ### Related Statements - * [SELECT Main](sql-ref-syntax-qry-select.html) - * [WHERE Clause](sql-ref-syntax-qry-select-where.html) - * [GROUP BY Clause](sql-ref-syntax-qry-select-groupby.html) - * [HAVING Clause](sql-ref-syntax-qry-select-having.html) - * [ORDER BY Clause](sql-ref-syntax-qry-select-orderby.html) - * [SORT BY Clause](sql-ref-syntax-qry-select-sortby.html) - * [DISTRIBUTE BY Clause](sql-ref-syntax-qry-select-distribute-by.html) - * [LIMIT Clause](sql-ref-syntax-qry-select-limit.html) +* [SELECT Main](sql-ref-syntax-qry-select.html) +* [WHERE Clause](sql-ref-syntax-qry-select-where.html) +* [GROUP BY Clause](sql-ref-syntax-qry-select-groupby.html) +* [HAVING Clause](sql-ref-syntax-qry-select-having.html) +* [ORDER BY Clause](sql-ref-syntax-qry-select-orderby.html) +* [SORT BY Clause](sql-ref-syntax-qry-select-sortby.html) +* [DISTRIBUTE BY Clause](sql-ref-syntax-qry-select-distribute-by.html) +* [LIMIT Clause](sql-ref-syntax-qry-select-limit.html) diff --git a/docs/sql-ref-syntax-qry-select-cte.md b/docs/sql-ref-syntax-qry-select-cte.md index 2408c884c64b5..351de64a2d026 100644 --- a/docs/sql-ref-syntax-qry-select-cte.md +++ b/docs/sql-ref-syntax-qry-select-cte.md @@ -25,33 +25,28 @@ A common table expression (CTE) defines a temporary result set that a user can r ### Syntax -{% highlight sql %} +```sql WITH common_table_expression [ , ... ] -{% endhighlight %} +``` While `common_table_expression` is defined as -{% highlight sql %} -expression_name [ ( column_name [ , ... ] ) ] [ AS ] ( [ common_table_expression ] query ) -{% endhighlight %} +```sql +expression_name [ ( column_name [ , ... ] ) ] [ AS ] ( query ) +``` ### Parameters -
-
expression_name
-
+* **expression_name** + Specifies a name for the common table expression. -
-
-
-
query
-
- A SELECT statement. -
-
+ +* **query** + + A [SELECT statement](sql-ref-syntax-qry-select.html). ### Examples -{% highlight sql %} +```sql -- CTE with multiple column aliases WITH t(x, y) AS (SELECT 1, 2) SELECT * FROM t WHERE x = 1 AND y = 2; @@ -62,7 +57,7 @@ SELECT * FROM t WHERE x = 1 AND y = 2; +---+---+ -- CTE in CTE definition -WITH t as ( +WITH t AS ( WITH t2 AS (SELECT 1) SELECT * FROM t2 ) @@ -122,8 +117,8 @@ SELECT * FROM t2; +---+ | 2| +---+ -{% endhighlight %} +``` ### Related Statements - * [SELECT](sql-ref-syntax-qry-select.html) +* [SELECT](sql-ref-syntax-qry-select.html) diff --git a/docs/sql-ref-syntax-qry-select-distribute-by.md b/docs/sql-ref-syntax-qry-select-distribute-by.md index 9e2db27ae7161..1fdfb91dad286 100644 --- a/docs/sql-ref-syntax-qry-select-distribute-by.md +++ b/docs/sql-ref-syntax-qry-select-distribute-by.md @@ -21,28 +21,25 @@ license: | ### Description -The DISTRIBUTE BY clause is used to repartition the data based +The `DISTRIBUTE BY` 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. ### Syntax -{% highlight sql %} +```sql DISTRIBUTE BY { expression [ , ... ] } -{% endhighlight %} +``` ### Parameters -
-
expression
-
+* **expression** + Specifies combination of one or more values, operators and SQL functions that results in a value. -
-
### Examples -{% highlight sql %} +```sql CREATE TABLE person (name STRING, age INT); INSERT INTO person VALUES ('Zen Hui', 25), @@ -85,15 +82,15 @@ SELECT age, name FROM person DISTRIBUTE BY age; | 16|Shone S| | 16| Jack N| +---+-------+ -{% endhighlight %} +``` ### Related Statements - * [SELECT Main](sql-ref-syntax-qry-select.html) - * [WHERE Clause](sql-ref-syntax-qry-select-where.html) - * [GROUP BY Clause](sql-ref-syntax-qry-select-groupby.html) - * [HAVING Clause](sql-ref-syntax-qry-select-having.html) - * [ORDER BY Clause](sql-ref-syntax-qry-select-orderby.html) - * [SORT BY Clause](sql-ref-syntax-qry-select-sortby.html) - * [CLUSTER BY Clause](sql-ref-syntax-qry-select-clusterby.html) - * [LIMIT Clause](sql-ref-syntax-qry-select-limit.html) +* [SELECT Main](sql-ref-syntax-qry-select.html) +* [WHERE Clause](sql-ref-syntax-qry-select-where.html) +* [GROUP BY Clause](sql-ref-syntax-qry-select-groupby.html) +* [HAVING Clause](sql-ref-syntax-qry-select-having.html) +* [ORDER BY Clause](sql-ref-syntax-qry-select-orderby.html) +* [SORT BY Clause](sql-ref-syntax-qry-select-sortby.html) +* [CLUSTER BY Clause](sql-ref-syntax-qry-select-clusterby.html) +* [LIMIT Clause](sql-ref-syntax-qry-select-limit.html) diff --git a/docs/sql-ref-syntax-qry-select-groupby.md b/docs/sql-ref-syntax-qry-select-groupby.md index 22fe782f9eaa7..bd9377ef78df6 100644 --- a/docs/sql-ref-syntax-qry-select-groupby.md +++ b/docs/sql-ref-syntax-qry-select-groupby.md @@ -21,84 +21,79 @@ license: | ### Description -The GROUP BY clause is used to group the rows based on a set of specified grouping expressions and compute aggregations on +The `GROUP BY` 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. When a FILTER clause is attached to an aggregate function, only the matching rows are passed to that function. ### Syntax -{% highlight sql %} +```sql GROUP BY group_expression [ , group_expression [ , ... ] ] [ { WITH ROLLUP | WITH CUBE | GROUPING SETS (grouping_set [ , ...]) } ] GROUP BY GROUPING SETS (grouping_set [ , ...]) -{% endhighlight %} +``` While aggregate functions are defined as -{% highlight sql %} +```sql aggregate_name ( [ DISTINCT ] expression [ , ... ] ) [ FILTER ( WHERE boolean_expression ) ] -{% endhighlight %} +``` ### Parameters -
-
GROUPING SETS
-
+* **GROUPING SETS** + Groups the rows for each subset of the expressions specified in the grouping sets. For example, - GROUP BY GROUPING SETS (warehouse, product) is semantically equivalent - to union of results of GROUP BY warehouse and GROUP BY product. This clause - is a shorthand for a UNION ALL where each leg of the UNION ALL - operator performs aggregation of subset of the columns specified in the GROUPING SETS clause. -
-
grouping_set
-
- A grouping set is specified by zero or more comma-separated expressions in parentheses.

- Syntax: - - ([expression [, ...]]) - -
-
grouping_expression
-
+ `GROUP BY GROUPING SETS (warehouse, product)` is semantically equivalent + to union of results of `GROUP BY warehouse` and `GROUP BY product`. This clause + is a shorthand for a `UNION ALL` where each leg of the `UNION ALL` + operator performs aggregation of subset of the columns specified in the `GROUPING SETS` clause. + +* **grouping_set** + + A grouping set is specified by zero or more comma-separated expressions in parentheses. + + **Syntax:** `( [ expression [ , ... ] ] )` + +* **grouping_expression** + Specifies the critieria based on which the rows are grouped together. The grouping of rows is performed based on result values of the grouping expressions. A grouping expression may be a column alias, a column position or an expression. -
-
ROLLUP
-
+ +* **ROLLUP** + Specifies multiple levels of aggregations in a single statement. This clause is used to compute aggregations - based on multiple grouping sets. ROLLUP is a shorthand for GROUPING SETS. For example, - GROUP BY warehouse, product WITH ROLLUP is equivalent to GROUP BY GROUPING SETS - ((warehouse, product), (warehouse), ()). - The N elements of a ROLLUP specification results in N+1 GROUPING SETS. -
-
CUBE
-
- CUBE clause is used to perform aggregations based on combination of grouping columns specified in the - GROUP BY clause. CUBE is a shorthand for GROUPING SETS. For example, - GROUP BY warehouse, product WITH CUBE is equivalent to GROUP BY GROUPING SETS - ((warehouse, product), (warehouse), (product), ()). - The N elements of a CUBE specification results in 2^N GROUPING SETS. -
-
aggregate_name
-
+ based on multiple grouping sets. `ROLLUP` is a shorthand for `GROUPING SETS`. For example, + `GROUP BY warehouse, product WITH ROLLUP` is equivalent to `GROUP BY GROUPING SETS + ((warehouse, product), (warehouse), ())`. + The N elements of a `ROLLUP` specification results in N+1 `GROUPING SETS`. + +* **CUBE** + + `CUBE` clause is used to perform aggregations based on combination of grouping columns specified in the + `GROUP BY` clause. `CUBE` is a shorthand for `GROUPING SETS`. For example, + `GROUP BY warehouse, product WITH CUBE` is equivalent to `GROUP BY GROUPING SETS + ((warehouse, product), (warehouse), (product), ())`. + The N elements of a `CUBE` specification results in 2^N `GROUPING SETS`. + +* **aggregate_name** + Specifies an aggregate function name (MIN, MAX, COUNT, SUM, AVG, etc.). -
-
DISTINCT
-
+ +* **DISTINCT** + Removes duplicates in input rows before they are passed to aggregate functions. -
-
FILTER
-
- Filters the input rows for which the boolean_expression in the WHERE clause evaluates + +* **FILTER** + + Filters the input rows for which the `boolean_expression` in the `WHERE` clause evaluates to true are passed to the aggregate function; other rows are discarded. -
-
### Examples -{% highlight sql %} +```sql CREATE TABLE dealer (id INT, city STRING, car_model STRING, quantity INT); INSERT INTO dealer VALUES (100, 'Fremont', 'Honda Civic', 10), @@ -174,106 +169,106 @@ SELECT id, sum(quantity) FILTER ( SELECT city, car_model, sum(quantity) AS sum FROM dealer GROUP BY GROUPING SETS ((city, car_model), (city), (car_model), ()) ORDER BY city; -+--------+------------+---+ -| city| car_model|sum| -+--------+------------+---+ -| null| null| 78| -| null| HondaAccord| 33| -| null| HondaCRV| 10| -| null| HondaCivic| 35| -| Dublin| null| 33| -| Dublin| HondaAccord| 10| -| Dublin| HondaCRV| 3| -| Dublin| HondaCivic| 20| -| Fremont| null| 32| -| Fremont| HondaAccord| 15| -| Fremont| HondaCRV| 7| -| Fremont| HondaCivic| 10| -| SanJose| null| 13| -| SanJose| HondaAccord| 8| -| SanJose| HondaCivic| 5| -+--------+------------+---+ ++---------+------------+---+ +| city| car_model|sum| ++---------+------------+---+ +| null| null| 78| +| null| HondaAccord| 33| +| null| HondaCRV| 10| +| null| HondaCivic| 35| +| Dublin| null| 33| +| Dublin| HondaAccord| 10| +| Dublin| HondaCRV| 3| +| Dublin| HondaCivic| 20| +| Fremont| null| 32| +| Fremont| HondaAccord| 15| +| Fremont| HondaCRV| 7| +| Fremont| HondaCivic| 10| +| San Jose| null| 13| +| San Jose| HondaAccord| 8| +| San Jose| HondaCivic| 5| ++---------+------------+---+ -- Alternate syntax for `GROUPING SETS` in which both `GROUP BY` and `GROUPING SETS` -- specifications are present. SELECT city, car_model, sum(quantity) AS sum FROM dealer GROUP BY city, car_model GROUPING SETS ((city, car_model), (city), (car_model), ()) ORDER BY city, car_model; -+--------+------------+---+ -| city| car_model|sum| -+--------+------------+---+ -| null| null| 78| -| null| HondaAccord| 33| -| null| HondaCRV| 10| -| null| HondaCivic| 35| -| Dublin| null| 33| -| Dublin| HondaAccord| 10| -| Dublin| HondaCRV| 3| -| Dublin| HondaCivic| 20| -| Fremont| null| 32| -| Fremont| HondaAccord| 15| -| Fremont| HondaCRV| 7| -| Fremont| HondaCivic| 10| -| SanJose| null| 13| -| SanJose| HondaAccord| 8| -| SanJose| HondaCivic| 5| -+--------+------------+---+ ++---------+------------+---+ +| city| car_model|sum| ++---------+------------+---+ +| null| null| 78| +| null| HondaAccord| 33| +| null| HondaCRV| 10| +| null| HondaCivic| 35| +| Dublin| null| 33| +| Dublin| HondaAccord| 10| +| Dublin| HondaCRV| 3| +| Dublin| HondaCivic| 20| +| Fremont| null| 32| +| Fremont| HondaAccord| 15| +| Fremont| HondaCRV| 7| +| Fremont| HondaCivic| 10| +| San Jose| null| 13| +| San Jose| HondaAccord| 8| +| San Jose| HondaCivic| 5| ++---------+------------+---+ -- Group by processing with `ROLLUP` clause. -- Equivalent GROUP BY GROUPING SETS ((city, car_model), (city), ()) SELECT city, car_model, sum(quantity) AS sum FROM dealer GROUP BY city, car_model WITH ROLLUP ORDER BY city, car_model; -+--------+------------+---+ -| city| car_model|sum| -+--------+------------+---+ -| null| null| 78| -| Dublin| null| 33| -| Dublin| HondaAccord| 10| -| Dublin| HondaCRV| 3| -| Dublin| HondaCivic| 20| -| Fremont| null| 32| -| Fremont| HondaAccord| 15| -| Fremont| HondaCRV| 7| -| Fremont| HondaCivic| 10| -| SanJose| null| 13| -| SanJose| HondaAccord| 8| -| SanJose| HondaCivic| 5| -+--------+------------+---+ ++---------+------------+---+ +| city| car_model|sum| ++---------+------------+---+ +| null| null| 78| +| Dublin| null| 33| +| Dublin| HondaAccord| 10| +| Dublin| HondaCRV| 3| +| Dublin| HondaCivic| 20| +| Fremont| null| 32| +| Fremont| HondaAccord| 15| +| Fremont| HondaCRV| 7| +| Fremont| HondaCivic| 10| +| San Jose| null| 13| +| San Jose| HondaAccord| 8| +| San Jose| HondaCivic| 5| ++---------+------------+---+ -- Group by processing with `CUBE` clause. -- Equivalent GROUP BY GROUPING SETS ((city, car_model), (city), (car_model), ()) SELECT city, car_model, sum(quantity) AS sum FROM dealer GROUP BY city, car_model WITH CUBE ORDER BY city, car_model; -+--------+------------+---+ -| city| car_model|sum| -+--------+------------+---+ -| null| null| 78| -| null| HondaAccord| 33| -| null| HondaCRV| 10| -| null| HondaCivic| 35| -| Dublin| null| 33| -| Dublin| HondaAccord| 10| -| Dublin| HondaCRV| 3| -| Dublin| HondaCivic| 20| -| Fremont| null| 32| -| Fremont| HondaAccord| 15| -| Fremont| HondaCRV| 7| -| Fremont| HondaCivic| 10| -| SanJose| null| 13| -| SanJose| HondaAccord| 8| -| SanJose| HondaCivic| 5| -+--------+------------+---+ -{% endhighlight %} ++---------+------------+---+ +| city| car_model|sum| ++---------+------------+---+ +| null| null| 78| +| null| HondaAccord| 33| +| null| HondaCRV| 10| +| null| HondaCivic| 35| +| Dublin| null| 33| +| Dublin| HondaAccord| 10| +| Dublin| HondaCRV| 3| +| Dublin| HondaCivic| 20| +| Fremont| null| 32| +| Fremont| HondaAccord| 15| +| Fremont| HondaCRV| 7| +| Fremont| HondaCivic| 10| +| San Jose| null| 13| +| San Jose| HondaAccord| 8| +| San Jose| HondaCivic| 5| ++---------+------------+---+ +``` ### Related Statements - * [SELECT Main](sql-ref-syntax-qry-select.html) - * [WHERE Clause](sql-ref-syntax-qry-select-where.html) - * [HAVING Clause](sql-ref-syntax-qry-select-having.html) - * [ORDER BY Clause](sql-ref-syntax-qry-select-orderby.html) - * [SORT BY Clause](sql-ref-syntax-qry-select-sortby.html) - * [CLUSTER BY Clause](sql-ref-syntax-qry-select-clusterby.html) - * [DISTRIBUTE BY Clause](sql-ref-syntax-qry-select-distribute-by.html) - * [LIMIT Clause](sql-ref-syntax-qry-select-limit.html) +* [SELECT Main](sql-ref-syntax-qry-select.html) +* [WHERE Clause](sql-ref-syntax-qry-select-where.html) +* [HAVING Clause](sql-ref-syntax-qry-select-having.html) +* [ORDER BY Clause](sql-ref-syntax-qry-select-orderby.html) +* [SORT BY Clause](sql-ref-syntax-qry-select-sortby.html) +* [CLUSTER BY Clause](sql-ref-syntax-qry-select-clusterby.html) +* [DISTRIBUTE BY Clause](sql-ref-syntax-qry-select-distribute-by.html) +* [LIMIT Clause](sql-ref-syntax-qry-select-limit.html) diff --git a/docs/sql-ref-syntax-qry-select-having.md b/docs/sql-ref-syntax-qry-select-having.md index c8c4f2c38104c..935782c551e1f 100644 --- a/docs/sql-ref-syntax-qry-select-having.md +++ b/docs/sql-ref-syntax-qry-select-having.md @@ -21,39 +21,35 @@ license: | ### Description -The HAVING clause is used to filter the results produced by -GROUP BY based on the specified condition. It is often used +The `HAVING` clause is used to filter the results produced by +`GROUP BY` based on the specified condition. It is often used in conjunction with a [GROUP BY](sql-ref-syntax-qry-select-groupby.html) clause. ### Syntax -{% highlight sql %} +```sql HAVING boolean_expression -{% endhighlight %} +``` ### Parameters -
-
boolean_expression
-
- Specifies any expression that evaluates to a result type boolean. Two or +* **boolean_expression** + + Specifies any expression that evaluates to a result type `boolean`. Two or more expressions may be combined together using the logical - operators ( AND, OR ).

- - Note
- The expressions specified in the HAVING clause can only refer to: -
    -
  1. Constants
  2. -
  3. Expressions that appear in GROUP BY
  4. -
  5. Aggregate functions
  6. -
-
-
+ operators ( `AND`, `OR` ). + + **Note** + + The expressions specified in the `HAVING` clause can only refer to: + 1. Constants + 2. Expressions that appear in GROUP BY + 3. Aggregate functions ### Examples -{% highlight sql %} +```sql CREATE TABLE dealer (id INT, city STRING, car_model STRING, quantity INT); INSERT INTO dealer VALUES (100, 'Fremont', 'Honda Civic', 10), @@ -117,15 +113,15 @@ SELECT sum(quantity) AS sum FROM dealer HAVING sum(quantity) > 10; +---+ | 78| +---+ -{% endhighlight %} +``` ### Related Statements - * [SELECT Main](sql-ref-syntax-qry-select.html) - * [WHERE Clause](sql-ref-syntax-qry-select-where.html) - * [GROUP BY Clause](sql-ref-syntax-qry-select-groupby.html) - * [ORDER BY Clause](sql-ref-syntax-qry-select-orderby.html) - * [SORT BY Clause](sql-ref-syntax-qry-select-sortby.html) - * [CLUSTER BY Clause](sql-ref-syntax-qry-select-clusterby.html) - * [DISTRIBUTE BY Clause](sql-ref-syntax-qry-select-distribute-by.html) - * [LIMIT Clause](sql-ref-syntax-qry-select-limit.html) +* [SELECT Main](sql-ref-syntax-qry-select.html) +* [WHERE Clause](sql-ref-syntax-qry-select-where.html) +* [GROUP BY Clause](sql-ref-syntax-qry-select-groupby.html) +* [ORDER BY Clause](sql-ref-syntax-qry-select-orderby.html) +* [SORT BY Clause](sql-ref-syntax-qry-select-sortby.html) +* [CLUSTER BY Clause](sql-ref-syntax-qry-select-clusterby.html) +* [DISTRIBUTE BY Clause](sql-ref-syntax-qry-select-distribute-by.html) +* [LIMIT Clause](sql-ref-syntax-qry-select-limit.html) diff --git a/docs/sql-ref-syntax-qry-select-hints.md b/docs/sql-ref-syntax-qry-select-hints.md index 16f4f95f90ea1..4bb48b08d5e3b 100644 --- a/docs/sql-ref-syntax-qry-select-hints.md +++ b/docs/sql-ref-syntax-qry-select-hints.md @@ -23,39 +23,33 @@ license: | Join Hints allow users to suggest the join strategy that Spark should use. Prior to Spark 3.0, only the `BROADCAST` Join Hint was supported. `MERGE`, `SHUFFLE_HASH` and `SHUFFLE_REPLICATE_NL` Joint Hints support was added in 3.0. When different join strategy hints are specified on both sides of a join, Spark prioritizes hints in the following order: `BROADCAST` over `MERGE` over `SHUFFLE_HASH` over `SHUFFLE_REPLICATE_NL`. When both sides are specified with the `BROADCAST` hint or the `SHUFFLE_HASH` hint, Spark will pick the build side based on the join type and the sizes of the relations. Since a given strategy may not support all join types, Spark is not guaranteed to use the join strategy suggested by the hint. +### Syntax + +```sql +/*+ join_hint [ , ... ] */ +``` + ### Join Hints Types -
-
BROADCAST
-
- Suggests that Spark use broadcast join. The join side with the hint will be broadcast regardless of autoBroadcastJoinThreshold. If both sides of the join have the broadcast hints, the one with the smaller size (based on stats) will be broadcast. The aliases for BROADCAST are BROADCASTJOIN and MAPJOIN. -
-
- -
-
MERGE
-
- Suggests that Spark use shuffle sort merge join. The aliases for MERGE are SHUFFLE_MERGE and MERGEJOIN. -
-
- -
-
SHUFFLE_HASH
-
- Suggests that Spark use shuffle hash join. If both sides have the shuffle hash hints, Spark chooses the smaller side (based on stats) as the build side. -
-
- -
-
SHUFFLE_REPLICATE_NL
-
+* **BROADCAST** + + Suggests that Spark use broadcast join. The join side with the hint will be broadcast regardless of `autoBroadcastJoinThreshold`. If both sides of the join have the broadcast hints, the one with the smaller size (based on stats) will be broadcast. The aliases for `BROADCAST` are `BROADCASTJOIN` and `MAPJOIN`. + +* **MERGE** + + Suggests that Spark use shuffle sort merge join. The aliases for `MERGE` are `SHUFFLE_MERGE` and `MERGEJOIN`. + +* **SHUFFLE_HASH** + + Suggests that Spark use shuffle hash join. If both sides have the shuffle hash hints, Spark chooses the smaller side (based on stats) as the build side. + +* **SHUFFLE_REPLICATE_NL** + Suggests that Spark use shuffle-and-replicate nested loop join. -
-
### Examples -{% highlight sql %} +```sql -- Join Hints for broadcast join SELECT /*+ BROADCAST(t1) */ * FROM t1 INNER JOIN t2 ON t1.key = t2.key; SELECT /*+ BROADCASTJOIN (t1) */ * FROM t1 left JOIN t2 ON t1.key = t2.key; @@ -78,10 +72,10 @@ SELECT /*+ SHUFFLE_REPLICATE_NL(t1) */ * FROM t1 INNER JOIN t2 ON t1.key = t2.ke -- Spark will issue Warning in the following example -- org.apache.spark.sql.catalyst.analysis.HintErrorLogger: Hint (strategy=merge) -- is overridden by another hint and will not take effect. -SELECT /*+ BROADCAST(t1) */ /*+ MERGE(t1, t2) */ * FROM t1 INNER JOIN t2 ON t1.key = t2.key; -{% endhighlight %} +SELECT /*+ BROADCAST(t1), MERGE(t1, t2) */ * FROM t1 INNER JOIN t2 ON t1.key = t2.key; +``` ### Related Statements - * [JOIN](sql-ref-syntax-qry-select-join.html) - * [SELECT](sql-ref-syntax-qry-select.html) +* [JOIN](sql-ref-syntax-qry-select-join.html) +* [SELECT](sql-ref-syntax-qry-select.html) diff --git a/docs/sql-ref-syntax-qry-select-inline-table.md b/docs/sql-ref-syntax-qry-select-inline-table.md index 9c33cbc679f06..38ecc3da5e14e 100644 --- a/docs/sql-ref-syntax-qry-select-inline-table.md +++ b/docs/sql-ref-syntax-qry-select-inline-table.md @@ -25,32 +25,24 @@ An inline table is a temporary table created using a VALUES clause. ### Syntax -{% highlight sql %} +```sql VALUES ( expression [ , ... ] ) [ table_alias ] -{% endhighlight %} +``` ### Parameters -
-
expression
-
+* **expression** + Specifies a combination of one or more values, operators and SQL functions that results in a value. -
-
-
-
table_alias
-
+ +* **table_alias** + Specifies a temporary name with an optional column name list.

- Syntax: - - [ AS ] table_name [ ( column_name [ , ... ] ) ] - -
-
+ **Syntax:** `[ AS ] table_name [ ( column_name [ , ... ] ) ]` ### Examples -{% highlight sql %} +```sql -- single row, without a table alias SELECT * FROM VALUES ("one", 1); +----+----+ @@ -77,8 +69,8 @@ SELECT * FROM VALUES ("one", array(0, 1)), ("two", array(2, 3)) AS data(a, b); |one|[0, 1]| |two|[2, 3]| +---+------+ -{% endhighlight %} +``` -### Related Statement +### Related Statements - * [SELECT](sql-ref-syntax-qry-select.html) +* [SELECT](sql-ref-syntax-qry-select.html) diff --git a/docs/sql-ref-syntax-qry-select-join.md b/docs/sql-ref-syntax-qry-select-join.md index 0b1bb1eb8fd61..28b21f5e3f0ff 100644 --- a/docs/sql-ref-syntax-qry-select-join.md +++ b/docs/sql-ref-syntax-qry-select-join.md @@ -25,118 +25,95 @@ A SQL join is used to combine rows from two relations based on join criteria. Th ### Syntax -{% highlight sql %} +```sql relation { [ join_type ] JOIN relation [ join_criteria ] | NATURAL join_type JOIN relation } -{% endhighlight %} +``` ### Parameters -
-
relation
-
+* **relation** + Specifies the relation to be joined. -
-
join_type
-
- Specifies the join type.

- Syntax:
- - [ INNER ] - | CROSS - | LEFT [ OUTER ] - | [ LEFT ] SEMI - | RIGHT [ OUTER ] - | FULL [ OUTER ] - | [ LEFT ] ANTI - -
-
join_criteria
-
- Specifies how the rows from one relation will be combined with the rows of another relation.

- Syntax: - - ON boolean_expression | USING ( column_name [ , column_name ... ] ) -

- boolean_expression
- Specifies an expression with a return type of boolean. -
-
+ +* **join_type** + + Specifies the join type. + + **Syntax:** + + `[ INNER ] | CROSS | LEFT [ OUTER ] | [ LEFT ] SEMI | RIGHT [ OUTER ] | FULL [ OUTER ] | [ LEFT ] ANTI` + +* **join_criteria** + + Specifies how the rows from one relation will be combined with the rows of another relation. + + **Syntax:** `ON boolean_expression | USING ( column_name [ , ... ] )` + + `boolean_expression` + + Specifies an expression with a return type of boolean. ### Join Types -#### Inner Join - -
-The inner join is the default join in Spark SQL. It selects rows that have matching values in both relations.

- Syntax:
- - relation [ INNER ] JOIN relation [ join_criteria ] - -
- -#### Left Join - -
-A left join returns all values from the left relation and the matched values from the right relation, or appends NULL if there is no match. It is also referred to as a left outer join.

- Syntax:
- - relation LEFT [ OUTER ] JOIN relation [ join_criteria ] - -
- -#### Right Join - -
-A right join returns all values from the right relation and the matched values from the left relation, or appends NULL if there is no match. It is also referred to as a right outer join.

- Syntax:
- - relation RIGHT [ OUTER ] JOIN relation [ join_criteria ] - -
- -#### Full Join - -
-A full join returns all values from both relations, appending NULL values on the side that does not have a match. It is also referred to as a full outer join.

- Syntax:
- - relation FULL [ OUTER ] JOIN relation [ join_criteria ] - -
- -#### Cross Join - -
-A cross join returns the Cartesian product of two relations.

- Syntax:
- - relation CROSS JOIN relation [ join_criteria ] - -
- -#### Semi Join - -
-A semi join returns values from the left side of the relation that has a match with the right. It is also referred to as a left semi join.

- Syntax:
- - relation [ LEFT ] SEMI JOIN relation [ join_criteria ] - -
- -#### Anti Join - -
-An anti join returns values from the left relation that has no match with the right. It is also referred to as a left anti join.

- Syntax:
- - relation [ LEFT ] ANTI JOIN relation [ join_criteria ] - -
+#### **Inner Join** + +The inner join is the default join in Spark SQL. It selects rows that have matching values in both relations. + +**Syntax:** + +`relation [ INNER ] JOIN relation [ join_criteria ]` + +#### **Left Join** + +A left join returns all values from the left relation and the matched values from the right relation, or appends NULL if there is no match. It is also referred to as a left outer join. + +**Syntax:** + +`relation LEFT [ OUTER ] JOIN relation [ join_criteria ]` + +#### **Right Join** + +A right join returns all values from the right relation and the matched values from the left relation, or appends NULL if there is no match. It is also referred to as a right outer join. + +**Syntax:** + +`relation RIGHT [ OUTER ] JOIN relation [ join_criteria ]` + +#### **Full Join** + +A full join returns all values from both relations, appending NULL values on the side that does not have a match. It is also referred to as a full outer join. + +**Syntax:** + +`relation FULL [ OUTER ] JOIN relation [ join_criteria ]` + +#### **Cross Join** + +A cross join returns the Cartesian product of two relations. + +**Syntax:** + +`relation CROSS JOIN relation [ join_criteria ]` + +#### **Semi Join** + +A semi join returns values from the left side of the relation that has a match with the right. It is also referred to as a left semi join. + +**Syntax:** + +`relation [ LEFT ] SEMI JOIN relation [ join_criteria ]` + +#### **Anti Join** + +An anti join returns values from the left relation that has no match with the right. It is also referred to as a left anti join. + +**Syntax:** + +`relation [ LEFT ] ANTI JOIN relation [ join_criteria ]` ### Examples -{% highlight sql %} +```sql -- Use employee and department tables to demonstrate different type of joins. SELECT * FROM employee; +---+-----+------+ @@ -253,9 +230,9 @@ SELECT * FROM employee ANTI JOIN department ON employee.deptno = department.dept |104| Evan| 4| |106| Amy| 6| +---+-----+------+ -{% endhighlight %} +``` ### Related Statements - * [SELECT](sql-ref-syntax-qry-select.html) - * [Join Hints](sql-ref-syntax-qry-select-hints.html) +* [SELECT](sql-ref-syntax-qry-select.html) +* [Join Hints](sql-ref-syntax-qry-select-hints.html) diff --git a/docs/sql-ref-syntax-qry-select-like.md b/docs/sql-ref-syntax-qry-select-like.md index 408673c532ddd..feb5eb7b3c80d 100644 --- a/docs/sql-ref-syntax-qry-select-like.md +++ b/docs/sql-ref-syntax-qry-select-like.md @@ -25,38 +25,30 @@ A LIKE predicate is used to search for a specific pattern. ### Syntax -{% highlight sql %} +```sql [ NOT ] { LIKE search_pattern [ ESCAPE esc_char ] | RLIKE regex_pattern } -{% endhighlight %} +``` ### Parameters -
-
search_pattern
-
- Specifies a string pattern to be searched by the LIKE clause. It can contain special pattern-matching characters: -
    -
  • %
  • matches zero or more characters. -
  • _
  • matches exactly one character. -
-
-
-
-
esc_char
-
- Specifies the escape character. The default escape character is \. -
-
-
-
regex_pattern
-
- Specifies a regular expression search pattern to be searched by the RLIKE clause. -
-
+* **search_pattern** + + Specifies a string pattern to be searched by the `LIKE` clause. It can contain special pattern-matching characters: + + * `%` matches zero or more characters. + * `_` matches exactly one character. + +* **esc_char** + + Specifies the escape character. The default escape character is `\`. + +* **regex_pattern** + + Specifies a regular expression search pattern to be searched by the `RLIKE` clause. ### Examples -{% highlight sql %} +```sql CREATE TABLE person (id INT, name STRING, age INT); INSERT INTO person VALUES (100, 'John', 30), @@ -90,12 +82,11 @@ SELECT * FROM person WHERE name NOT LIKE 'M_ry'; |400| Dan| 50| +---+------+---+ -SELECT * FROM person WHERE name RLIKE '[MD]'; +SELECT * FROM person WHERE name RLIKE 'M+'; +---+----+----+ | id|name| age| +---+----+----+ |300|Mike| 80| -|400| Dan| 50| |200|Mary|null| +---+----+----+ @@ -112,9 +103,9 @@ SELECT * FROM person WHERE name LIKE '%$_%' ESCAPE '$'; +---+------+---+ |500|Evan_W| 16| +---+------+---+ -{% endhighlight %} +``` ### Related Statements - * [SELECT](sql-ref-syntax-qry-select.html) - * [WHERE Clause](sql-ref-syntax-qry-select-where.html) +* [SELECT](sql-ref-syntax-qry-select.html) +* [WHERE Clause](sql-ref-syntax-qry-select-where.html) diff --git a/docs/sql-ref-syntax-qry-select-limit.md b/docs/sql-ref-syntax-qry-select-limit.md index eaeaed068102f..ec3532214084b 100644 --- a/docs/sql-ref-syntax-qry-select-limit.md +++ b/docs/sql-ref-syntax-qry-select-limit.md @@ -21,34 +21,31 @@ license: | ### Description -The LIMIT clause is used to constrain the number of rows returned by +The `LIMIT` 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 ensure that the results are deterministic. ### Syntax -{% highlight sql %} +```sql LIMIT { ALL | integer_expression } -{% endhighlight %} +``` ### Parameters -
-
ALL
-
+* **ALL** + If specified, the query returns all the rows. In other words, no limit is applied if this option is specified. -
-
integer_expression
-
+ +* **integer_expression** + Specifies a foldable expression that returns an integer. -
-
### Examples -{% highlight sql %} +```sql CREATE TABLE person (name STRING, age INT); INSERT INTO person VALUES ('Zen Hui', 25), @@ -95,15 +92,15 @@ SELECT name, age FROM person ORDER BY name LIMIT length('SPARK'); -- A non-foldable expression as an input to LIMIT is not allowed. SELECT name, age FROM person ORDER BY name LIMIT length(name); org.apache.spark.sql.AnalysisException: The limit expression must evaluate to a constant value ... -{% endhighlight %} +``` ### Related Statements - * [SELECT Main](sql-ref-syntax-qry-select.html) - * [WHERE Clause](sql-ref-syntax-qry-select-where.html) - * [GROUP BY Clause](sql-ref-syntax-qry-select-groupby.html) - * [HAVING Clause](sql-ref-syntax-qry-select-having.html) - * [ORDER BY Clause](sql-ref-syntax-qry-select-orderby.html) - * [SORT BY Clause](sql-ref-syntax-qry-select-sortby.html) - * [CLUSTER BY Clause](sql-ref-syntax-qry-select-clusterby.html) - * [DISTRIBUTE BY Clause](sql-ref-syntax-qry-select-distribute-by.html) +* [SELECT Main](sql-ref-syntax-qry-select.html) +* [WHERE Clause](sql-ref-syntax-qry-select-where.html) +* [GROUP BY Clause](sql-ref-syntax-qry-select-groupby.html) +* [HAVING Clause](sql-ref-syntax-qry-select-having.html) +* [ORDER BY Clause](sql-ref-syntax-qry-select-orderby.html) +* [SORT BY Clause](sql-ref-syntax-qry-select-sortby.html) +* [CLUSTER BY Clause](sql-ref-syntax-qry-select-clusterby.html) +* [DISTRIBUTE BY Clause](sql-ref-syntax-qry-select-distribute-by.html) diff --git a/docs/sql-ref-syntax-qry-select-orderby.md b/docs/sql-ref-syntax-qry-select-orderby.md index d927177398f7f..85bbe514cdc95 100644 --- a/docs/sql-ref-syntax-qry-select-orderby.md +++ b/docs/sql-ref-syntax-qry-select-orderby.md @@ -21,56 +21,48 @@ license: | ### Description -The ORDER BY clause is used to return the result rows in a sorted manner +The `ORDER BY` 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. ### Syntax -{% highlight sql %} +```sql ORDER BY { expression [ sort_direction | nulls_sort_oder ] [ , ... ] } -{% endhighlight %} +``` ### Parameters -
-
ORDER BY
-
- Specifies a comma-separated list of expressions along with optional parameters sort_direction - and nulls_sort_order which are used to sort the rows. -
-
sort_direction
-
+* **ORDER BY** + + Specifies a comma-separated list of expressions along with optional parameters `sort_direction` + and `nulls_sort_order` which are used to sort the rows. + +* **sort_direction** + Optionally specifies whether to sort the rows in ascending or descending - order. The valid values for the sort direction are ASC for ascending - and DESC for descending. If sort direction is not explicitly specified, then by default - rows are sorted ascending.

- Syntax: - - [ ASC | DESC ] - -
-
nulls_sort_order
-
+ order. The valid values for the sort direction are `ASC` for ascending + and `DESC` for descending. If sort direction is not explicitly specified, then by default + rows are sorted ascending. + + **Syntax:** [ ASC `|` DESC ] + +* **nulls_sort_order** + Optionally specifies whether NULL values are returned before/after non-NULL values. If - null_sort_order is not specified, then NULLs sort first if sort order is - ASC and NULLS sort last if sort order is DESC.

-
    -
  1. If NULLS FIRST is specified, then NULL values are returned first - regardless of the sort order.
  2. -
  3. If NULLS LAST is specified, then NULL values are returned last regardless of - the sort order.
  4. -

- Syntax: - - [ NULLS { FIRST | LAST } ] - -
-
+ `null_sort_order` is not specified, then NULLs sort first if sort order is + `ASC` and NULLS sort last if sort order is `DESC`. + + 1. If `NULLS FIRST` is specified, then NULL values are returned first + regardless of the sort order. + 2. If `NULLS LAST` is specified, then NULL values are returned last regardless of + the sort order. + + **Syntax:** `[ NULLS { FIRST | LAST } ]` ### Examples -{% highlight sql %} +```sql CREATE TABLE person (id INT, name STRING, age INT); INSERT INTO person VALUES (100, 'John', 30), @@ -139,15 +131,15 @@ SELECT * FROM person ORDER BY name ASC, age DESC; |200| Mary|null| |300| Mike| 80| +---+-----+----+ -{% endhighlight %} +``` ### Related Statements - * [SELECT Main](sql-ref-syntax-qry-select.html) - * [WHERE Clause](sql-ref-syntax-qry-select-where.html) - * [GROUP BY Clause](sql-ref-syntax-qry-select-groupby.html) - * [HAVING Clause](sql-ref-syntax-qry-select-having.html) - * [SORT BY Clause](sql-ref-syntax-qry-select-sortby.html) - * [CLUSTER BY Clause](sql-ref-syntax-qry-select-clusterby.html) - * [DISTRIBUTE BY Clause](sql-ref-syntax-qry-select-distribute-by.html) - * [LIMIT Clause](sql-ref-syntax-qry-select-limit.html) +* [SELECT Main](sql-ref-syntax-qry-select.html) +* [WHERE Clause](sql-ref-syntax-qry-select-where.html) +* [GROUP BY Clause](sql-ref-syntax-qry-select-groupby.html) +* [HAVING Clause](sql-ref-syntax-qry-select-having.html) +* [SORT BY Clause](sql-ref-syntax-qry-select-sortby.html) +* [CLUSTER BY Clause](sql-ref-syntax-qry-select-clusterby.html) +* [DISTRIBUTE BY Clause](sql-ref-syntax-qry-select-distribute-by.html) +* [LIMIT Clause](sql-ref-syntax-qry-select-limit.html) diff --git a/docs/sql-ref-syntax-qry-select-setops.md b/docs/sql-ref-syntax-qry-select-setops.md index 98c20941d16bf..8cd12c37fa603 100644 --- a/docs/sql-ref-syntax-qry-select-setops.md +++ b/docs/sql-ref-syntax-qry-select-setops.md @@ -35,13 +35,13 @@ Note that input relations must have the same number of columns and compatible da #### Syntax -{% highlight sql %} +```sql [ ( ] relation [ ) ] EXCEPT | MINUS [ ALL | DISTINCT ] [ ( ] relation [ ) ] -{% endhighlight %} +``` #### Examples -{% highlight sql %} +```sql -- Use number1 and number2 tables to demonstrate set operators in this page. SELECT * FROM number1; +---+ @@ -98,7 +98,7 @@ SELECT c FROM number1 MINUS ALL (SELECT c FROM number2); | 3| | 4| +---+ -{% endhighlight %} +``` ### INTERSECT @@ -106,13 +106,13 @@ SELECT c FROM number1 MINUS ALL (SELECT c FROM number2); #### Syntax -{% highlight sql %} +```sql [ ( ] relation [ ) ] INTERSECT [ ALL | DISTINCT ] [ ( ] relation [ ) ] -{% endhighlight %} +``` #### Examples -{% highlight sql %} +```sql (SELECT c FROM number1) INTERSECT (SELECT c FROM number2); +---+ | c| @@ -137,7 +137,7 @@ SELECT c FROM number1 MINUS ALL (SELECT c FROM number2); | 2| | 2| +---+ -{% endhighlight %} +``` ### UNION @@ -145,13 +145,13 @@ SELECT c FROM number1 MINUS ALL (SELECT c FROM number2); #### Syntax -{% highlight sql %} +```sql [ ( ] relation [ ) ] UNION [ ALL | DISTINCT ] [ ( ] relation [ ) ] -{% endhighlight %} +``` ### Examples -{% highlight sql %} +```sql (SELECT c FROM number1) UNION (SELECT c FROM number2); +---+ | c| @@ -189,8 +189,8 @@ SELECT c FROM number1 UNION ALL (SELECT c FROM number2); | 2| | 2| +---+ -{% endhighlight %} +``` ### Related Statements - * [SELECT Statement](sql-ref-syntax-qry-select.html) +* [SELECT Statement](sql-ref-syntax-qry-select.html) diff --git a/docs/sql-ref-syntax-qry-select-sortby.md b/docs/sql-ref-syntax-qry-select-sortby.md index 1dfa10429709e..554bdb569d005 100644 --- a/docs/sql-ref-syntax-qry-select-sortby.md +++ b/docs/sql-ref-syntax-qry-select-sortby.md @@ -21,58 +21,50 @@ license: | ### Description -The SORT BY clause is used to return the result rows sorted +The `SORT BY` clause is used to return the result rows sorted within each partition in the user specified order. When there is more than one partition -SORT BY may return result that is partially ordered. This is different +`SORT BY` may return result that is partially ordered. This is different than [ORDER BY](sql-ref-syntax-qry-select-orderby.html) clause which guarantees a total order of the output. ### Syntax -{% highlight sql %} +```sql SORT BY { expression [ sort_direction | nulls_sort_order ] [ , ... ] } -{% endhighlight %} +``` ### Parameters -
-
SORT BY
-
- Specifies a comma-separated list of expressions along with optional parameters sort_direction - and nulls_sort_order which are used to sort the rows within each partition. -
-
sort_direction
-
+* **SORT BY** + + Specifies a comma-separated list of expressions along with optional parameters `sort_direction` + and `nulls_sort_order` which are used to sort the rows within each partition. + +* **sort_direction** + Optionally specifies whether to sort the rows in ascending or descending - order. The valid values for the sort direction are ASC for ascending - and DESC for descending. If sort direction is not explicitly specified, then by default - rows are sorted ascending.

- Syntax: - - [ ASC | DESC ] - -
-
nulls_sort_order
-
+ order. The valid values for the sort direction are `ASC` for ascending + and `DESC` for descending. If sort direction is not explicitly specified, then by default + rows are sorted ascending. + + **Syntax:** `[ ASC | DESC ]` + +* **nulls_sort_order** + Optionally specifies whether NULL values are returned before/after non-NULL values. If - null_sort_order is not specified, then NULLs sort first if sort order is - ASC and NULLS sort last if sort order is DESC.

-
    -
  1. If NULLS FIRST is specified, then NULL values are returned first - regardless of the sort order.
  2. -
  3. If NULLS LAST is specified, then NULL values are returned last regardless of - the sort order.
  4. -

- Syntax: - - [ NULLS { FIRST | LAST } ] - -
-
+ `null_sort_order` is not specified, then NULLs sort first if sort order is + `ASC` and NULLS sort last if sort order is `DESC`. + + 1. If `NULLS FIRST` is specified, then NULL values are returned first + regardless of the sort order. + 2. If `NULLS LAST` is specified, then NULL values are returned last regardless of + the sort order. + + **Syntax:** `[ NULLS { FIRST | LAST } ]` ### Examples -{% highlight sql %} +```sql CREATE TABLE person (zip_code INT, name STRING, age INT); INSERT INTO person VALUES (94588, 'Zen Hui', 50), @@ -172,15 +164,15 @@ SELECT /*+ REPARTITION(zip_code) */ name, age, zip_code FROM person | David K| 42| 94511| |Lalit B.|null| 94511| +--------+----+--------+ -{% endhighlight %} +``` ### Related Statements - * [SELECT Main](sql-ref-syntax-qry-select.html) - * [WHERE Clause](sql-ref-syntax-qry-select-where.html) - * [GROUP BY Clause](sql-ref-syntax-qry-select-groupby.html) - * [HAVING Clause](sql-ref-syntax-qry-select-having.html) - * [ORDER BY Clause](sql-ref-syntax-qry-select-orderby.html) - * [CLUSTER BY Clause](sql-ref-syntax-qry-select-clusterby.html) - * [DISTRIBUTE BY Clause](sql-ref-syntax-qry-select-distribute-by.html) - * [LIMIT Clause](sql-ref-syntax-qry-select-limit.html) +* [SELECT Main](sql-ref-syntax-qry-select.html) +* [WHERE Clause](sql-ref-syntax-qry-select-where.html) +* [GROUP BY Clause](sql-ref-syntax-qry-select-groupby.html) +* [HAVING Clause](sql-ref-syntax-qry-select-having.html) +* [ORDER BY Clause](sql-ref-syntax-qry-select-orderby.html) +* [CLUSTER BY Clause](sql-ref-syntax-qry-select-clusterby.html) +* [DISTRIBUTE BY Clause](sql-ref-syntax-qry-select-distribute-by.html) +* [LIMIT Clause](sql-ref-syntax-qry-select-limit.html) diff --git a/docs/sql-ref-syntax-qry-select-tvf.md b/docs/sql-ref-syntax-qry-select-tvf.md index 1d9505a2bc11b..89ad01aff2167 100644 --- a/docs/sql-ref-syntax-qry-select-tvf.md +++ b/docs/sql-ref-syntax-qry-select-tvf.md @@ -25,41 +25,53 @@ A table-valued function (TVF) is a function that returns a relation or a set of ### Syntax -{% highlight sql %} +```sql function_name ( expression [ , ... ] ) [ table_alias ] -{% endhighlight %} +``` ### Parameters -
-
expression
-
+* **expression** + Specifies a combination of one or more values, operators and SQL functions that results in a value. -
-
-
-
table_alias
-
- Specifies a temporary name with an optional column name list.

- Syntax: - - [ AS ] table_name [ ( column_name [ , ... ] ) ] - -
-
+ +* **table_alias** + + Specifies a temporary name with an optional column name list. + + **Syntax:** `[ AS ] table_name [ ( column_name [ , ... ] ) ]` ### Supported Table-valued Functions -|Function|Argument Type(s)|Description| -|--------|----------------|-----------| -|**range** ( *end* )|Long|Creates a table with a single *LongType* column named *id*,
containing rows in a range from 0 to *end* (exclusive) with step value 1.| -|**range** ( *start, end* )|Long, Long|Creates a table with a single *LongType* column named *id*,
containing rows in a range from *start* to *end* (exclusive) with step value 1.| -|**range** ( *start, end, step* )|Long, Long, Long|Creates a table with a single *LongType* column named *id*,
containing rows in a range from *start* to *end* (exclusive) with *step* value.| -|**range** ( *start, end, step, numPartitions* )|Long, Long, Long, Int|Creates a table with a single *LongType* column named *id*,
containing rows in a range from *start* to *end* (exclusive) with *step* value, with partition number *numPartitions* specified.| + + + + + + + + + + + + + + + + + + + + + + + + +
FunctionArgument Type(s)Description
range ( end ) Long Creates a table with a single LongType column named id, containing rows in a range from 0 to end (exclusive) with step value 1.
range ( start, end ) Long, Long Creates a table with a single LongType column named id, containing rows in a range from start to end (exclusive) with step value 1.
range ( start, end, step ) Long, Long, Long Creates a table with a single LongType column named id, containing rows in a range from start to end (exclusive) with step value.
range ( start, end, step, numPartitions ) Long, Long, Long, Int Creates a table with a single LongType column named id, containing rows in a range from start to end (exclusive) with step value, with partition number numPartitions specified.
### Examples -{% highlight sql %} +```sql -- range call with end SELECT * FROM range(6 + cos(3)); +---+ @@ -105,8 +117,8 @@ SELECT * FROM range(5, 8) AS test; | 6| | 7| +---+ -{% endhighlight %} +``` -### Related Statement +### Related Statements - * [SELECT](sql-ref-syntax-qry-select.html) +* [SELECT](sql-ref-syntax-qry-select.html) diff --git a/docs/sql-ref-syntax-qry-select-usedb.md b/docs/sql-ref-syntax-qry-select-usedb.md index bb95a8e4ddf30..4119a4927bc9f 100644 --- a/docs/sql-ref-syntax-qry-select-usedb.md +++ b/docs/sql-ref-syntax-qry-select-usedb.md @@ -28,32 +28,29 @@ The default database name is 'default'. ### Syntax -{% highlight sql %} +```sql USE database_name -{% endhighlight %} +``` ### Parameter -
-
database_name
-
- Name of the database will be used. If the database does not exist, an exception will be thrown. -
-
+* **database_name** + + Name of the database will be used. If the database does not exist, an exception will be thrown. ### Examples -{% highlight sql %} +```sql -- Use the 'userdb' which exists. USE userdb; -- Use the 'userdb1' which doesn't exist USE userdb1; Error: org.apache.spark.sql.catalyst.analysis.NoSuchDatabaseException: Database 'userdb1' not found;(state=,code=0) -{% endhighlight %} +``` ### Related Statements - * [CREATE DATABASE](sql-ref-syntax-ddl-create-database.html) - * [DROP DATABASE](sql-ref-syntax-ddl-drop-database.html) - * [CREATE TABLE ](sql-ref-syntax-ddl-create-table.html) +* [CREATE DATABASE](sql-ref-syntax-ddl-create-database.html) +* [DROP DATABASE](sql-ref-syntax-ddl-drop-database.html) +* [CREATE TABLE ](sql-ref-syntax-ddl-create-table.html) diff --git a/docs/sql-ref-syntax-qry-select-where.md b/docs/sql-ref-syntax-qry-select-where.md index 360313fcfff1c..ca3f5ec7866c6 100644 --- a/docs/sql-ref-syntax-qry-select-where.md +++ b/docs/sql-ref-syntax-qry-select-where.md @@ -21,29 +21,26 @@ license: | ### Description -The WHERE clause is used to limit the results of the FROM +The `WHERE` clause is used to limit the results of the `FROM` clause of a query or a subquery based on the specified condition. ### Syntax -{% highlight sql %} +```sql WHERE boolean_expression -{% endhighlight %} +``` ### Parameters -
-
boolean_expression
-
- Specifies any expression that evaluates to a result type boolean. Two or +* **boolean_expression** + + Specifies any expression that evaluates to a result type `boolean`. Two or more expressions may be combined together using the logical - operators ( AND, OR ). -
-
+ operators ( `AND`, `OR` ). ### Examples -{% highlight sql %} +```sql CREATE TABLE person (id INT, name STRING, age INT); INSERT INTO person VALUES (100, 'John', 30), @@ -116,15 +113,15 @@ SELECT * FROM person AS parent +---+----+----+ |200|Mary|null| +---+----+----+ -{% endhighlight %} +``` ### Related Statements - * [SELECT Main](sql-ref-syntax-qry-select.html) - * [GROUP BY Clause](sql-ref-syntax-qry-select-groupby.html) - * [HAVING Clause](sql-ref-syntax-qry-select-having.html) - * [ORDER BY Clause](sql-ref-syntax-qry-select-orderby.html) - * [SORT BY Clause](sql-ref-syntax-qry-select-sortby.html) - * [CLUSTER BY Clause](sql-ref-syntax-qry-select-clusterby.html) - * [DISTRIBUTE BY Clause](sql-ref-syntax-qry-select-distribute-by.html) - * [LIMIT Clause](sql-ref-syntax-qry-select-limit.html) +* [SELECT Main](sql-ref-syntax-qry-select.html) +* [GROUP BY Clause](sql-ref-syntax-qry-select-groupby.html) +* [HAVING Clause](sql-ref-syntax-qry-select-having.html) +* [ORDER BY Clause](sql-ref-syntax-qry-select-orderby.html) +* [SORT BY Clause](sql-ref-syntax-qry-select-sortby.html) +* [CLUSTER BY Clause](sql-ref-syntax-qry-select-clusterby.html) +* [DISTRIBUTE BY Clause](sql-ref-syntax-qry-select-distribute-by.html) +* [LIMIT Clause](sql-ref-syntax-qry-select-limit.html) diff --git a/docs/sql-ref-syntax-qry-select.md b/docs/sql-ref-syntax-qry-select.md index bc2cc0269124e..1aeecdb982c4c 100644 --- a/docs/sql-ref-syntax-qry-select.md +++ b/docs/sql-ref-syntax-qry-select.md @@ -28,7 +28,7 @@ of a query along with examples. ### Syntax -{% highlight sql %} +```sql [ WITH with_query [ , ... ] ] select_statement [ { UNION | INTERSECT | EXCEPT } [ ALL | DISTINCT ] select_statement, ... ] [ ORDER BY { expression [ ASC | DESC ] [ NULLS { FIRST | LAST } ] [ , ...] } ] @@ -37,126 +37,125 @@ select_statement [ { UNION | INTERSECT | EXCEPT } [ ALL | DISTINCT ] select_stat [ DISTRIBUTE BY { expression [, ...] } ] [ WINDOW { named_window [ , WINDOW named_window, ... ] } ] [ LIMIT { ALL | expression } ] -{% endhighlight %} +``` While `select_statement` is defined as -{% highlight sql %} +```sql SELECT [ hints , ... ] [ ALL | DISTINCT ] { named_expression [ , ... ] } FROM { from_item [ , ...] } [ WHERE boolean_expression ] [ GROUP BY expression [ , ...] ] [ HAVING boolean_expression ] -{% endhighlight %} +``` ### Parameters -
-
with_query
-
- Specifies the common table expressions (CTEs) before the main query block. +* **with_query** + + Specifies the [common table expressions (CTEs)](sql-ref-syntax-qry-select-cte.html) before the main query block. 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** + 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. -
-
ALL
-
+ +* **ALL** + Select all matching rows from the relation and is enabled by default. -
-
DISTINCT
-
+ +* **DISTINCT** + Select all matching rows from the relation after removing duplicates in results. -
-
named_expression
-
- An expression with an assigned name. In general, it denotes a column expression.

- Syntax: - - expression [AS] [alias] - -
-
from_item
-
- Specifies a source of input for the query. It can be one of the following: -
    -
  1. Table relation
  2. -
  3. Join relation
  4. -
  5. Table-value function
  6. -
  7. Inline table
  8. -
  9. Subquery
  10. -
-
-
WHERE
-
- Filters the result of the FROM clause based on the supplied predicates. -
-
GROUP BY
-
- 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
-
- 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
-
- 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
-
- 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
-
- 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
-
- 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
-
- 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. -
-
boolean_expression
-
- Specifies an expression with a return type of boolean. -
-
expression
-
- Specifies a combination of one or more values, operators, and SQL functions that evaluates to a value. -
-
named_window
-
- Specifies aliases for one or more source window specifications. The source window specifications can - be referenced in the widow definitions in the query. -
-
+ +* **named_expression** + + An expression with an assigned name. In general, it denotes a column expression. + + **Syntax:** `expression [AS] [alias]` + + * **from_item** + + Specifies a source of input for the query. It can be one of the following: + * Table relation + * [Join relation](sql-ref-syntax-qry-select-join.html) + * [Table-value function](sql-ref-syntax-qry-select-tvf.html) + * [Inline table](sql-ref-syntax-qry-select-inline-table.html) + * Subquery + + + * **WHERE** + + Filters the result of the FROM clause based on the supplied predicates. + + * **GROUP BY** + + 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** + + 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** + + 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** + + 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** + + 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** + + 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** + + 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. + + * **boolean_expression** + + Specifies an expression with a return type of boolean. + + * **expression** + + Specifies a combination of one or more values, operators, and SQL functions that evaluates to a value. + + * **named_window** + + Specifies aliases for one or more source window specifications. The source window specifications can + be referenced in the widow definitions in the query. ### Related Statements - * [WHERE Clause](sql-ref-syntax-qry-select-where.html) - * [GROUP BY Clause](sql-ref-syntax-qry-select-groupby.html) - * [HAVING Clause](sql-ref-syntax-qry-select-having.html) - * [ORDER BY Clause](sql-ref-syntax-qry-select-orderby.html) - * [SORT BY Clause](sql-ref-syntax-qry-select-sortby.html) - * [CLUSTER BY Clause](sql-ref-syntax-qry-select-clusterby.html) - * [DISTRIBUTE BY Clause](sql-ref-syntax-qry-select-distribute-by.html) - * [LIMIT Clause](sql-ref-syntax-qry-select-limit.html) - * [TABLESAMPLE](sql-ref-syntax-qry-sampling.html) - * [JOIN](sql-ref-syntax-qry-select-join.html) - * [SET Operators](sql-ref-syntax-qry-select-setops.html) - * [Common Table Expression](sql-ref-syntax-qry-select-cte.html) +* [WHERE Clause](sql-ref-syntax-qry-select-where.html) +* [GROUP BY Clause](sql-ref-syntax-qry-select-groupby.html) +* [HAVING Clause](sql-ref-syntax-qry-select-having.html) +* [ORDER BY Clause](sql-ref-syntax-qry-select-orderby.html) +* [SORT BY Clause](sql-ref-syntax-qry-select-sortby.html) +* [CLUSTER BY Clause](sql-ref-syntax-qry-select-clusterby.html) +* [DISTRIBUTE BY Clause](sql-ref-syntax-qry-select-distribute-by.html) +* [LIMIT Clause](sql-ref-syntax-qry-select-limit.html) +* [Common Table Expression](sql-ref-syntax-qry-select-cte.html) +* [Inline Table](sql-ref-syntax-qry-select-inline-table.html) +* [JOIN](sql-ref-syntax-qry-select-join.html) +* [Join Hints](sql-ref-syntax-qry-select-hints.html) +* [LIKE Predicate](sql-ref-syntax-qry-select-like.html) +* [Set Operators](sql-ref-syntax-qry-select-setops.html) +* [TABLESAMPLE](sql-ref-syntax-qry-sampling.html) +* [Table-valued Function](sql-ref-syntax-qry-select-tvf.html) +* [Window Function](sql-ref-syntax-qry-window.html) diff --git a/docs/sql-ref-syntax-qry-window.md b/docs/sql-ref-syntax-qry-window.md index e3762925760e2..9c03b65fec3eb 100644 --- a/docs/sql-ref-syntax-qry-window.md +++ b/docs/sql-ref-syntax-qry-window.md @@ -25,67 +25,52 @@ Window functions operate on a group of rows, referred to as a window, and calcul ### Syntax -{% highlight sql %} +```sql window_function OVER ( [ { PARTITION | DISTRIBUTE } BY partition_col_name = partition_col_val ( [ , ... ] ) ] { ORDER | SORT } BY expression [ ASC | DESC ] [ NULLS { FIRST | LAST } ] [ , ... ] [ window_frame ] ) -{% endhighlight %} +``` ### Parameters -
-
window_function
-
-
    -
  • Ranking Functions
  • -
    - Syntax: - - RANK | DENSE_RANK | PERCENT_RANK | NTILE | ROW_NUMBER - -
-
    -
  • Analytic Functions
  • -
    - Syntax: - - CUME_DIST | LAG | LEAD - -
-
    -
  • Aggregate Functions
  • -
    - Syntax: - - MAX | MIN | COUNT | SUM | AVG | ... - -
    - Please refer to the Built-in Functions document for a complete list of Spark aggregate functions. -
-
-
-
-
window_frame
-
+* **window_function** + + * Ranking Functions + + **Syntax:** `RANK | DENSE_RANK | PERCENT_RANK | NTILE | ROW_NUMBER` + + * Analytic Functions + + **Syntax:** `CUME_DIST | LAG | LEAD` + + * Aggregate Functions + + **Syntax:** `MAX | MIN | COUNT | SUM | AVG | ...` + + Please refer to the [Built-in Aggregation Functions](sql-ref-functions-builtin.html#aggregate-functions) document for a complete list of Spark aggregate functions. + +* **window_frame** + Specifies which row to start the window on and where to end it.
- Syntax:
- { RANGE | ROWS } { frame_start | BETWEEN frame_start AND frame_end }
- If frame_end is omitted it defaults to CURRENT ROW.

-
    - frame_start and frame_end have the following syntax
    - Syntax:
    - - UNBOUNDED PRECEDING | offset PRECEDING | CURRENT ROW | offset FOLLOWING | UNBOUNDED FOLLOWING -
    - offset:specifies the offset from the position of the current row. -
-
-
+ + **Syntax:** + + `{ RANGE | ROWS } { frame_start | BETWEEN frame_start AND frame_end }` + + If frame_end is omitted it defaults to CURRENT ROW. + + `frame_start` and `frame_end` have the following syntax + + **Syntax:** + + `UNBOUNDED PRECEDING | offset PRECEDING | CURRENT ROW | offset FOLLOWING | UNBOUNDED FOLLOWING` + + `offset:` specifies the offset from the position of the current row. ### Examples -{% highlight sql %} +```sql CREATE TABLE employees (name STRING, dept STRING, salary INT, age INT); INSERT INTO employees VALUES ("Lisa", "Sales", 10000, 35); @@ -199,8 +184,8 @@ SELECT name, salary, | Jane| Marketing| 29000|29000|35000| | Jeff| Marketing| 35000|29000| 0| +-----+-----------+------+-----+-----+ -{% endhighlight %} +``` ### Related Statements - * [SELECT](sql-ref-syntax-qry-select.html) +* [SELECT](sql-ref-syntax-qry-select.html) diff --git a/docs/sql-ref-syntax-qry.md b/docs/sql-ref-syntax-qry.md index 325c9b69f12f9..1171fead55e30 100644 --- a/docs/sql-ref-syntax-qry.md +++ b/docs/sql-ref-syntax-qry.md @@ -27,20 +27,21 @@ to SELECT are also included in this section. Spark also provides the ability to generate logical and physical plan for a given query using [EXPLAIN](sql-ref-syntax-qry-explain.html) statement. - * [WHERE Clause](sql-ref-syntax-qry-select-where.html) - * [GROUP BY Clause](sql-ref-syntax-qry-select-groupby.html) - * [HAVING Clause](sql-ref-syntax-qry-select-having.html) - * [ORDER BY Clause](sql-ref-syntax-qry-select-orderby.html) - * [SORT BY Clause](sql-ref-syntax-qry-select-sortby.html) - * [CLUSTER BY Clause](sql-ref-syntax-qry-select-clusterby.html) - * [DISTRIBUTE BY Clause](sql-ref-syntax-qry-select-distribute-by.html) - * [LIMIT Clause](sql-ref-syntax-qry-select-limit.html) - * [JOIN](sql-ref-syntax-qry-select-join.html) - * [Join Hints](sql-ref-syntax-qry-select-hints.html) - * [Set Operators](sql-ref-syntax-qry-select-setops.html) - * [TABLESAMPLE](sql-ref-syntax-qry-sampling.html) - * [Table-valued Function](sql-ref-syntax-qry-select-tvf.html) - * [Inline Table](sql-ref-syntax-qry-select-inline-table.html) - * [Common Table Expression](sql-ref-syntax-qry-select-cte.html) - * [Window Function](sql-ref-syntax-qry-window.html) - * [EXPLAIN Statement](sql-ref-syntax-qry-explain.html) +* [WHERE Clause](sql-ref-syntax-qry-select-where.html) +* [GROUP BY Clause](sql-ref-syntax-qry-select-groupby.html) +* [HAVING Clause](sql-ref-syntax-qry-select-having.html) +* [ORDER BY Clause](sql-ref-syntax-qry-select-orderby.html) +* [SORT BY Clause](sql-ref-syntax-qry-select-sortby.html) +* [CLUSTER BY Clause](sql-ref-syntax-qry-select-clusterby.html) +* [DISTRIBUTE BY Clause](sql-ref-syntax-qry-select-distribute-by.html) +* [LIMIT Clause](sql-ref-syntax-qry-select-limit.html) +* [Common Table Expression](sql-ref-syntax-qry-select-cte.html) +* [Inline Table](sql-ref-syntax-qry-select-inline-table.html) +* [JOIN](sql-ref-syntax-qry-select-join.html) +* [Join Hints](sql-ref-syntax-qry-select-hints.html) +* [LIKE Predicate](sql-ref-syntax-qry-select-like.html) +* [Set Operators](sql-ref-syntax-qry-select-setops.html) +* [TABLESAMPLE](sql-ref-syntax-qry-sampling.html) +* [Table-valued Function](sql-ref-syntax-qry-select-tvf.html) +* [Window Function](sql-ref-syntax-qry-window.html) +* [EXPLAIN Statement](sql-ref-syntax-qry-explain.html) From f7bf42826e5c6f1fa179b0569badf0474c8a532a Mon Sep 17 00:00:00 2001 From: Huaxin Gao Date: Mon, 4 May 2020 09:13:37 -0700 Subject: [PATCH 02/10] fix --- docs/sql-ref-syntax-aux-analyze-table.md | 2 +- docs/sql-ref-syntax-aux-show-functions.md | 2 +- docs/sql-ref-syntax-aux-show.md | 4 ++-- docs/sql-ref-syntax-ddl-alter-table.md | 4 ---- docs/sql-ref-syntax-ddl-create-function.md | 6 ++++-- docs/sql-ref-syntax-ddl-create-table-datasource.md | 2 +- 6 files changed, 9 insertions(+), 11 deletions(-) diff --git a/docs/sql-ref-syntax-aux-analyze-table.md b/docs/sql-ref-syntax-aux-analyze-table.md index a8e11303432ba..8f43d7388d7db 100644 --- a/docs/sql-ref-syntax-aux-analyze-table.md +++ b/docs/sql-ref-syntax-aux-analyze-table.md @@ -47,7 +47,7 @@ ANALYZE TABLE table_identifier [ partition_spec ] * **[ NOSCAN `|` FOR COLUMNS col [ , ... ] `|` FOR ALL COLUMNS ]** - * If no analyze option is specified, `ANALYZE TABLE` collects the table's number of rows and size in bytes. + * If no analyze option is specified, `ANALYZE TABLE` collects the table's number of rows and size in bytes. * **NOSCAN** Collects only the table's size in bytes ( which does not require scanning the entire table ). diff --git a/docs/sql-ref-syntax-aux-show-functions.md b/docs/sql-ref-syntax-aux-show-functions.md index 2cfca0f34bf77..942d6a5409ca4 100644 --- a/docs/sql-ref-syntax-aux-show-functions.md +++ b/docs/sql-ref-syntax-aux-show-functions.md @@ -49,7 +49,7 @@ SHOW [ function_kind ] FUNCTIONS [ [ LIKE ] { function_name | regex_pattern } ] a database then the function is resolved from the user specified database, otherwise it is resolved from the current database. - **Syntax:** `[database_name.]function_name` + **Syntax:** `[ database_name. ] function_name` * **regex_pattern** diff --git a/docs/sql-ref-syntax-aux-show.md b/docs/sql-ref-syntax-aux-show.md index 424fe71370897..9f64ea2d50ae1 100644 --- a/docs/sql-ref-syntax-aux-show.md +++ b/docs/sql-ref-syntax-aux-show.md @@ -20,11 +20,11 @@ license: | --- * [SHOW COLUMNS](sql-ref-syntax-aux-show-columns.html) + * [SHOW CREATE TABLE](sql-ref-syntax-aux-show-create-table.html) * [SHOW DATABASES](sql-ref-syntax-aux-show-databases.html) * [SHOW FUNCTIONS](sql-ref-syntax-aux-show-functions.html) + * [SHOW PARTITIONS](sql-ref-syntax-aux-show-partitions.html) * [SHOW TABLE EXTENDED](sql-ref-syntax-aux-show-table.html) * [SHOW TABLES](sql-ref-syntax-aux-show-tables.html) * [SHOW TBLPROPERTIES](sql-ref-syntax-aux-show-tblproperties.html) - * [SHOW PARTITIONS](sql-ref-syntax-aux-show-partitions.html) - * [SHOW CREATE TABLE](sql-ref-syntax-aux-show-create-table.html) * [SHOW VIEWS](sql-ref-syntax-aux-show-views.html) diff --git a/docs/sql-ref-syntax-ddl-alter-table.md b/docs/sql-ref-syntax-ddl-alter-table.md index dc3f52344c43a..7a109d91d16bf 100644 --- a/docs/sql-ref-syntax-ddl-alter-table.md +++ b/docs/sql-ref-syntax-ddl-alter-table.md @@ -71,8 +71,6 @@ ALTER TABLE table_identifier ADD COLUMNS ( col_spec [ , ... ] ) Specifies the columns to be added. - **Syntax:** `PARTITION ( partition_col_name = partition_col_val [ , ... ] )` - ### ALTER OR CHANGE COLUMN `ALTER TABLE ALTER COLUMN` or `ALTER TABLE CHANGE COLUMN` statement changes column's comment. @@ -95,8 +93,6 @@ ALTER TABLE table_identifier { ALTER | CHANGE } [ COLUMN ] col_spec alterColumnA Specifies the columns to be added. - **Syntax:** `PARTITION ( partition_col_name = partition_col_val [ , ... ] )` - * **alterColumnAction** Change the comment string. diff --git a/docs/sql-ref-syntax-ddl-create-function.md b/docs/sql-ref-syntax-ddl-create-function.md index e66df5352b1b5..aa6c1fad7b56b 100644 --- a/docs/sql-ref-syntax-ddl-create-function.md +++ b/docs/sql-ref-syntax-ddl-create-function.md @@ -55,8 +55,10 @@ CREATE [ OR REPLACE ] [ TEMPORARY ] FUNCTION [ IF NOT EXISTS ] * **IF NOT EXISTS** - Specifies a name of function to be created. The function name may be - optionally qualified with a database name. + If specified, creates the function only when it does not exist. The creation + of function succeeds (no error is thrown) if the specified function already + exists in the system. This parameter is mutually exclusive to `OR REPLACE` + and can not be specified together. * **function_name** diff --git a/docs/sql-ref-syntax-ddl-create-table-datasource.md b/docs/sql-ref-syntax-ddl-create-table-datasource.md index b592116c2a9e4..bb7215ab06876 100644 --- a/docs/sql-ref-syntax-ddl-create-table-datasource.md +++ b/docs/sql-ref-syntax-ddl-create-table-datasource.md @@ -65,7 +65,7 @@ as any order. For example, you can write COMMENT table_comment after TBLPROPERTI **NOTE:** Bucketing is an optimization technique that uses buckets (and bucketing columns) to determine data partitioning and avoid data shuffle. -* **SORTED BY** + **SORTED BY** Determines the order in which the data is stored in buckets. Default is Ascending order. From 365492890678721d5399e5649ccd4223e84a9132 Mon Sep 17 00:00:00 2001 From: Huaxin Gao Date: Mon, 4 May 2020 10:34:02 -0700 Subject: [PATCH 03/10] fix --- docs/sql-ref-syntax-ddl-create-table-datasource.md | 2 +- docs/sql-ref-syntax-ddl-create-table-hiveformat.md | 2 +- docs/sql-ref-syntax-ddl-create-table-like.md | 2 +- docs/sql-ref-syntax-qry-window.md | 10 +++++----- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/docs/sql-ref-syntax-ddl-create-table-datasource.md b/docs/sql-ref-syntax-ddl-create-table-datasource.md index bb7215ab06876..b592116c2a9e4 100644 --- a/docs/sql-ref-syntax-ddl-create-table-datasource.md +++ b/docs/sql-ref-syntax-ddl-create-table-datasource.md @@ -65,7 +65,7 @@ as any order. For example, you can write COMMENT table_comment after TBLPROPERTI **NOTE:** Bucketing is an optimization technique that uses buckets (and bucketing columns) to determine data partitioning and avoid data shuffle. - **SORTED BY** +* **SORTED BY** Determines the order in which the data is stored in buckets. Default is Ascending order. diff --git a/docs/sql-ref-syntax-ddl-create-table-hiveformat.md b/docs/sql-ref-syntax-ddl-create-table-hiveformat.md index 576d9190f2716..7f7033fcaebaf 100644 --- a/docs/sql-ref-syntax-ddl-create-table-hiveformat.md +++ b/docs/sql-ref-syntax-ddl-create-table-hiveformat.md @@ -67,7 +67,7 @@ as any order. For example, you can write COMMENT table_comment after TBLPROPERTI * **LOCATION** - Path to the directory where table data is stored, Path to the directory where table data is stored, which could be a path on distributed storage like HDFS, etc. + Path to the directory where table data is stored, which could be a path on distributed storage like HDFS, etc. * **COMMENT** diff --git a/docs/sql-ref-syntax-ddl-create-table-like.md b/docs/sql-ref-syntax-ddl-create-table-like.md index a374c554bd179..23d8e4f9712a6 100644 --- a/docs/sql-ref-syntax-ddl-create-table-like.md +++ b/docs/sql-ref-syntax-ddl-create-table-like.md @@ -60,7 +60,7 @@ CREATE TABLE [IF NOT EXISTS] table_identifier LIKE source_table_identifier * **LOCATION** - Path to the directory where table data is stored,Path to the directory where table data is stored, which could be a path on distributed storage like HDFS, etc. Location to create an external table. + Path to the directory where table data is stored, which could be a path on distributed storage like HDFS, etc. Location to create an external table. ### Examples diff --git a/docs/sql-ref-syntax-qry-window.md b/docs/sql-ref-syntax-qry-window.md index 9c03b65fec3eb..823ffa2677624 100644 --- a/docs/sql-ref-syntax-qry-window.md +++ b/docs/sql-ref-syntax-qry-window.md @@ -58,15 +58,15 @@ window_function OVER `{ RANGE | ROWS } { frame_start | BETWEEN frame_start AND frame_end }` - If frame_end is omitted it defaults to CURRENT ROW. + * `frame_start` and `frame_end` have the following syntax: - `frame_start` and `frame_end` have the following syntax + **Syntax:** - **Syntax:** + `UNBOUNDED PRECEDING | offset PRECEDING | CURRENT ROW | offset FOLLOWING | UNBOUNDED FOLLOWING` - `UNBOUNDED PRECEDING | offset PRECEDING | CURRENT ROW | offset FOLLOWING | UNBOUNDED FOLLOWING` + `offset:` specifies the `offset` from the position of the current row. - `offset:` specifies the offset from the position of the current row. + **Note:** If `frame_end` is omitted it defaults to `CURRENT ROW`. ### Examples From 0af379145c2a76573a229db65412c770717579b0 Mon Sep 17 00:00:00 2001 From: Huaxin Gao Date: Mon, 4 May 2020 15:37:04 -0700 Subject: [PATCH 04/10] fix --- docs/sql-ref-literals.md | 20 +++++++++---------- docs/sql-ref-syntax-aux-show-functions.md | 1 + docs/sql-ref-syntax-ddl-alter-table.md | 3 ++- .../sql-ref-syntax-qry-select-inline-table.md | 2 +- docs/sql-ref-syntax-qry-window.md | 2 +- 5 files changed, 15 insertions(+), 13 deletions(-) diff --git a/docs/sql-ref-literals.md b/docs/sql-ref-literals.md index d203f3503ef87..a9a19967a2b76 100644 --- a/docs/sql-ref-literals.md +++ b/docs/sql-ref-literals.md @@ -145,13 +145,13 @@ A numeric literal is used to specify a fixed or floating-point number. #### Integral Literal -#### Syntax +##### Syntax ```sql [ + | - ] digit [ ... ] [ L | S | Y ] ``` -#### Parameters +##### Parameters * **digit** @@ -173,7 +173,7 @@ A numeric literal is used to specify a fixed or floating-point number. Indicates a 4-byte signed integer number. -#### Examples +##### Examples ```sql SELECT -2147483648 AS col; @@ -207,7 +207,7 @@ SELECT 482S AS col; #### Fractional Literals -#### Syntax +##### Syntax decimal literals: ```sql @@ -229,7 +229,7 @@ and exponent is defined as E [ + | - ] digit [ ... ] ``` -#### Parameters +##### Parameters * **digit** @@ -243,7 +243,7 @@ E [ + | - ] digit [ ... ] Case insensitive, indicates `DECIMAL`, with the total number of digits as precision and the number of digits to right of decimal point as scale. -#### Examples +##### Examples ```sql SELECT 12.578 AS col; @@ -337,7 +337,7 @@ A Datetime literal is used to specify a datetime value. #### Date Literal -#### Syntax +##### Syntax ```sql DATE { 'yyyy' | @@ -347,7 +347,7 @@ DATE { 'yyyy' | ``` Note: defaults to `01` if month or day is not specified. -#### Examples +##### Examples ```sql SELECT DATE '1997' AS col; @@ -374,7 +374,7 @@ SELECT DATE '2011-11-11' AS col; #### Timestamp Literal -#### Syntax +##### Syntax ```sql TIMESTAMP { 'yyyy' | @@ -399,7 +399,7 @@ Note: defaults to `00` if hour, minute or second is not specified. Note: defaults to the session local timezone (set via `spark.sql.session.timeZone`) if `zone_id` is not specified. -#### Examples +##### Examples ```sql SELECT TIMESTAMP '1997-01-31 09:26:56.123' AS col; diff --git a/docs/sql-ref-syntax-aux-show-functions.md b/docs/sql-ref-syntax-aux-show-functions.md index 942d6a5409ca4..b4dd72801202e 100644 --- a/docs/sql-ref-syntax-aux-show-functions.md +++ b/docs/sql-ref-syntax-aux-show-functions.md @@ -9,6 +9,7 @@ license: | The ASF licenses this file to You under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at + http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software diff --git a/docs/sql-ref-syntax-ddl-alter-table.md b/docs/sql-ref-syntax-ddl-alter-table.md index 7a109d91d16bf..092ffef9b29fa 100644 --- a/docs/sql-ref-syntax-ddl-alter-table.md +++ b/docs/sql-ref-syntax-ddl-alter-table.md @@ -91,7 +91,7 @@ ALTER TABLE table_identifier { ALTER | CHANGE } [ COLUMN ] col_spec alterColumnA * **COLUMNS ( col_spec )** - Specifies the columns to be added. + Specifies the column to be altered or be changed. * **alterColumnAction** @@ -204,6 +204,7 @@ ALTER TABLE table_identifier [ partition_spec ] SET LOCATION 'new_location' * **table_identifier** Specifies a table name, which may be optionally qualified with a database name. + **Syntax:** `[ database_name. ] table_name` * **partition_spec** diff --git a/docs/sql-ref-syntax-qry-select-inline-table.md b/docs/sql-ref-syntax-qry-select-inline-table.md index 38ecc3da5e14e..c88d188dd28a5 100644 --- a/docs/sql-ref-syntax-qry-select-inline-table.md +++ b/docs/sql-ref-syntax-qry-select-inline-table.md @@ -37,7 +37,7 @@ VALUES ( expression [ , ... ] ) [ table_alias ] * **table_alias** - Specifies a temporary name with an optional column name list.

+ Specifies a temporary name with an optional column name list. **Syntax:** `[ AS ] table_name [ ( column_name [ , ... ] ) ]` ### Examples diff --git a/docs/sql-ref-syntax-qry-window.md b/docs/sql-ref-syntax-qry-window.md index 823ffa2677624..a1c2b18b04fce 100644 --- a/docs/sql-ref-syntax-qry-window.md +++ b/docs/sql-ref-syntax-qry-window.md @@ -52,7 +52,7 @@ window_function OVER * **window_frame** - Specifies which row to start the window on and where to end it.
+ Specifies which row to start the window on and where to end it. **Syntax:** From 37ebf02845a9d343fc81a62466458c634d9a3a85 Mon Sep 17 00:00:00 2001 From: Huaxin Gao Date: Mon, 4 May 2020 18:18:45 -0700 Subject: [PATCH 05/10] more changes --- ...sql-ref-syntax-aux-resource-mgmt-add-jar.md | 1 + docs/sql-ref-syntax-ddl-alter-table.md | 18 +++++++++++------- docs/sql-ref-syntax-qry-select-inline-table.md | 1 + 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/docs/sql-ref-syntax-aux-resource-mgmt-add-jar.md b/docs/sql-ref-syntax-aux-resource-mgmt-add-jar.md index 264c50a87ea55..4694bff99daf5 100644 --- a/docs/sql-ref-syntax-aux-resource-mgmt-add-jar.md +++ b/docs/sql-ref-syntax-aux-resource-mgmt-add-jar.md @@ -32,6 +32,7 @@ ADD JAR file_name ### Parameters * **file_name** + The name of the JAR file to be added. It could be either on a local file system or a distributed file system. ### Examples diff --git a/docs/sql-ref-syntax-ddl-alter-table.md b/docs/sql-ref-syntax-ddl-alter-table.md index 092ffef9b29fa..eb0e9a9f9cf73 100644 --- a/docs/sql-ref-syntax-ddl-alter-table.md +++ b/docs/sql-ref-syntax-ddl-alter-table.md @@ -73,7 +73,7 @@ ALTER TABLE table_identifier ADD COLUMNS ( col_spec [ , ... ] ) ### ALTER OR CHANGE COLUMN -`ALTER TABLE ALTER COLUMN` or `ALTER TABLE CHANGE COLUMN` statement changes column's comment. +`ALTER TABLE ALTER COLUMN` or `ALTER TABLE CHANGE COLUMN` statement changes column's definition. #### Syntax @@ -95,9 +95,7 @@ ALTER TABLE table_identifier { ALTER | CHANGE } [ COLUMN ] col_spec alterColumnA * **alterColumnAction** - Change the comment string. - - **Syntax:** `COMMENT STRING` + Change column's definition. ### ADD AND DROP PARTITION @@ -122,7 +120,7 @@ ALTER TABLE table_identifier ADD [IF NOT EXISTS] * **partition_spec** - Partition to be added.. + Partition to be added. **Syntax:** `PARTITION ( partition_col_name = partition_col_val [ , ... ] )` @@ -417,10 +415,16 @@ ALTER TABLE test_tab SET SERDE 'org.apache.hadoop.hive.serde2.columnar.LazyBinar ALTER TABLE dbx.tab1 SET SERDE 'org.apache.hadoop' WITH SERDEPROPERTIES ('k' = 'v', 'kay' = 'vee') -- SET TABLE PROPERTIES -ALTER TABLE dbx.tab1 SET TBLPROPERTIES ('winner' = 'loser') +ALTER TABLE dbx.tab1 SET TBLPROPERTIES ('winner' = 'loser'); + +-- SET TABLE COMMENT Using SET PROPERTIES +ALTER TABLE dbx.tab1 SET TBLPROPERTIES ('comment' = 'A table comment.'); + +-- Alter TABLE COMMENT Using SET PROPERTIES +ALTER TABLE dbx.tab1 SET TBLPROPERTIES ('comment' = 'This is a new comment.'); -- DROP TABLE PROPERTIES -ALTER TABLE dbx.tab1 UNSET TBLPROPERTIES ('winner') +ALTER TABLE dbx.tab1 UNSET TBLPROPERTIES ('winner'); ``` ### Related Statements diff --git a/docs/sql-ref-syntax-qry-select-inline-table.md b/docs/sql-ref-syntax-qry-select-inline-table.md index c88d188dd28a5..7f0372ea787e5 100644 --- a/docs/sql-ref-syntax-qry-select-inline-table.md +++ b/docs/sql-ref-syntax-qry-select-inline-table.md @@ -38,6 +38,7 @@ VALUES ( expression [ , ... ] ) [ table_alias ] * **table_alias** Specifies a temporary name with an optional column name list. + **Syntax:** `[ AS ] table_name [ ( column_name [ , ... ] ) ]` ### Examples From 0a8df5157a0bf88846512d8973684a4869295de2 Mon Sep 17 00:00:00 2001 From: Huaxin Gao Date: Mon, 4 May 2020 22:31:02 -0700 Subject: [PATCH 06/10] address comments --- docs/sql-ref-ansi-compliance.md | 10 +++++----- docs/sql-ref-identifier.md | 8 ++++---- docs/sql-ref-literals.md | 10 +++++----- docs/sql-ref-syntax-aux-show-table.md | 4 ++-- docs/sql-ref-syntax-ddl-drop-function.md | 6 +++--- docs/sql-ref-syntax-ddl-drop-table.md | 4 ++-- docs/sql-ref-syntax-ddl-drop-view.md | 4 ++-- docs/sql-ref-syntax-qry-select-limit.md | 2 +- docs/sql-ref-syntax-qry-select-usedb.md | 3 ++- 9 files changed, 26 insertions(+), 25 deletions(-) diff --git a/docs/sql-ref-ansi-compliance.md b/docs/sql-ref-ansi-compliance.md index a9c91473c7dd8..b62834ebe9067 100644 --- a/docs/sql-ref-ansi-compliance.md +++ b/docs/sql-ref-ansi-compliance.md @@ -44,7 +44,7 @@ When `spark.sql.ansi.enabled` is set to `true` and an overflow occurs in numeric ```sql -- `spark.sql.ansi.enabled=true` SELECT 2147483647 + 1; - java.lang.ArithmeticException: integer overflow +java.lang.ArithmeticException: integer overflow -- `spark.sql.ansi.enabled=false` SELECT 2147483647 + 1; @@ -69,10 +69,10 @@ In future releases, the behaviour of type coercion might change along with the o -- `spark.sql.ansi.enabled=true` SELECT CAST('a' AS INT); - java.lang.NumberFormatException: invalid input syntax for type numeric: a +java.lang.NumberFormatException: invalid input syntax for type numeric: a SELECT CAST(2147483648L AS INT); - java.lang.ArithmeticException: Casting 2147483648 to int causes overflow +java.lang.ArithmeticException: Casting 2147483648 to int causes overflow -- `spark.sql.ansi.enabled=false` (This is a default behaviour) SELECT CAST('a' AS INT); @@ -94,8 +94,8 @@ CREATE TABLE t (v INT); -- `spark.sql.storeAssignmentPolicy=ANSI` INSERT INTO t VALUES ('1'); - org.apache.spark.sql.AnalysisException: Cannot write incompatible data to table '`default`.`t`': - - Cannot safely cast 'v': StringType to IntegerType; +org.apache.spark.sql.AnalysisException: Cannot write incompatible data to table '`default`.`t`': +- Cannot safely cast 'v': StringType to IntegerType; -- `spark.sql.storeAssignmentPolicy=LEGACY` (This is a legacy behaviour until Spark 2.x) INSERT INTO t VALUES ('1'); diff --git a/docs/sql-ref-identifier.md b/docs/sql-ref-identifier.md index 5b48ece19fb07..84f3d99815c70 100644 --- a/docs/sql-ref-identifier.md +++ b/docs/sql-ref-identifier.md @@ -57,16 +57,16 @@ Note: If `spark.sql.ansi.enabled` is set to true, ANSI SQL reserved keywords can ```sql -- This CREATE TABLE fails with ParseException because of the illegal identifier name a.b CREATE TABLE test (a.b int); - org.apache.spark.sql.catalyst.parser.ParseException: - no viable alternative at input 'CREATE TABLE test (a.'(line 1, pos 20) +org.apache.spark.sql.catalyst.parser.ParseException: +no viable alternative at input 'CREATE TABLE test (a.'(line 1, pos 20) -- This CREATE TABLE works CREATE TABLE test (`a.b` int); -- This CREATE TABLE fails with ParseException because special character ` is not escaped CREATE TABLE test1 (`a`b` int); - org.apache.spark.sql.catalyst.parser.ParseException: - no viable alternative at input 'CREATE TABLE test (`a`b`'(line 1, pos 23) +org.apache.spark.sql.catalyst.parser.ParseException: +no viable alternative at input 'CREATE TABLE test (`a`b`'(line 1, pos 23) -- This CREATE TABLE works CREATE TABLE test (`a``b` int); diff --git a/docs/sql-ref-literals.md b/docs/sql-ref-literals.md index a9a19967a2b76..6e65024d3cfc6 100644 --- a/docs/sql-ref-literals.md +++ b/docs/sql-ref-literals.md @@ -36,12 +36,12 @@ A string literal is used to specify a character string value. #### Syntax ```sql -'c [ ... ]' | "c [ ... ]" +'char [ ... ]' | "char [ ... ]" ``` #### Parameters -* **c** +* **char** One character from the character set. Use `\` to escape special characters (e.g., `'` or `\`). @@ -77,14 +77,14 @@ A binary literal is used to specify a byte sequence value. #### Syntax ```sql -X { 'c [ ... ]' | "c [ ... ]" } +X { 'num [ ... ]' | "num [ ... ]" } ``` #### Parameters -* **c** +* **num** - One character from the character set. + Any hexadecimal number from 0 to F. #### Examples diff --git a/docs/sql-ref-syntax-aux-show-table.md b/docs/sql-ref-syntax-aux-show-table.md index 6be6e7eff79ca..0ce0a3eefa538 100644 --- a/docs/sql-ref-syntax-aux-show-table.md +++ b/docs/sql-ref-syntax-aux-show-table.md @@ -170,8 +170,8 @@ SHOW TABLE EXTENDED IN default LIKE `employee` PARTITION (`grade=1`); -- show partition file system details with regex fails as shown below SHOW TABLE EXTENDED IN default LIKE `empl*` PARTITION (`grade=1`); - Error: Error running query: org.apache.spark.sql.catalyst.analysis.NoSuchTableException: - Table or view 'emplo*' not found in database 'default'; (state=,code=0) +Error: Error running query: org.apache.spark.sql.catalyst.analysis.NoSuchTableException: + Table or view 'emplo*' not found in database 'default'; (state=,code=0) ``` ### Related Statements diff --git a/docs/sql-ref-syntax-ddl-drop-function.md b/docs/sql-ref-syntax-ddl-drop-function.md index b1b2ff9b1bb21..bef31d74afcff 100644 --- a/docs/sql-ref-syntax-ddl-drop-function.md +++ b/docs/sql-ref-syntax-ddl-drop-function.md @@ -79,9 +79,9 @@ DROP FUNCTION test_avg; -- Try to drop Permanent function which is not present DROP FUNCTION test_avg; - Error: Error running query: - org.apache.spark.sql.catalyst.analysis.NoSuchPermanentFunctionException: - Function 'default.test_avg' not found in database 'default'; (state=,code=0) +Error: Error running query: +org.apache.spark.sql.catalyst.analysis.NoSuchPermanentFunctionException: +Function 'default.test_avg' not found in database 'default'; (state=,code=0) -- List the functions after dropping, it should list only temporary function SHOW USER FUNCTIONS; diff --git a/docs/sql-ref-syntax-ddl-drop-table.md b/docs/sql-ref-syntax-ddl-drop-table.md index f2ff89993f2c3..7dee677c853a6 100644 --- a/docs/sql-ref-syntax-ddl-drop-table.md +++ b/docs/sql-ref-syntax-ddl-drop-table.md @@ -56,8 +56,8 @@ DROP TABLE userdb.employeetable; -- Assumes a table named `employeetable` does not exists. -- Throws exception DROP TABLE employeetable; - Error: org.apache.spark.sql.AnalysisException: Table or view not found: employeetable; - (state=,code=0) +Error: org.apache.spark.sql.AnalysisException: Table or view not found: employeetable; +(state=,code=0) -- Assumes a table named `employeetable` does not exists,Try with IF EXISTS -- this time it will not throw exception diff --git a/docs/sql-ref-syntax-ddl-drop-view.md b/docs/sql-ref-syntax-ddl-drop-view.md index 0f4a7ca6c9463..4320ccf38280c 100644 --- a/docs/sql-ref-syntax-ddl-drop-view.md +++ b/docs/sql-ref-syntax-ddl-drop-view.md @@ -53,8 +53,8 @@ DROP VIEW userdb.employeeView; -- Assumes a view named `employeeView` does not exists. -- Throws exception DROP VIEW employeeView; - Error: org.apache.spark.sql.AnalysisException: Table or view not found: employeeView; - (state=,code=0) +Error: org.apache.spark.sql.AnalysisException: Table or view not found: employeeView; +(state=,code=0) -- Assumes a view named `employeeView` does not exists,Try with IF EXISTS -- this time it will not throw exception diff --git a/docs/sql-ref-syntax-qry-select-limit.md b/docs/sql-ref-syntax-qry-select-limit.md index ec3532214084b..03c4df3cbc442 100644 --- a/docs/sql-ref-syntax-qry-select-limit.md +++ b/docs/sql-ref-syntax-qry-select-limit.md @@ -91,7 +91,7 @@ SELECT name, age FROM person ORDER BY name LIMIT length('SPARK'); -- A non-foldable expression as an input to LIMIT is not allowed. SELECT name, age FROM person ORDER BY name LIMIT length(name); - org.apache.spark.sql.AnalysisException: The limit expression must evaluate to a constant value ... +org.apache.spark.sql.AnalysisException: The limit expression must evaluate to a constant value ... ``` ### Related Statements diff --git a/docs/sql-ref-syntax-qry-select-usedb.md b/docs/sql-ref-syntax-qry-select-usedb.md index 4119a4927bc9f..90076e0306125 100644 --- a/docs/sql-ref-syntax-qry-select-usedb.md +++ b/docs/sql-ref-syntax-qry-select-usedb.md @@ -46,7 +46,8 @@ USE userdb; -- Use the 'userdb1' which doesn't exist USE userdb1; - Error: org.apache.spark.sql.catalyst.analysis.NoSuchDatabaseException: Database 'userdb1' not found;(state=,code=0) +Error: org.apache.spark.sql.catalyst.analysis.NoSuchDatabaseException: Database 'userdb1' not found; +(state=,code=0) ``` ### Related Statements From 0575f06fcb31ecc8cad490cce029cac4befaaebd Mon Sep 17 00:00:00 2001 From: Huaxin Gao Date: Mon, 4 May 2020 22:59:31 -0700 Subject: [PATCH 07/10] bold Note --- docs/sql-ref-identifier.md | 2 +- docs/sql-ref-literals.md | 6 +++--- docs/sql-ref-syntax-qry-sampling.md | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/sql-ref-identifier.md b/docs/sql-ref-identifier.md index 84f3d99815c70..f65d491cc2fc4 100644 --- a/docs/sql-ref-identifier.md +++ b/docs/sql-ref-identifier.md @@ -30,7 +30,7 @@ An identifier is a string used to identify a database object such as a table, vi ```sql { letter | digit | '_' } [ , ... ] ``` -Note: If `spark.sql.ansi.enabled` is set to true, ANSI SQL reserved keywords cannot be used as identifiers. For more details, please refer to [ANSI Compliance](sql-ref-ansi-compliance.html). +**Note:** If `spark.sql.ansi.enabled` is set to true, ANSI SQL reserved keywords cannot be used as identifiers. For more details, please refer to [ANSI Compliance](sql-ref-ansi-compliance.html). #### Delimited Identifier diff --git a/docs/sql-ref-literals.md b/docs/sql-ref-literals.md index 6e65024d3cfc6..4d9c8c5c7495e 100644 --- a/docs/sql-ref-literals.md +++ b/docs/sql-ref-literals.md @@ -345,7 +345,7 @@ DATE { 'yyyy' | 'yyyy-[m]m-[d]d' | 'yyyy-[m]m-[d]d[T]' } ``` -Note: defaults to `01` if month or day is not specified. +**Note:** defaults to `01` if month or day is not specified. ##### Examples @@ -386,7 +386,7 @@ TIMESTAMP { 'yyyy' | 'yyyy-[m]m-[d]d[T][h]h:[m]m:[s]s[.]' | 'yyyy-[m]m-[d]d[T][h]h:[m]m:[s]s.[ms][ms][ms][us][us][us][zone_id]'} ``` -Note: defaults to `00` if hour, minute or second is not specified. +**Note:** defaults to `00` if hour, minute or second is not specified. `zone_id` should have one of the forms: * Z - Zulu time zone UTC+0 * `+|-[h]h:[m]m` @@ -397,7 +397,7 @@ Note: defaults to `00` if hour, minute or second is not specified. * `+|-hhmmss` * Region-based zone IDs in the form `area/city`, such as `Europe/Paris` -Note: defaults to the session local timezone (set via `spark.sql.session.timeZone`) if `zone_id` is not specified. +**Note:** defaults to the session local timezone (set via `spark.sql.session.timeZone`) if `zone_id` is not specified. ##### Examples diff --git a/docs/sql-ref-syntax-qry-sampling.md b/docs/sql-ref-syntax-qry-sampling.md index 28e21e802fe25..f9c7b760a239f 100644 --- a/docs/sql-ref-syntax-qry-sampling.md +++ b/docs/sql-ref-syntax-qry-sampling.md @@ -26,7 +26,7 @@ The `TABLESAMPLE` statement is used to sample the table. It supports the followi * `TABLESAMPLE`(x `PERCENT`): Sample the table down to the given percentage. Note that percentages are defined as a number between 0 and 100. * `TABLESAMPLE`(`BUCKET` x `OUT OF` y): Sample the table down to a `x` out of `y` fraction. -Note: `TABLESAMPLE` returns the approximate number of rows or fraction requested. +**Note:** `TABLESAMPLE` returns the approximate number of rows or fraction requested. ### Syntax From 5726a1f080f7bffc9a863d79f7ddb8b674716b4e Mon Sep 17 00:00:00 2001 From: Huaxin Gao Date: Mon, 4 May 2020 23:45:15 -0700 Subject: [PATCH 08/10] address comments --- docs/sql-ref-functions-builtin.md | 2 +- docs/sql-ref-syntax-aux-show-partitions.md | 2 +- docs/sql-ref-syntax-qry-select-tvf.md | 31 +++++----------------- 3 files changed, 8 insertions(+), 27 deletions(-) diff --git a/docs/sql-ref-functions-builtin.md b/docs/sql-ref-functions-builtin.md index 1bca68e5f19df..cabb83e09fde9 100644 --- a/docs/sql-ref-functions-builtin.md +++ b/docs/sql-ref-functions-builtin.md @@ -70,7 +70,7 @@ license: | ### JSON Functions {% include_relative generated-json-funcs-table.html %} #### Examples -{% include_relative generated-agg-funcs-examples.html %} +{% include_relative generated-json-funcs-examples.html %} {% break %} {% endif %} {% endfor %} diff --git a/docs/sql-ref-syntax-aux-show-partitions.md b/docs/sql-ref-syntax-aux-show-partitions.md index f937f8f524342..d93825550413f 100644 --- a/docs/sql-ref-syntax-aux-show-partitions.md +++ b/docs/sql-ref-syntax-aux-show-partitions.md @@ -42,7 +42,7 @@ SHOW PARTITIONS table_identifier [ partition_spec ] * **partition_spec** An optional parameter that specifies a comma separated list of key and value pairs - for partitions. When specified, the partitions that match the partition spec are returned. + for partitions. When specified, the partitions that match the partition specification are returned. **Syntax:** `PARTITION ( partition_col_name = partition_col_val [ , ... ] )` diff --git a/docs/sql-ref-syntax-qry-select-tvf.md b/docs/sql-ref-syntax-qry-select-tvf.md index 89ad01aff2167..cc8d7c34645fb 100644 --- a/docs/sql-ref-syntax-qry-select-tvf.md +++ b/docs/sql-ref-syntax-qry-select-tvf.md @@ -43,31 +43,12 @@ function_name ( expression [ , ... ] ) [ table_alias ] ### Supported Table-valued Functions - - - - - - - - - - - - - - - - - - - - - - - - -
FunctionArgument Type(s)Description
range ( end ) Long Creates a table with a single LongType column named id, containing rows in a range from 0 to end (exclusive) with step value 1.
range ( start, end ) Long, Long Creates a table with a single LongType column named id, containing rows in a range from start to end (exclusive) with step value 1.
range ( start, end, step ) Long, Long, Long Creates a table with a single LongType column named id, containing rows in a range from start to end (exclusive) with step value.
range ( start, end, step, numPartitions ) Long, Long, Long, Int Creates a table with a single LongType column named id, containing rows in a range from start to end (exclusive) with step value, with partition number numPartitions specified.
+|Function|Argument Type(s)|Description| +|--------|----------------|-----------| +|**range** ( *end* )|Long|Creates a table with a single *LongType* column named *id*,
containing rows in a range from 0 to *end* (exclusive) with step value 1.| +|**range** ( *start, end* )|Long, Long|Creates a table with a single *LongType* column named *id*,
containing rows in a range from *start* to *end* (exclusive) with step value 1.| +|**range** ( *start, end, step* )|Long, Long, Long|Creates a table with a single *LongType* column named *id*,
containing rows in a range from *start* to *end* (exclusive) with *step* value.| +|**range** ( *start, end, step, numPartitions* )|Long, Long, Long, Int|Creates a table with a single *LongType* column named *id*,
containing rows in a range from *start* to *end* (exclusive) with *step* value, with partition number *numPartitions* specified.| ### Examples From bd0b900f1051161acf8459b33c2eb5a1a713986d Mon Sep 17 00:00:00 2001 From: Huaxin Gao Date: Tue, 5 May 2020 08:34:44 -0700 Subject: [PATCH 09/10] a -> an before 8 --- docs/sql-ref-literals.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/sql-ref-literals.md b/docs/sql-ref-literals.md index 4d9c8c5c7495e..b83f7f0a97c24 100644 --- a/docs/sql-ref-literals.md +++ b/docs/sql-ref-literals.md @@ -159,7 +159,7 @@ A numeric literal is used to specify a fixed or floating-point number. * **L** - Case insensitive, indicates `BIGINT`, which is a 8-byte signed integer number. + Case insensitive, indicates `BIGINT`, which is an 8-byte signed integer number. * **S** @@ -237,7 +237,7 @@ E [ + | - ] digit [ ... ] * **D** - Case insensitive, indicates `DOUBLE`, which is a 8-byte double-precision floating point number. + Case insensitive, indicates `DOUBLE`, which is an 8-byte double-precision floating point number. * **BD** From bd82fdd6d132020a72d8f1ed3f4327e3b334555b Mon Sep 17 00:00:00 2001 From: Huaxin Gao Date: Tue, 5 May 2020 09:09:12 -0700 Subject: [PATCH 10/10] fix errors --- docs/sql-ref-syntax-ddl-create-database.md | 2 +- docs/sql-ref-syntax-ddl-create-table-hiveformat.md | 2 +- docs/sql-ref-syntax-ddl-create-table-like.md | 2 +- docs/sql-ref-syntax-ddl-create-view.md | 2 +- docs/sql-ref-syntax-ddl-drop-table.md | 6 +++--- docs/sql-ref-syntax-ddl-drop-view.md | 6 +++--- 6 files changed, 10 insertions(+), 10 deletions(-) diff --git a/docs/sql-ref-syntax-ddl-create-database.md b/docs/sql-ref-syntax-ddl-create-database.md index 8c0951253bf37..9d8bf47844724 100644 --- a/docs/sql-ref-syntax-ddl-create-database.md +++ b/docs/sql-ref-syntax-ddl-create-database.md @@ -40,7 +40,7 @@ CREATE { DATABASE | SCHEMA } [ IF NOT EXISTS ] database_name * **IF NOT EXISTS** - Creates a database with the given name if it doesn't exists. If a database with the same name already exists, nothing will happen. + Creates a database with the given name if it does not exist. If a database with the same name already exists, nothing will happen. * **database_directory** diff --git a/docs/sql-ref-syntax-ddl-create-table-hiveformat.md b/docs/sql-ref-syntax-ddl-create-table-hiveformat.md index 7f7033fcaebaf..38f8856a24e3d 100644 --- a/docs/sql-ref-syntax-ddl-create-table-hiveformat.md +++ b/docs/sql-ref-syntax-ddl-create-table-hiveformat.md @@ -63,7 +63,7 @@ as any order. For example, you can write COMMENT table_comment after TBLPROPERTI * **STORED AS** - File format for table storage, could be TEXTFILE, ORC, PARQUET,etc. + File format for table storage, could be TEXTFILE, ORC, PARQUET, etc. * **LOCATION** diff --git a/docs/sql-ref-syntax-ddl-create-table-like.md b/docs/sql-ref-syntax-ddl-create-table-like.md index 23d8e4f9712a6..cfb959ca6b23d 100644 --- a/docs/sql-ref-syntax-ddl-create-table-like.md +++ b/docs/sql-ref-syntax-ddl-create-table-like.md @@ -52,7 +52,7 @@ CREATE TABLE [IF NOT EXISTS] table_identifier LIKE source_table_identifier * **STORED AS** - File format for table storage, could be TEXTFILE, ORC, PARQUET,etc. + File format for table storage, could be TEXTFILE, ORC, PARQUET, etc. * **TBLPROPERTIES** diff --git a/docs/sql-ref-syntax-ddl-create-view.md b/docs/sql-ref-syntax-ddl-create-view.md index 032bcbcf19ad3..1a9c1f62728e7 100644 --- a/docs/sql-ref-syntax-ddl-create-view.md +++ b/docs/sql-ref-syntax-ddl-create-view.md @@ -46,7 +46,7 @@ CREATE [ OR REPLACE ] [ [ GLOBAL ] TEMPORARY ] VIEW [ IF NOT EXISTS ] view_ident * **IF NOT EXISTS** - Creates a view if it does not exists. + Creates a view if it does not exist. * **view_identifier** diff --git a/docs/sql-ref-syntax-ddl-drop-table.md b/docs/sql-ref-syntax-ddl-drop-table.md index 7dee677c853a6..a15a9928f437d 100644 --- a/docs/sql-ref-syntax-ddl-drop-table.md +++ b/docs/sql-ref-syntax-ddl-drop-table.md @@ -36,7 +36,7 @@ DROP TABLE [ IF EXISTS ] table_identifier * **IF EXISTS** - If specified, no exception is thrown when the table does not exists. + If specified, no exception is thrown when the table does not exist. * **table_identifier** @@ -53,13 +53,13 @@ DROP TABLE employeetable; -- Assumes a table named `employeetable` exists in the `userdb` database DROP TABLE userdb.employeetable; --- Assumes a table named `employeetable` does not exists. +-- Assumes a table named `employeetable` does not exist. -- Throws exception DROP TABLE employeetable; Error: org.apache.spark.sql.AnalysisException: Table or view not found: employeetable; (state=,code=0) --- Assumes a table named `employeetable` does not exists,Try with IF EXISTS +-- Assumes a table named `employeetable` does not exist,Try with IF EXISTS -- this time it will not throw exception DROP TABLE IF EXISTS employeetable; ``` diff --git a/docs/sql-ref-syntax-ddl-drop-view.md b/docs/sql-ref-syntax-ddl-drop-view.md index 4320ccf38280c..5b680d7f907e0 100644 --- a/docs/sql-ref-syntax-ddl-drop-view.md +++ b/docs/sql-ref-syntax-ddl-drop-view.md @@ -33,7 +33,7 @@ DROP VIEW [ IF EXISTS ] view_identifier * **IF EXISTS** - If specified, no exception is thrown when the view does not exists. + If specified, no exception is thrown when the view does not exist. * **view_identifier** @@ -50,13 +50,13 @@ DROP VIEW employeeView; -- Assumes a view named `employeeView` exists in the `userdb` database DROP VIEW userdb.employeeView; --- Assumes a view named `employeeView` does not exists. +-- Assumes a view named `employeeView` does not exist. -- Throws exception DROP VIEW employeeView; Error: org.apache.spark.sql.AnalysisException: Table or view not found: employeeView; (state=,code=0) --- Assumes a view named `employeeView` does not exists,Try with IF EXISTS +-- Assumes a view named `employeeView` does not exist,Try with IF EXISTS -- this time it will not throw exception DROP VIEW IF EXISTS employeeView; ```