简体   繁体   中英

Inserting into Hive table - Non Partitioned table to Partitioned table - Cannot insert into target table because column number/types

When I tried to insert into a Partiotioned table I am getting the bellow error SemanticException [Error 10044]: Line 1:23 Cannot insert into target table because column number/types are different ''US'': Table insclause-0 has 2 columns, but query has 3 columns.

My Input data

1,aaa,US
2,bbb,US
3,ccc,IN
4,ddd,US
5,eee,IN
6,fff,IN
7,ggg,US

Created hive table tx

create table tx (no int,name string,country string) ROW FORMAT DELIMITED FIELDS TERMINATED BY ',';

Created Partitioned table t1 partitioned by country

create table t1 (no int,name string) PARTITIONED BY (country string)  ROW FORMAT DELIMITED FIELDS TERMINATED BY ',';

I tried the bellow two insert, but failed

    INSERT OVERWRITE TABLE t1 PARTITION (country='US') 
SELECT *   from tx where country = 'US';

    INSERT OVERWRITE TABLE t1 PARTITION (country='US') 
SELECT no,name,country from tx where country = 'US';

Error : SemanticException [Error 10044]: Line 1:23 Cannot insert into target table because column number/types are different ''US'': Table insclause-0 has 2 columns, but query has 3 columns.

A Big Thanks to Samson Scharfrichter

    INSERT OVERWRITE TABLE t1 PARTITION (country='US') 
SELECT no,name  from tx where country = 'US';
    INSERT INTO TABLE t1 PARTITION (country='IN') 
SELECT no,name  from tx where country = 'IN';

I checked the Partitions

hive>  SHOW PARTITIONS t1;
OK
country=IN
country=US
Time taken: 0.291 seconds, Fetched: 2 row(s)
hive>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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