maropu commented on a change in pull request #29056: URL: https://github.com/apache/spark/pull/29056#discussion_r456980758
########## File path: docs/sql-ref-syntax-qry-select-pivot.md ########## @@ -0,0 +1,101 @@ +--- +layout: global +title: PIVOT Clause +displayTitle: PIVOT Clause +license: | + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + 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 + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--- + +### Description + +The `PIVOT` clause is used for data perspective. We can get the aggregated values based on specific column values, which will be turned to multiple columns used in `SELECT Clause`. The `PIVOT` clause can be specified after the table name or subquery. + +### Syntax + +```sql +PIVOT ( { aggregate_expression [ AS aggregate_expression_alias ] } [ , ... ] + FOR column_list IN ( expression_list ) ) +``` + +### Parameters + +* **aggregate_expression** + + Specifies an aggregate expression (SUM(a), COUNT(DISTINCT b), etc.). + +* **aggregate_expression_alias** + + Specifies an alias for the aggregate expression. + +* **column_list** + + Contains columns in the `FROM` clause, which specifies the columns we want to replace with new columns. We can use brackets to surround the columns, such as `( c1, c2 )`. Review comment: nit: `( c1, c2 )` -> `(c1, c2)` ########## File path: docs/sql-ref-syntax-ddl-create-table-hiveformat.md ########## @@ -114,9 +162,45 @@ CREATE TABLE student (id INT, name STRING) PARTITIONED BY (age INT); --Use Row Format and file format -CREATE TABLE student (id INT,name STRING) +CREATE TABLE student (id INT, name STRING) ROW FORMAT DELIMITED FIELDS TERMINATED BY ',' STORED AS TEXTFILE; + +--Use complex datatype +CREATE EXTERNAL TABLE family( + name STRING, + friends ARRAY<STRING>, + children MAP<STRING, INT>, + address STRUCT<street: STRING, city: STRING> + ) + ROW FORMAT DELIMITED FIELDS TERMINATED BY ',' ESCAPED BY '\\' + COLLECTION ITEMS TERMINATED BY '_' + MAP KEYS TERMINATED BY ':' + LINES TERMINATED BY '\n' + NULL DEFINED AS 'foonull' + STORED AS TEXTFILE + LOCATION '/tmp/family/'; + +--Use predefined custom SerDe +CREATE TABLE avroExample + ROW FORMAT SERDE 'org.apache.hadoop.hive.serde2.avro.AvroSerDe' + STORED AS INPUTFORMAT 'org.apache.hadoop.hive.ql.io.avro.AvroContainerInputFormat' + OUTPUTFORMAT 'org.apache.hadoop.hive.ql.io.avro.AvroContainerOutputFormat' + TBLPROPERTIES ('avro.schema.literal'='{ "namespace": "org.apache.hive", + "name": "first_schema", + "type": "record", + "fields": [ + { "name":"string1", "type":"string" }, + { "name":"string2", "type":"string" } + ] }'); + +--Use personalized custom SerDe(we may need to `ADD JAR xxx.jar` first to ensure we can find the serde_class, or you may run into `CLASSNOTFOUND` exception) Review comment: please add a blank line ``` --Use personalized custom SerDe(we may need to `ADD JAR xxx.jar` first to ensure we can find the serde_class, --or you may run into `CLASSNOTFOUND` exception). ``` ########## File path: docs/sql-ref-syntax-qry-select.md ########## @@ -83,8 +85,15 @@ SELECT [ hints , ... ] [ ALL | DISTINCT ] { named_expression [ , ... ] } * [Table-value function](sql-ref-syntax-qry-select-tvf.html) * [Inline table](sql-ref-syntax-qry-select-inline-table.html) * Subquery + + * **PIVOT** + The `PIVOT` clause is used for data perspective; We can get the aggregated values based on specific column value. + * **LATERAL VIEW** + + The `LATERAL VIEW` clause is used in conjunction with generator functions such as explode(), which will generate a virtual table containing one or more rows. `LATERAL VIEW` will apply the rows to each original output row. Review comment: explode() -> EXPLODE? ########## File path: docs/sql-ref-syntax-qry-select-pivot.md ########## @@ -0,0 +1,101 @@ +--- +layout: global +title: PIVOT Clause +displayTitle: PIVOT Clause +license: | + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + 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 + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--- + +### Description + +The `PIVOT` clause is used for data perspective. We can get the aggregated values based on specific column values, which will be turned to multiple columns used in `SELECT Clause`. The `PIVOT` clause can be specified after the table name or subquery. Review comment: \`SELECT Clause\` -> a \`SELECT\` caluse? ########## File path: docs/sql-ref-syntax-qry-select-lateral-view.md ########## @@ -0,0 +1,130 @@ +--- +layout: global +title: LATERAL VIEW Clause +displayTitle: LATERAL VIEW Clause +license: | + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + 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 + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--- + +### Description + +The `LATERAL VIEW` clause is used in conjunction with generator functions such as explode(), which will generate a virtual table containing one or more rows. `LATERAL VIEW` will apply the rows to each original output row. Review comment: `explode()` -> `EXPLODE`? ########## File path: docs/sql-ref-syntax-qry-select-groupby.md ########## @@ -91,6 +93,18 @@ aggregate_name ( [ DISTINCT ] expression [ , ... ] ) [ FILTER ( WHERE boolean_ex 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. +* **FIRST** + + `FIRST` selects a first expression value from the data set. We can specify an optional `IGNORE NULL` clause to ignore NULL values. + +* **LAST** + + `LAST` selects a last expression value from the data set. We can specify an optional `IGNORE NULLS` clause to ignore NULL values. + +* **IGNORE NULLS** + + `IGNORE NULLS` is used to ignore null values, which are used in `FIRST` and `LAST` + Review comment: Looks verbose, so could you remove this? ########## File path: docs/sql-ref-syntax-qry-select-pivot.md ########## @@ -0,0 +1,101 @@ +--- +layout: global +title: PIVOT Clause +displayTitle: PIVOT Clause +license: | + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + 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 + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--- + +### Description + +The `PIVOT` clause is used for data perspective. We can get the aggregated values based on specific column values, which will be turned to multiple columns used in `SELECT Clause`. The `PIVOT` clause can be specified after the table name or subquery. + +### Syntax + +```sql +PIVOT ( { aggregate_expression [ AS aggregate_expression_alias ] } [ , ... ] + FOR column_list IN ( expression_list ) ) +``` + +### Parameters + +* **aggregate_expression** + + Specifies an aggregate expression (SUM(a), COUNT(DISTINCT b), etc.). + +* **aggregate_expression_alias** + + Specifies an alias for the aggregate expression. + +* **column_list** + + Contains columns in the `FROM` clause, which specifies the columns we want to replace with new columns. We can use brackets to surround the columns, such as `( c1, c2 )`. + +* **expression_list** + + Specifies new columns, which are used to match values in `column_List` as the aggregating condition. We can also add aliases for them. Review comment: `column_List` -> `column_list ` ########## File path: docs/sql-ref-syntax-qry-select-lateral-view.md ########## @@ -0,0 +1,130 @@ +--- +layout: global +title: LATERAL VIEW Clause +displayTitle: LATERAL VIEW Clause +license: | + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + 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 + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--- + +### Description + +The `LATERAL VIEW` clause is used in conjunction with generator functions such as explode(), which will generate a virtual table containing one or more rows. `LATERAL VIEW` will apply the rows to each original output row. + +### Syntax + +```sql +LATERAL VIEW [ OUTER ] generator_function ( expression [ , ... ] ) [ table_alias ] AS column_alias [ , ... ] +``` + +### Parameters + +* **OUTER** + + If `LATERAL VIEW` is used without `OUTER`, and `generator_function` returns empty, then no results will be output in `SELECT` clause. + If `LATERAL VIEW` is used with `OUTER`, and `generator_function` returns empty, then results will be output normally with `NULL` as `generator_function` output. + +* **generator_function** + + This expression will output a virtual table with a single input row. Review comment: ``` Specifies an generator function (EXPLODE, INLINE, etc.). ``` ########## File path: docs/sql-ref-syntax-qry-select-pivot.md ########## @@ -0,0 +1,101 @@ +--- +layout: global +title: PIVOT Clause +displayTitle: PIVOT Clause +license: | + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + 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 + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--- + +### Description + +The `PIVOT` clause is used for data perspective. We can get the aggregated values based on specific column values, which will be turned to multiple columns used in `SELECT Clause`. The `PIVOT` clause can be specified after the table name or subquery. + +### Syntax + +```sql +PIVOT ( { aggregate_expression [ AS aggregate_expression_alias ] } [ , ... ] + FOR column_list IN ( expression_list ) ) Review comment: cc: @maryannxue @gatorsmile ########## File path: docs/sql-ref-syntax-qry-select-case.md ########## @@ -0,0 +1,107 @@ +--- +layout: global +title: CASE Clause +displayTitle: CASE Clause +license: | + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + 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 + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--- + +### Description + +`CASE` clause uses a rule to return a specific result based on the specified condition, similar to if/else statements in other programming languages. + +### Syntax + +```sql +CASE [ expression ] { WHEN boolean_expression THEN then_expression } [ ... ] + [ ELSE else_expression ] +END +``` + +### Parameters + +* **boolean_expression** + + Specifies an expression with a return type of boolean. Review comment: https://github.com/apache/spark/blame/master/docs/sql-ref-syntax-qry-select-where.md#L35-L39 ########## File path: docs/sql-ref-syntax-qry-select-lateral-view.md ########## @@ -0,0 +1,130 @@ +--- +layout: global +title: LATERAL VIEW Clause +displayTitle: LATERAL VIEW Clause +license: | + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + 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 + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--- + +### Description + +The `LATERAL VIEW` clause is used in conjunction with generator functions such as explode(), which will generate a virtual table containing one or more rows. `LATERAL VIEW` will apply the rows to each original output row. + +### Syntax + +```sql +LATERAL VIEW [ OUTER ] generator_function ( expression [ , ... ] ) [ table_alias ] AS column_alias [ , ... ] +``` + +### Parameters + +* **OUTER** + + If `LATERAL VIEW` is used without `OUTER`, and `generator_function` returns empty, then no results will be output in `SELECT` clause. + If `LATERAL VIEW` is used with `OUTER`, and `generator_function` returns empty, then results will be output normally with `NULL` as `generator_function` output. Review comment: How about just saying it like this? ``` If `OUTER` specified, returns null if an input array/map is empty or null. ``` ########## File path: docs/sql-ref-syntax-qry-select-lateral-view.md ########## @@ -0,0 +1,130 @@ +--- +layout: global +title: LATERAL VIEW Clause +displayTitle: LATERAL VIEW Clause +license: | + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + 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 + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--- + +### Description + +The `LATERAL VIEW` clause is used in conjunction with generator functions such as explode(), which will generate a virtual table containing one or more rows. `LATERAL VIEW` will apply the rows to each original output row. + +### Syntax + +```sql +LATERAL VIEW [ OUTER ] generator_function ( expression [ , ... ] ) [ table_alias ] AS column_alias [ , ... ] +``` + +### Parameters + +* **OUTER** + + If `LATERAL VIEW` is used without `OUTER`, and `generator_function` returns empty, then no results will be output in `SELECT` clause. + If `LATERAL VIEW` is used with `OUTER`, and `generator_function` returns empty, then results will be output normally with `NULL` as `generator_function` output. + +* **generator_function** + + This expression will output a virtual table with a single input row. + +* **expression** + + Parameters for generating_function. Review comment: Loos verbose? ########## File path: docs/sql-ref-syntax-qry-select-groupby.md ########## @@ -81,6 +81,8 @@ aggregate_name ( [ DISTINCT ] expression [ , ... ] ) [ FILTER ( WHERE boolean_ex * **aggregate_name** Specifies an aggregate function name (MIN, MAX, COUNT, SUM, AVG, etc.). + Some aggregate function like `FIRST` and `LAST` have special usage as the following: + **Syntax:** `[ FIRST | LAST ] ( [ distinct ] expression [ IGNORE NULLS ] ) [ FILTER ( WHERE boolean_expression ) ]` Review comment: ``` * **aggregate_name** Specifies an aggregate function name (MIN, MAX, COUNT, SUM, AVG, FIRST, LAST, etc.). Note that `FIRST` and `LAST` have an optional `IGNORE NULLS` clause; when the option specified, it will returns the first or last value that is not null (or null if all values are null). * **DISTINCT** ``` ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
