官网介绍:
https://cwiki.apache.org/confluence/display/Hive/LanguageManual+Types
本章将介绍hive不同的数据类型,用于创建表,hive数据类型分为四种类型,如下:
- 数值类型(Numeric Type)
- 时间类型(Date/Time Type)
- 字符串类型(string Type)
- misc Type
- 复杂类型(complex Type)
1.numericType
| 类型 | 后缀 | 示例 | 数据范围 | 存储 | 说明 |
|---|---|---|---|---|---|
| tinyint | Y | 10Y | -128 to 127 | 1 byte | |
| smallint | S | 10S | -32768-32767 | 2 byte | |
| integer | - | 10 | -2,147,483,648 to 2,147,483,648 to 2,147,483,647 | 4 byte | |
| int | - | 10 | -2,147,483,648 to 2,147,483,648 to 2,147,483,647 | 4 byte | 2.2.0integer的同义词引入 |
| bigint | L | 10L | -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 | 8 byte | |
| float | 4 byte | ||||
| double | 8 byte | ||||
| double precision | double的别名 avaliable starting with 2.2.0 | ||||
| decimal | 0.11.0引入,精度38位,0.13.0引入用户可定义精度和规模 | ||||
| numeric | same as decimal ,starting with 3.0.0 |
2.Date/Time Type
| 类型 | 说明 |
|---|---|
| timestamp | starting with 0.8.0 |
| date | starting with 0.12.0 |
| interval | starting with 1.2.0 |
3.字符串类型
可以使用单引号(”)或双引号(“”)来指定
| 数据类型 | 长度 | 版本说明 |
|---|---|---|
| string | ||
| varchar | 1-65355 | 0.12.0 |
| char | 255 | 0.13.0 |
4.misc Type
| 类型 | 版本 |
|---|---|
| boolean | |
| binary | 0.8.0 |
5.复杂类型
| 类型 | 实例 | 版本 |
|---|---|---|
| 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,…> | 0.7.0 |
3.时间戳
支持传统的UNIX时间戳可选的纳秒精度。他支持java.sql.timestamp格式”yyyy-MM-dd HH:MM:SS.fffffffff”和”yyyy-MM-dd HH:MM:ss.ffffffff”
4.日期
yyyy-MM-dd
5.小数点
DECIMAL(precision,scale)
decimal(10,0)
二.联合类型
版权声明:本文为tpyqwe原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。