0

I have seen this but it does not work on my data.

I have this data:

 1, John, a@com;b@com2,32
 2, Jack, ab@com;c@com2,33

and loaded them to hive by:

create table t7(id int,name string, email Array<string>, age int)
ROW FORMAT DELIMITED
FIELDS TERMINATED BY ','
COLLECTION items terminated by ';'
STORED AS textfile;
Load data inpath '/user/maria_dev/7.txt' into table t7;

and the select output

enter image description here

but I cannot search specific value whithin the array enter image description here

enter image description here

So, what am I missing?

1 Answer 1

1

The reason that yours does not work is that you have whitespace before the first element so you have to use trim

select * from t7 where trim(email[0]) like "%a@%";
CREATE TABLE `t7`(
  `id` int,
  `name` string,
  `email` array<string>,
  `age` int)
ROW FORMAT DELIMITED
  FIELDS TERMINATED BY ','
  COLLECTION ITEMS TERMINATED BY '\;'

hive> select * from t7 where trim(email[0])="a@com";
OK
1        John   [" a@com","b@com2"]     32

hive> select * from t7 LATERAL VIEW explode(email) exploded_table as id_email where id_email like "%com2%";
OK
1        John   [" a@com","b@com2"]     32      b@com2
2        Jack   [" ab@com","c@com2"]    33      c@com2

Sign up to request clarification or add additional context in comments.

2 Comments

thanks, why have you used '\;' instead of ';'? mine works fine, any specific reason?
';' is not working correctly for me, use '\\;' instead?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.