2017-10-18 65 views
0

我已經創建了一個外部表,如下面中間一列:分區蜂巢表與另一個外部表

create external table if not exists complaints (date_received string, product string, sub_product string, issue string, sub_issue string, consumer_complaint_narrative string, state string, company_public_response string, company varchar(50), zipcode int, tags string, consumer_consent_provided string, submitted_via string, date_sent_company string, company_response string, timely_response string, consumer_disputed string, complaint_id int) row format delimited fields terminated by ',' stored as textfile location 'hdfs:hostname:8020/complaints/'; 

現在我想創建一個分區作爲國家另一個表complaints_new並具有從所有數據上表。這如何成爲現實?

我嘗試以下:

create external table if not exists complaints_new (date_received string, product string, sub_product string, issue string, sub_issue string, consumer_complaint_narrative string, company_public_response string, company varchar(50), zipcode int, tags string, consumer_consent_provided string, submitted_via string, date_sent_company string, company_response string, timely_response string, consumer_disputed string, complaint_id int) partitioned by (state varchar(20)) row format delimited fields terminated by ',' stored as textfile location 'hdfs://hostname:8020/complaints/'; 

SET hive.exec.dynamic.partition = true; 
SET hive.exec.dynamic.partition.mode = nonstrict; 
SET hive.mapred.mode = nonstrict; 

insert into table complaints_new partition(state) select * from complaints; 

查詢失敗。

+0

它是如何失敗?請提供錯誤日誌。如果不存在,創建外部表將不會創建表(如果它已經存在)。刪除並創建沒有'如果不存在'選項,以確保表正確地重新創建 – leftjoin

回答

0

你在這裏有幾個問題......你指向的是同一位置,這意味着你將讀取並覆蓋該位置......另一個問題是Hive期望th分區列是最後一個元素你的名單,這意味着你不能做選擇*,而不得不選擇字段到字段,並把你的選擇語句的狀態和結束