首先创建一个外部分区表(分区字段设置为时间类型(timestamp))
辅助表test
创建普通外部表
create external table test
(
id string comment '账号',
datekey timestamp comment '交易时间',
name string comment '公司名称'
)
location '/xx/lrz_test';
create external table testa
(
id string comment '账号',
datekey timestamp comment '交易时间',
name string comment '公司名称'
)
partitioned by (datekey1 timestamp)
location '/xxx/testa';
插入数据
insert overwrite TABLE testa partition (datekey1=current_date)
select
id,
datekey s,
name
from test
此时就会报错,hive不支持分区字段为timestamp类型
创建一个外部分区表(分区字段设置为字符类型(string))可以解决这个问题
create external table testa
(
id string comment '账号',
datekey timestamp comment '交易时间',
name string comment '公司名称'
)
partitioned by (datekey1 string)
location '/xxx/testa';
插入数据
insert overwrite TABLE testa partition (datekey1='2021-05-21')
select
id,
datekey s,
name
from test