过滤hive复杂数据类型

时间:2017-07-02 08:36:58

标签: hadoop hive hiveql

我使用hive创建了一个表,我希望过滤数据

create table student(
      id bigint
     ,name string
     , course array<string>)
ROW FORMAT DELIMiTED fields terminated by '\t'
collection items terminated by ','
STORED AS TEXTFILE;

之类的数据
100 student1    java,.net,hadoop
101 student2    .net,hadoop
102 student3    java,hadoop
103 student4    .net,hadoop
104 student5    java,.net
105 student6    java,.net,hadoop
106 student7    .net,hadoop
  

适合这个数据基于cource = hadoop

请有人帮助我。

1 个答案:

答案 0 :(得分:0)

select  * 
from    student
where   array_contains (course,'hadoop')
;
+-----+----------+--------------------------+
| id  |   name   |          course          |
+-----+----------+--------------------------+
| 100 | student1 | ["java",".net","hadoop"] |
| 101 | student2 | [".net","hadoop"]        |
| 102 | student3 | ["java","hadoop"]        |
| 103 | student4 | [".net","hadoop"]        |
| 105 | student6 | ["java",".net","hadoop"] |
| 106 | student7 | [".net","hadoop"]        |
+-----+----------+--------------------------+