You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
| DELIMITED [ FIELDS TERMINATED BY fields_termiated_char [ ESCAPED BY escaped_char ] ]
43
+
[ COLLECTION ITEMS TERMINATED BY collection_items_termiated_char ]
44
+
[ MAP KEYS TERMINATED BY map_key_termiated_char ]
45
+
[ LINES TERMINATED BY row_termiated_char ]
46
+
[ NULL DEFINED AS null_char ]
39
47
```
40
48
41
49
Note that, the clauses between the columns definition clause and the AS SELECT clause can come in
@@ -51,15 +59,55 @@ as any order. For example, you can write COMMENT table_comment after TBLPROPERTI
51
59
52
60
***EXTERNAL**
53
61
54
-
Table is defined using the path provided as LOCATION, does not use default location for this table.
62
+
Table is defined using the path provided as `LOCATION`, does not use default location for this table.
55
63
56
64
***PARTITIONED BY**
57
65
58
66
Partitions are created on the table, based on the columns specified.
67
+
68
+
***row_format**
69
+
70
+
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.
71
+
72
+
***SERDE**
73
+
74
+
Specifies a custom SerDe for one table.
75
+
76
+
***serde_class**
77
+
78
+
Specifies a fully-qualified class name of a custom SerDe.
79
+
80
+
***SERDEPROPERTIES**
81
+
82
+
A list of key-value pairs that is used to tag the SerDe definition.
83
+
84
+
***DELIMITED**
85
+
86
+
The `DELIMITED` clause can be used to specify the native SerDe and state the delimiter, escape character, null character and so on.
87
+
88
+
***FIELDS TERMINATED BY**
59
89
60
-
***ROW FORMAT**
90
+
Used to define a column separator.
91
+
92
+
***COLLECTION ITEMS TERMINATED BY**
61
93
62
-
SERDE is used to specify a custom SerDe or the DELIMITED clause in order to use the native SerDe.
94
+
Used to define a collection item separator.
95
+
96
+
***MAP KEYS TERMINATED BY**
97
+
98
+
Used to define a map key separator.
99
+
100
+
***LINES TERMINATED BY**
101
+
102
+
Used to define a row separator.
103
+
104
+
***NULL DEFINED AS**
105
+
106
+
Used to define the specific value for NULL.
107
+
108
+
***ESCAPED BY**
109
+
110
+
Used for escape mechanism.
63
111
64
112
***STORED AS**
65
113
@@ -114,9 +162,47 @@ CREATE TABLE student (id INT, name STRING)
114
162
PARTITIONED BY (age INT);
115
163
116
164
--Use Row Format and file format
117
-
CREATETABLEstudent (id INT,name STRING)
165
+
CREATETABLEstudent (id INT,name STRING)
118
166
ROW FORMAT DELIMITED FIELDS TERMINATED BY ','
119
167
STORED AS TEXTFILE;
168
+
169
+
--Use complex datatype
170
+
CREATE EXTERNAL TABLE family(
171
+
name STRING,
172
+
friends ARRAY<STRING>,
173
+
children MAP<STRING, INT>,
174
+
address STRUCT<street: STRING, city: STRING>
175
+
)
176
+
ROW FORMAT DELIMITED FIELDS TERMINATED BY ',' ESCAPED BY '\\'
177
+
COLLECTION ITEMS TERMINATED BY '_'
178
+
MAP KEYS TERMINATED BY ':'
179
+
LINES TERMINATED BY '\n'
180
+
NULL DEFINED AS'foonull'
181
+
STORED AS TEXTFILE
182
+
LOCATION '/tmp/family/';
183
+
184
+
--Use predefined custom SerDe
185
+
CREATETABLEavroExample
186
+
ROW FORMAT SERDE 'org.apache.hadoop.hive.serde2.avro.AvroSerDe'
187
+
STORED AS INPUTFORMAT 'org.apache.hadoop.hive.ql.io.avro.AvroContainerInputFormat'
Licensed to the Apache Software Foundation (ASF) under one or more
7
+
contributor license agreements. See the NOTICE file distributed with
8
+
this work for additional information regarding copyright ownership.
9
+
The ASF licenses this file to You under the Apache License, Version 2.0
10
+
(the "License"); you may not use this file except in compliance with
11
+
the License. You may obtain a copy of the License at
12
+
13
+
http://www.apache.org/licenses/LICENSE-2.0
14
+
15
+
Unless required by applicable law or agreed to in writing, software
16
+
distributed under the License is distributed on an "AS IS" BASIS,
17
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18
+
See the License for the specific language governing permissions and
19
+
limitations under the License.
20
+
---
21
+
22
+
### Description
23
+
24
+
`CASE` clause uses a rule to return a specific result based on the specified condition, similar to if/else statements in other programming languages.
25
+
26
+
### Syntax
27
+
28
+
```sql
29
+
CASE [ expression ] { WHEN boolean_expression THEN then_expression } [ ... ]
30
+
[ ELSE else_expression ]
31
+
END
32
+
```
33
+
34
+
### Parameters
35
+
36
+
***boolean_expression**
37
+
38
+
Specifies any expression that evaluates to a result type `boolean`. Two or
39
+
more expressions may be combined together using the logical
40
+
operators ( `AND`, `OR` ).
41
+
42
+
***then_expression**
43
+
44
+
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.
45
+
46
+
***else_expression**
47
+
48
+
Specifies the default expression; `then_expression` and `else_expression` should all be same type or coercible to a common type.
49
+
50
+
### Examples
51
+
52
+
```sql
53
+
CREATETABLEperson (id INT, name STRING, age INT);
54
+
INSERT INTO person VALUES
55
+
(100, 'John', 30),
56
+
(200, 'Mary', NULL),
57
+
(300, 'Mike', 80),
58
+
(400, 'Dan', 50);
59
+
60
+
SELECT id, CASE WHEN id >200 THEN 'bigger' ELSE 'small' END FROM person;
0 commit comments