2017-10-18 62 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分区列是最后一个元素你的名单,这意味着你不能做选择*,而不得不选择字段到字段,并把你的选择语句的状态和结束