2014-10-10 97 views
0

我有一個帶有4個分區的外部Hive表。我還有4個基於不同Hive表的配置單元視圖。從Hive視圖加載Hive分區

每週我都希望配置單元視圖覆蓋外部配置單元表中的分區。

我知道我可以從下面

CREATE TABLE hive_table AS SELECT * FROM hive_view; 

像秀視圖中創建一個未分區蜂巢表,但有沒有辦法覆蓋從視圖中的數據分區?

回答

0

是的,有一種方法:

INSERT OVERWRITE TABLE <table_name> 
PARTITION(<partition_clause>) 
SELECT <select_clause> 

它是這樣的操作之前,設置hive.exec.dynamic.partitiontrue需要。在此處查看詳情:Hive Language Manual DML - Dynamic Partitions

-1
set hive.exec.dynamic.partition=true; 

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


--partition table 

create external table pracitse_part (
id int, 
first_name string, 
last_name string, 
email string, 
ip_address string 
) 
partitioned by (gender string) 
row format delimited 
fields terminated by ','; 

--create veiw table 

create view practise_view as 
    select p.* 
    from practise p join practise_temp pt 
    on p.id=pt.id 
    where p.id < 11; 

--load data into partition table from view table 

insert overwrite table pracitse_part partition(gender) 
select id,first_name,last_name,email,ip_address,gender from practise_view;