在蜂巢中的数组内查询
Query within an Array in hive
我看过 this 但它对我的数据不起作用。
我有这个数据:
1, John, a@com;b@com2,32
2, Jack, ab@com;c@com2,33
并通过以下方式将它们加载到配置单元:
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;
和select输出
但我无法搜索数组中的特定值
那么,我错过了什么?
你的不起作用的原因是你在第一个元素之前有空格所以你必须使用 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
我看过 this 但它对我的数据不起作用。
我有这个数据:
1, John, a@com;b@com2,32
2, Jack, ab@com;c@com2,33
并通过以下方式将它们加载到配置单元:
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;
和select输出
但我无法搜索数组中的特定值
那么,我错过了什么?
你的不起作用的原因是你在第一个元素之前有空格所以你必须使用 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