| 类型 | 描述 | 示例 |
| — | — | — |
| BOOLEAN | true/false | TRUE |
| TINYINT | 1字节有符号整数,从-128到127 | 1Y |
| SMALLINT | 2字节有符号整数,从-32768到32767 | 1S |
| INT | 4字节有符号整数,从-2147483648到2147483647 | 1 |
| BIGINT | 8字节有符号整数,
从-9223372036854775808到9223372036854
【一线大厂Java面试题解析+核心总结学习笔记+最新架构讲解视频+实战项目源码讲义】 浏览器打开:qq.cn.hn/FTf 免费领取
775807 | 1L |
| FLOAT | 4字节单精度浮点数 | 1.0 |
| DOUBLE | 8字节(64位)双精度浮点数 | 1.0 |
| DECIMAL | 任意精度有符号小数 | 1.0 |
| STRING | 无上限可变长度字符串 | ‘a’, “a” |
| VARCHAR | 可变长度字符串 | ‘a’, “a” |
| CHAR | 固定长度字符串 | ‘a’, “a” |
| BINARY | 字节数组 | - |
| TIMESTAMP | 精度到纳秒的时间戳 | ‘2020-03-01 00:00:00’ |
| DATE | 日期 | ‘2020-01-01’ |
STRING,变长,无需最大长度声明,理论上能存储2GB字符;
VARCHAR,变长,需要声明最大长度(1到65535之间),例如VARCHAR(100);
CHAR,定长,如CHAR(100);
create table t1(
int_field INT,
string_field STRING,
boolean_field BOOLEAN,
date_field DATE,
timestamp_field TIMESTAMP
)
ROW FORMAT DELIMITED FIELDS TERMINATED BY ‘\t’
STORED AS TEXTFILE;
insert into t1
values
(101, ‘a101’, true, ‘2020-01-01’, ‘2020-03-01 00:00:00’);
insert into t1
select
103, ‘a103’, true, ‘2020-01-01’, current_timestamp()
from t1 limit 1;
hive> select * from t1;
OK
101 a101 true 2020-01-01 2020-03-01 00:00:00
103 a103 true 2020-01-01 2020-10-27 20:42:35.729
Time taken: 0.062 seconds, Fetched: 2 row(s)
select unix_timestamp();
响应:
hive> select unix_timestamp();
OK
1603802631
Time taken: 0.028 seconds, Fetched: 1 row(s)
select cast(date_field as timestamp) from t1;
响应:
hive> select cast(date_field as timestamp) from t1;
OK
2020-01-01 00:00:00
2020-01-01 00:00:00
Time taken: 0.051 seconds, Fetched: 2 row(s)
select to_date(timestamp_field) from t1;
响应: