You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@hive.apache.org by Kuldeep Chitrakar <ku...@synechron.com> on 2016/06/28 13:02:47 UTC

Hive error : Can not convert struct<> to

Hi

I have staged table as

hive (revise)> desc employees_se;
OK
name                    string
salary                    float
subordinates      array<string>
deductions          map<string,float>
adr                         struct<street:string,cty:string,st:string,zip:int>

I am trying to insert the data in partitioned table employees as

hive (revise)> desc employees;
OK
name                    string
salary                    float
subordinates     array<string>
deductions         map<string,float>
address                struct<street:string,city:string,state:string,zip:int>
state                      string

# Partition Information
# col_name                        data_type                           comment

state                      string
Time taken: 0.161 seconds, Fetched: 11 row(s)

Command

FROM employees_se se
INSERT OVERWRITE TABLE employees
PARTITION(state='CA')
SELECT * WHERE se.adr.st='CA'

But I am getting an error as

FAILED: SemanticException [Error 10044]: Line 2:23 Cannot insert into target table because column number/types are different ''CA'': Cannot convert column 4 from struct<street:string,cty:string,st:string,zip:int> to struct<street:string,city:string,state:string,zip:int>.


Any idea, as I do not see anything wrong.




RE: Hive error : Can not convert struct<> to

Posted by "Markovitz, Dudu" <dm...@paypal.com>.
The staging table has no partitions, so no issue there.

Also, the error specifically refers to the covertion between the struct types.



Dudu





FAILED: SemanticException [Error 10044]: Line 2:23 Cannot insert into target table because column number/types are different ''CA'': Cannot convert column 4 from struct<street:string,cty:string,st:string,zip:int> to struct<street:string,city:string,state:string,zip:int>.





-----Original Message-----
From: Gopal Vijayaraghavan [mailto:gopal@hortonworks.com] On Behalf Of Gopal Vijayaraghavan
Sent: Tuesday, June 28, 2016 6:17 PM
To: user@hive.apache.org
Subject: Re: Hive error : Can not convert struct<> to <struct>



> PARTITION(state='CA')

> SELECT * WHERE se.adr.st='CA'

> FAILED: SemanticException [Error 10044]: Line 2:23 Cannot insert into

>target table because column number/types are different ''CA'':



The error is bogus, but the issue has to do with the "SELECT *".



Inserts where a partition is specified statically cannot have a partition column in the select.



So this is failing since it is trying to insert n-1 columns, because state='CA' cannot be repeated in the SELECT.



Cheers,

Gopal









Re: Hive error : Can not convert struct<> to

Posted by Gopal Vijayaraghavan <go...@apache.org>.
> PARTITION(state='CA')
> SELECT * WHERE se.adr.st='CA'
 
> FAILED: SemanticException [Error 10044]: Line 2:23 Cannot insert into
>target table because column number/types are different ''CA'':

The error is bogus, but the issue has to do with the "SELECT *".

Inserts where a partition is specified statically cannot have a partition
column in the select.

So this is failing since it is trying to insert n-1 columns, because
state='CA' cannot be repeated in the SELECT.

Cheers,
Gopal
 
 
 



RE: Hive error : Can not convert struct<> to

Posted by "Markovitz, Dudu" <dm...@paypal.com>.
Hi

The fields' names are part of the struct definition.
Different names, different types of structs.

Dudu


e.g.

Setup

create table t1 (s struct<c1:int,c2:int>);
create table t2 (s struct<col1:int,col2:int>);

insert into table t1 select named_struct('c1',1,'c2',2);


----------------------------------------------------------------------------------

insert into t2 select * from t1;

FAILED: SemanticException [Error 10044]: Line 1:12 Cannot insert into target table because column number/types are different 't2': Cannot convert column 0 from struct<c1:int,c2:int> to struct<col1:int,col2:int>.

----------------------------------------------------------------------------------

Solution 1 (per INSERT)

insert into t2 select named_struct('col1',s.c1,'col2',s.c2) from t1;

Solution 2 (one time)

alter table t2 change s s struct<c1:int,c2:int>;
insert into t2 select * from t1;



From: Kuldeep Chitrakar [mailto:kuldeep.chitrakar@synechron.com]
Sent: Tuesday, June 28, 2016 4:03 PM
To: user@hive.apache.org
Subject: Hive error : Can not convert struct<> to <struct>

Hi

I have staged table as

hive (revise)> desc employees_se;
OK
name                    string
salary                    float
subordinates      array<string>
deductions          map<string,float>
adr                         struct<street:string,cty:string,st:string,zip:int>

I am trying to insert the data in partitioned table employees as

hive (revise)> desc employees;
OK
name                    string
salary                    float
subordinates     array<string>
deductions         map<string,float>
address                struct<street:string,city:string,state:string,zip:int>
state                      string

# Partition Information
# col_name                        data_type                           comment

state                      string
Time taken: 0.161 seconds, Fetched: 11 row(s)

Command

FROM employees_se se
INSERT OVERWRITE TABLE employees
PARTITION(state='CA')
SELECT * WHERE se.adr.st='CA'

But I am getting an error as

FAILED: SemanticException [Error 10044]: Line 2:23 Cannot insert into target table because column number/types are different ''CA'': Cannot convert column 4 from struct<street:string,cty:string,st:string,zip:int> to struct<street:string,city:string,state:string,zip:int>.


Any idea, as I do not see anything wrong.