简体   繁体   English

对一个配置单元表进行分区,并在另一个外部表的中间添加一列

[英]Partition a hive table with a column in middle from another external table

I have created an external table as below: 我创建了一个外部表,如下所示:

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

Now I want to create another table complaints_new with partition as state and have all the data from above table. 现在,我想创建另一个表,以状态为partition的抱怨和新表,并从表中获取所有数据。 How can this be acheived? 如何做到这一点?

I tried the below: 我尝试了以下方法:

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;

The query is failing. 查询失败。

您在这里遇到了一些问题...您指向的位置相同,这意味着您将要读取和覆盖该位置...另一个问题是Hive希望分区列是列表中的最后一个元素,它意味着您不能选择*,而是必须选择一个字段到另一个字段,并放置状态和select语句的结尾

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM