使用另一个外部表中间的列对hive表进行分区

时间:2017-10-18 04:41:13

标签: hadoop hive hiveql

我创建了一个外部表格如下:

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/';

现在我想用partition作为state创建另一个表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;

查询失败。

1 个答案:

答案 0 :(得分:0)

你在这里有一些问题......你指的是同一个位置,这意味着你将阅读并覆盖该位置......另一个问题是Hive希望分区列成为你的最后一个元素list,这意味着你不能选择*,而是你必须选择字段到字段并放置select语句的状态和结尾

相关问题