hive支持的数据类型路下
数值类型 Numeric Types
TINYINT(1字节,数据范围:-128to127)SMALLINT(2字节,数据范围:-32,768to32,767)INT(4字节,数据范围:-2,147,483,648to2,147,483,647)BIGINT(8字节,数据范围:-9,223,372,036,854,775,808to9,223,372,036,854,775,807)FLOAT(4字节, 单精度浮点数)DOUBLE(8字节,双精度浮点数)DECIMAL
日期/时间类型 Date/Time Types
字符串类型 String Types
STRINGVARCHAR(Hive 0.12.0以上支持)CHAR(Hive 0.13.0以上支持)
Misc Types
复合类型 Complex Types
- arrays:
ARRAY<data_type> - maps:
MAP<primitive_type, data_type> - structs:
STRUCT<col_name : data_type [COMMENT col_comment], ...> - union:
UNIONTYPE<data_type, data_type, ...>(Hive 0.7.0以上支持)
列类型 Column Types
Integral Types (TINYINT, SMALLINT, INT, BIGINT)
数值类型默认是int,如果数值超出int的范围,就会被解释为bigint。
数值后面加上后缀表示:
|
Type |
Postfix |
Example |
|---|---|---|
| TINYINT | Y | 100Y |
| SMALLINT | S | 100S |
| BIGINT | L | 100L |
Strings
字符串可以用单引号(')或双引号(“)。Hive在字符串中使用C-Style的转义。
Varchar
Varchar types 创建的长度是 ( 1 到 65355), 在字符串中容许使用最大数量的字符. 如果string类型转换成varchar类型, 长度超过了最大值,将会被截断。 字符长度是由字符串所包含的数量决定.
Char
最大固定长度255.
Timestamps
支持传统的unix时间戳,可选的纳秒级精度。
支持的转换:
- 整型数值类型:解读为以秒为单位的UNIX时间戳
- 浮动点数值类型:解读为以秒和小数精度为单位的UNIX时间戳
- 字符串:JDBC兼容的java.sql.Timestamp格式“YYYY-MM-DD HH:MM:SS.fffffffff”(9位小数位精度)
时间戳被解释是与timezone无关,存储为从UNIX纪元的偏移量。提供便利的UDF和时区转换(to_utc_timestamp,from_utc_timestamp)。
所有现有datetime的UDF(月,日,年,小时,等)可以工作于TIMESTAMP数据类型。
Dates
日期值描述一个特定的年/月/日的{ { YYYY - MM - DD } }.
例, DATE '2013-01-01'. Date 类型没有时间.
Date 类型支持的范围是是 0000-01-01 to 9999-12-31, 依赖于原始的Java支持的日期类型.
转换 Dates
Date类型能和 Timestamp, String互相转换.
|
Valid casts to/from Date type |
Result |
|---|---|
| cast(date as date) | Same date value |
| cast(timestamp as date) | The year/month/day of the timestamp is determined, based on the local timezone, and returned as a date value. |
| cast(string as date) | If the string is in the form 'YYYY-MM-DD', then a date value corresponding to that year/month/day is returned. If the string value does not match this formate, then NULL is returned. |
| cast(date as timestamp) | A timestamp value is generated corresponding to midnight of the year/month/day of the date value, based on the local timezone. |
| cast(date as string) | The year/month/day represented by the Date is formatted as a string in the form 'YYYY-MM-DD'. |
本文详细介绍了Hive支持的各种数据类型,包括数值类型、日期/时间类型、字符串类型、复合类型及列类型,并提供了每种类型的特性说明和使用示例。
1639

被折叠的 条评论
为什么被折叠?



