0

我有一个 Hive 临时表,没有任何具有所需数据的分区。我想选择这些数据并插入到另一个按日期分区的表中。我尝试了以下技术但没有运气。

源表架构

 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'
4

1 回答 1

2

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

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;

2nd:不要unix_timestamp()用于这个目的,因为它会产生许多不同的时间戳,使用current_timestamp常量,阅读这个:https ://stackoverflow.com/a/58081191/2700344

于 2020-03-11T04:51:45.580 回答