arrays - 在Hive中的数组内查询

标签 arrays hadoop hive hdfs

我看过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;
和选择输出
enter image description here
但是我无法在数组中搜索特定值
enter image description here
enter image description here
那么,我想念什么?

最佳答案

您无法使用的原因是,第一个元素之前有空格,因此必须使用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

关于arrays - 在Hive中的数组内查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63462692/

相关文章:

Apache hadoop Yarn 示例程序

hadoop - 使用 SFTP 将文件移动到 Hadoop HDFS

php - 将数组存储为 JSON 时,为什么从角色数组中删除项目会中断?

javascript - 如何使用数组在chart.js中动态创建数据集?

javascript - 如何在 JavaScript 中连接字符串数组 - 连接时进行修改

hadoop - BigQuery 是否给出聚合的确切值?

apache-spark - 如何向通过 Spark 创建的 View 添加注释

azure - Azure 上的 Horton Sandbox 教程 - 无法从 HDFS 上传到 Hive

java - Dropwizard 和 hive-jdbc 之间的不兼容

c - 将结构数组返回到 main() 中的变量