2017-10-19 79 views
0
create table h5_qti_desc 
(h5id string, 
    query string, 
    title string, 
    item string, 
    query_ids string, 
    title_ids string, 
    item_ids string, 
    label bigint 
)PARTITIONED BY (day string) LIFECYCLE 160; 

insert overwrite into h5_qti_desc 
select * from aaa 
; 

我創建了一個名爲h5_qti_desc的表,並且我想從另一個aaa表中插入它,它具有day的字段並且在aaa中沒有分區。 表aaa有好幾天,比如'20171010','20171015'...
如何在日期中將h5_qti_desc作爲分區插入一次,並將aaa中的日期作爲h5_qti_desc分區中的日期。如何在Hive中將原始日期作爲分區插入表中?

回答

2

您可以使用Hive動態分區功能插入數據。動態分區插入(或多分區插入)旨在通過動態確定在掃描輸入表時應創建和填充哪些分區來解決此問題。

下面是一個使用一個INSERT語句加載數據到所有分割的例子:

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

hive>INSERT OVERWRITE TABLE h5_qti_desc PARTITION(day) 
      SELECT * FROM aaa 
      DISTRIBUTE day;