簡體   English   中英

從Hive視圖加載Hive分區

[英]Load Hive partition from Hive view

我有一個帶有4個分區的外部Hive表。 我也有基於不同的Hive表的4個Hive視圖。

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

我知道我可以從如下所示的視圖創建未分區的配置單元表

CREATE TABLE hive_table AS SELECT * FROM hive_view; 

但是有沒有辦法覆蓋視圖數據中的分區?

是的,有一種方法:

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

在執行此類操作之前,需要將hive.exec.dynamic.partition設置為true 在此處查看詳細信息: Hive語言手冊DML-動態分區

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;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM