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

问题描述 投票:0回答:1

我有一个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'
hadoop hive hiveql hadoop-partitioning hive-query
1个回答
0
投票

第一个开机动态分区和非严格模式:

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

© www.soinside.com 2019 - 2024. All rights reserved.