如何插入到配置单元表中,按从临时表读取的日期进行分区?

z2acfund  于 2021-05-27  发布在  Hadoop
关注(0)|答案(1)|浏览(432)

这个问题在这里已经有答案了

hive动态分区(2个答案)
10个月前关门了。
我有一个没有任何分区的hive temp表,其中包含所需的数据。我想选择此数据并插入到另一个按日期分区的表中。我尝试了以下技巧,但运气不好。
源表架构

CREATE TABLE cls_staging.cls_billing_address_em_tmp
( col1 string,
 col2 string,
col3 string);

目标表:

CREATE TABLE cls_staging.cls_billing_address_em_tmp
    ( col1 string,
     col2 string,
    col3 string) 
    PARTITIONED BY (
       curr_date string) 
      STORED AS ORC;

插入目标表的查询:

insert overwrite table cls_staging.cls_billing_address_em_tmp partition (record_date)  select col1, col2, col3, FROM_UNIXTIME(UNIX_TIMESTAMP()) from myDB.mytbl;

错误

Dynamic partition strict mode requires at least one static partition column

第二

insert overwrite table cls_staging.cls_billing_address_em_tmp partition (record_date = FROM_UNIXTIME(UNIX_TIMESTAMP()))  select col1, col2, col3 from myDB.mytbl;

错误:

cannot recognize input near 'FROM_UNIXTIME' '(' 'UNIX_TIMESTAMP'
qni6mghb

qni6mghb1#

第一次打开动态分区和非严格模式:

set hive.exec.dynamic.partition=true;
set hive.exec.dynamic.partition.mode=nonstrict;

insert overwrite table cls_staging.cls_billing_address_em_tmp partition (record_date)  
select col1, col2, col3, current_timestamp from myDB.mytbl;

第二:不要使用 unix_timestamp() 为此,因为它将生成许多不同的时间戳,所以使用 current_timestamp 常数,读这个:https://stackoverflow.com/a/58081191/2700344

相关问题