You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@hive.apache.org by Jie Zhang <ji...@gmail.com> on 2015/03/02 08:53:12 UTC

how to access array type?

Hi,

I am trying to use hive complex data type on hive0.14.0. However, could not
access the array type as manual indicated. I have an array column, but hit
SemanticException when access the individual item in the array. Any clue?
Did I use the wrong syntax or miss some property setting? Thanks!

hive> create table test1 (c1 array <int>) row format delimited collection
items terminated by ',';

OK

Time taken: 0.092 seconds

hive> select * from test1;

OK

[1,2,3]

Time taken: 0.065 seconds, Fetched: 1 row(s)

hive> select c1[0] from test1;

FAILED: SemanticException [Error 10004]: Line 1:7 Invalid table alias or
column reference 'c1[0]': (possible column names are: c1)

Jessica

Re: how to access array type?

Posted by Alexander Pivovarov <ap...@gmail.com>.
hive> create table test1 (c1 array<int>) row format delimited collection
items terminated by ',';
OK

hive> insert into test1 select array(1,2,3) from dual;
OK

hive> select * from test1;
OK
[1,2,3]

hive> select c1[0] from test1;
OK
1

$ hadoop fs -cat /apps/hive/warehouse/test1/000000_0
1,2,3



On Sun, Mar 1, 2015 at 11:53 PM, Jie Zhang <ji...@gmail.com> wrote:

> Hi,
>
> I am trying to use hive complex data type on hive0.14.0. However, could
> not access the array type as manual indicated. I have an array column, but
> hit SemanticException when access the individual item in the array. Any
> clue? Did I use the wrong syntax or miss some property setting? Thanks!
>
> hive> create table test1 (c1 array <int>) row format delimited collection
> items terminated by ',';
>
> OK
>
> Time taken: 0.092 seconds
>
> hive> select * from test1;
>
> OK
>
> [1,2,3]
>
> Time taken: 0.065 seconds, Fetched: 1 row(s)
>
> hive> select c1[0] from test1;
>
> FAILED: SemanticException [Error 10004]: Line 1:7 Invalid table alias or
> column reference 'c1[0]': (possible column names are: c1)
>
> Jessica
>