Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
bb1efa2
Merge pull request #1 from apache/master
GuoPhilipse May 20, 2020
1459d5b
Merge pull request #2 from apache/master
GuoPhilipse May 22, 2020
88c40fe
Merge pull request #3 from apache/master
GuoPhilipse May 22, 2020
df22083
Merge pull request #4 from apache/master
GuoPhilipse May 25, 2020
0436611
Merge pull request #5 from apache/master
GuoPhilipse May 27, 2020
ed80c84
Merge pull request #6 from apache/master
GuoPhilipse May 27, 2020
39ca87c
Merge pull request #7 from apache/master
GuoPhilipse May 28, 2020
c3b3c89
Merge pull request #8 from apache/master
GuoPhilipse May 28, 2020
c3546eb
Merge pull request #9 from apache/master
GuoPhilipse Jun 2, 2020
77a339a
Merge pull request #10 from apache/master
GuoPhilipse Jun 3, 2020
a6b4f74
Merge pull request #11 from apache/master
GuoPhilipse Jun 5, 2020
664277e
Merge pull request #12 from apache/master
GuoPhilipse Jun 7, 2020
fd677c9
Merge pull request #13 from apache/master
GuoPhilipse Jun 8, 2020
93b1f63
Merge pull request #14 from apache/master
GuoPhilipse Jun 10, 2020
a5b5474
Merge pull request #15 from apache/master
GuoPhilipse Jun 11, 2020
f4556a4
Merge pull request #16 from apache/master
GuoPhilipse Jun 11, 2020
6071006
Merge pull request #17 from apache/master
GuoPhilipse Jun 26, 2020
596b842
Merge pull request #18 from apache/master
GuoPhilipse Jun 29, 2020
dc24541
Merge pull request #19 from apache/master
GuoPhilipse Jul 5, 2020
c6f541b
Merge pull request #20 from apache/master
GuoPhilipse Jul 9, 2020
a80fa85
update case when docs
GuoPhilipse Jul 9, 2020
e4c2a17
update case when docs
GuoPhilipse Jul 9, 2020
24b64a8
update case when docs
GuoPhilipse Jul 9, 2020
3b15c75
fix capital issue.etc
GuoPhilipse Jul 10, 2020
0d9e72d
improve syntax desc
GuoPhilipse Jul 10, 2020
a119c85
add missing key words
GuoPhilipse Jul 11, 2020
61c57d1
fix spell error
GuoPhilipse Jul 11, 2020
b3a3248
update pivot and lateral view key words
GuoPhilipse Jul 12, 2020
2ee5419
update lateral view usgae
GuoPhilipse Jul 12, 2020
95071f3
update docs
GuoPhilipse Jul 13, 2020
bbce7d0
trigger rebuild
GuoPhilipse Jul 13, 2020
15aae2b
trigger rebuild
GuoPhilipse Jul 14, 2020
0625ca8
remove spark version
GuoPhilipse Jul 14, 2020
03da596
update docs
GuoPhilipse Jul 15, 2020
5b562eb
update docs
GuoPhilipse Jul 16, 2020
1570d76
update docs
GuoPhilipse Jul 16, 2020
d72139e
update docs
GuoPhilipse Jul 16, 2020
21ebafc
update docs
GuoPhilipse Jul 16, 2020
e5a1cf1
update docs
GuoPhilipse Jul 17, 2020
b281494
update docs
GuoPhilipse Jul 17, 2020
bed618b
update docs\
GuoPhilipse Jul 18, 2020
caa7130
update docs
GuoPhilipse Jul 19, 2020
2813735
update docs
GuoPhilipse Jul 20, 2020
ffa0603
update docs
GuoPhilipse Jul 21, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/_data/menu-sql.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,12 @@
url: sql-ref-syntax-qry-select-tvf.html
- text: Window Function
url: sql-ref-syntax-qry-select-window.html
- text: CASE Clause
url: sql-ref-syntax-qry-select-case.html
- text: LATERAL VIEW Clause
url: sql-ref-syntax-qry-select-lateral-view.html
- text: PIVOT Clause
url: sql-ref-syntax-qry-select-pivot.html
- text: EXPLAIN
url: sql-ref-syntax-qry-explain.html
- text: Auxiliary Statements
Expand Down
94 changes: 90 additions & 4 deletions docs/sql-ref-syntax-ddl-create-table-hiveformat.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ CREATE [ EXTERNAL ] TABLE [ IF NOT EXISTS ] table_identifier
[ LOCATION path ]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The bucketSpec is still missing in CREATE HIVE FORMAT table, right?

    [ CLUSTERED BY ( col_name3, col_name4, ... ) 
        [ SORTED BY ( col_name [ ASC | DESC ], ... ) ] 
        INTO num_buckets BUCKETS ]

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason we did not add it? @huaxingao @GuoPhilipse

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, we missed that.
@GuoPhilipse Could you please have a follow-up to add bucketSpec? Thanks!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we need it, will add it soon.

[ TBLPROPERTIES ( key1=val1, key2=val2, ... ) ]
[ AS select_statement ]

row_format:
: SERDE serde_class [ WITH SERDEPROPERTIES (k1=v1, k2=v2, ... ) ]
| DELIMITED [ FIELDS TERMINATED BY fields_termiated_char [ ESCAPED BY escaped_char ] ]
[ COLLECTION ITEMS TERMINATED BY collection_items_termiated_char ]
[ MAP KEYS TERMINATED BY map_key_termiated_char ]
[ LINES TERMINATED BY row_termiated_char ]
[ NULL DEFINED AS null_char ]
```

Note that, the clauses between the columns definition clause and the AS SELECT clause can come in
Expand All @@ -51,15 +59,55 @@ as any order. For example, you can write COMMENT table_comment after TBLPROPERTI

* **EXTERNAL**

Table is defined using the path provided as LOCATION, does not use default location for this table.
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**

Use the `SERDE` clause to specify a custom SerDe for one table. Otherwise, use the `DELIMITED` clause to use the native SerDe and specify the delimiter, escape character, null character and so on.

* **SERDE**

Specifies a custom SerDe for one table.

* **serde_class**

Specifies a fully-qualified class name of a custom SerDe.

* **SERDEPROPERTIES**

A list of key-value pairs that is used to tag the SerDe definition.

* **DELIMITED**

The `DELIMITED` clause can be used to specify the native SerDe and state the delimiter, escape character, null character and so on.

* **FIELDS TERMINATED BY**

* **ROW FORMAT**
Used to define a column separator.

* **COLLECTION ITEMS TERMINATED BY**

SERDE is used to specify a custom SerDe or the DELIMITED clause in order to use the native SerDe.
Used to define a collection item separator.

* **MAP KEYS TERMINATED BY**

Used to define a map key separator.

* **LINES TERMINATED BY**

Used to define a row separator.

* **NULL DEFINED AS**

Used to define the specific value for NULL.

* **ESCAPED BY**

Used for escape mechanism.

* **STORED AS**

Expand Down Expand Up @@ -114,9 +162,47 @@ 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)
ADD JAR /tmp/hive_serde_example.jar;

CREATE EXTERNAL TABLE family (id INT, name STRING)
ROW FORMAT SERDE 'com.ly.spark.serde.SerDeExample'
STORED AS INPUTFORMAT 'com.ly.spark.example.serde.io.SerDeExampleInputFormat'
OUTPUTFORMAT 'com.ly.spark.example.serde.io.SerDeExampleOutputFormat'
LOCATION '/tmp/family/';
```

### Related Statements
Expand Down
109 changes: 109 additions & 0 deletions docs/sql-ref-syntax-qry-select-case.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
---
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 any expression that evaluates to a result type `boolean`. Two or
more expressions may be combined together using the logical
operators ( `AND`, `OR` ).

* **then_expression**

Specifies the then expression based on the `boolean_expression` condition; `then_expression` and `else_expression` should all be same type or coercible to a common type.

* **else_expression**

Specifies the default expression; `then_expression` and `else_expression` should all be same type or coercible to a common type.

### Examples

```sql
CREATE TABLE person (id INT, name STRING, age INT);
INSERT INTO person VALUES
(100, 'John', 30),
(200, 'Mary', NULL),
(300, 'Mike', 80),
(400, 'Dan', 50);

SELECT id, CASE WHEN id > 200 THEN 'bigger' ELSE 'small' END FROM person;
+------+--------------------------------------------------+
| id | CASE WHEN (id > 200) THEN bigger ELSE small END |
+------+--------------------------------------------------+
| 100 | small |
| 200 | small |
| 300 | bigger |
| 400 | bigger |
+------+--------------------------------------------------+

SELECT id, CASE id WHEN 100 then 'bigger' WHEN id > 300 THEN '300' ELSE 'small' END FROM person;
+------+-----------------------------------------------------------------------------------------------+
| id | CASE WHEN (id = 100) THEN bigger WHEN (id = CAST((id > 300) AS INT)) THEN 300 ELSE small END |
+------+-----------------------------------------------------------------------------------------------+
| 100 | bigger |
| 200 | small |
| 300 | small |
| 400 | small |
+------+-----------------------------------------------------------------------------------------------+

SELECT * FROM person
WHERE
CASE 1 = 1
WHEN 100 THEN 'big'
WHEN 200 THEN 'bigger'
WHEN 300 THEN 'biggest'
ELSE 'small'
END = 'small';
+------+-------+-------+
| id | name | age |
+------+-------+-------+
| 100 | John | 30 |
| 200 | Mary | NULL |
| 300 | Mike | 80 |
| 400 | Dan | 50 |
+------+-------+-------+
```

### 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)
* [PIVOT Clause](sql-ref-syntax-qry-select-pivot.html)
* [LATERAL VIEW Clause](sql-ref-syntax-qry-select-lateral-view.html)
3 changes: 3 additions & 0 deletions docs/sql-ref-syntax-qry-select-clusterby.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,6 @@ SELECT age, name FROM person CLUSTER BY age;
* [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)
* [CASE Clause](sql-ref-syntax-qry-select-case.html)
* [PIVOT Clause](sql-ref-syntax-qry-select-pivot.html)
* [LATERAL VIEW Clause](sql-ref-syntax-qry-select-lateral-view.html)
3 changes: 3 additions & 0 deletions docs/sql-ref-syntax-qry-select-distribute-by.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,6 @@ SELECT age, name FROM person DISTRIBUTE BY age;
* [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)
* [CASE Clause](sql-ref-syntax-qry-select-case.html)
* [PIVOT Clause](sql-ref-syntax-qry-select-pivot.html)
* [LATERAL VIEW Clause](sql-ref-syntax-qry-select-lateral-view.html)
27 changes: 27 additions & 0 deletions docs/sql-ref-syntax-qry-select-groupby.md
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,30 @@ SELECT city, car_model, sum(quantity) AS sum FROM dealer
| San Jose| HondaAccord| 8|
| San Jose| HondaCivic| 5|
+---------+------------+---+

--Prepare data for ignore nulls example
CREATE TABLE person (id INT, name STRING, age INT);
INSERT INTO person VALUES
(100, 'Mary', NULL),
(200, 'John', 30),
(300, 'Mike', 80),
(400, 'Dan', 50);

--Select the first row in cloumn age
SELECT FIRST(age) FROM person;
+--------------------+
| first(age, false) |
+--------------------+
| NULL |
+--------------------+

--Get the first row in cloumn `age` ignore nulls,last row in column `id` and sum of cloumn `id`.
SELECT FIRST(age IGNORE NULLS), LAST(id), SUM(id) FROM person;
+-------------------+------------------+----------+
| first(age, true) | last(id, false) | sum(id) |
+-------------------+------------------+----------+
| 30 | 400 | 1000 |
+-------------------+------------------+----------+
```

### Related Statements
Expand All @@ -272,3 +296,6 @@ SELECT city, car_model, sum(quantity) AS sum FROM dealer
* [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)
* [CASE Clause](sql-ref-syntax-qry-select-case.html)
* [PIVOT Clause](sql-ref-syntax-qry-select-pivot.html)
* [LATERAL VIEW Clause](sql-ref-syntax-qry-select-lateral-view.html)
3 changes: 3 additions & 0 deletions docs/sql-ref-syntax-qry-select-having.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,6 @@ SELECT sum(quantity) AS sum FROM dealer HAVING sum(quantity) > 10;
* [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)
* [CASE Clause](sql-ref-syntax-qry-select-case.html)
* [PIVOT Clause](sql-ref-syntax-qry-select-pivot.html)
* [LATERAL VIEW Clause](sql-ref-syntax-qry-select-lateral-view.html)
Loading