Hive 简明教程
Hive - Data Types
本章将介绍 Hive 中的各种数据类型,这些数据类型都参与表创建。Hive 中的所有数据类型都分为以下四类:
This chapter takes you through the different data types in Hive, which are involved in the table creation. All the data types in Hive are classified into four types, given as follows:
-
Column Types
-
Literals
-
Null Values
-
Complex Types
Column Types
列类型用作 Hive 的列数据类型。如下所示:
Column type are used as column data types of Hive. They are as follows:
Integral Types
整型数据类型可以使用整数数据类型 INT 指定。当数据范围超过INT的范围时,您需要使用BIGINT,如果数据范围小于INT,则可以使用SMALLINT。TINYINT小于SMALLINT。
Integer type data can be specified using integral data types, INT. When the data range exceeds the range of INT, you need to use BIGINT and if the data range is smaller than the INT, you use SMALLINT. TINYINT is smaller than SMALLINT.
下表描绘了各种 INT 数据类型:
The following table depicts various INT data types:
Type |
Postfix |
Example |
TINYINT |
Y |
10Y |
SMALLINT |
S |
10S |
INT |
- |
10 |
BIGINT |
L |
10L |
String Types
字符串类型数据类型可以使用单引号(')或双引号(")指定。它包含两种数据类型:VARCHAR 和 CHAR。Hive 遵循 C 类型转义字符。
String type data types can be specified using single quotes (' ') or double quotes (" "). It contains two data types: VARCHAR and CHAR. Hive follows C-types escape characters.
下表列出了各种 CHAR 数据类型:
The following table depicts various CHAR data types:
Data Type |
Length |
VARCHAR |
1 to 65355 |
CHAR |
255 |
Timestamp
它支持传统的 UNIX 时间戳,并具有可选的纳秒精度。它支持 java.sql.Timestamp 格式“YYYY-MM-DD HH:MM:SS.fffffffff”和格式“yyyy-mm-dd hh:mm:ss.ffffffffff”。
It supports traditional UNIX timestamp with optional nanosecond precision. It supports java.sql.Timestamp format “YYYY-MM-DD HH:MM:SS.fffffffff” and format “yyyy-mm-dd hh:mm:ss.ffffffffff”.
Dates
DATE 值以年/月/日格式描述,形式为 {{YYYY-MM-DD}}。
DATE values are described in year/month/day format in the form {{YYYY-MM-DD}}.
Decimals
Hive 中的 DECIMAL 类型与 Java 的 Big Decimal 格式相同。它用于表示不可变的任意精度。语法和示例如下:
The DECIMAL type in Hive is as same as Big Decimal format of Java. It is used for representing immutable arbitrary precision. The syntax and example is as follows:
DECIMAL(precision, scale)
decimal(10,0)
Union Types
Union 是异构数据类型的集合。您可以使用 create union 创建一个实例。语法和示例如下:
Union is a collection of heterogeneous data types. You can create an instance using create union. The syntax and example is as follows:
UNIONTYPE<int, double, array<string>, struct<a:int,b:string>>
{0:1}
{1:2.0}
{2:["three","four"]}
{3:{"a":5,"b":"five"}}
{2:["six","seven"]}
{3:{"a":8,"b":"eight"}}
{0:9}
{1:10.0}
Literals
Hive 中使用了以下文字:
The following literals are used in Hive: