集合为collect\u的配置单元查询

o7jaxewo  于 2021-05-29  发布在  Hadoop
关注(0)|答案(1)|浏览(301)

我有两张table, sample_table1 有两列,如下所示

C1  C2
001  a
001  b
001  e
002  c
002  b
003  a
003  c

以及 sample_table2 两列为

C3  C4
a   0
b   1
c   0
d   1
e   0

我想得到这样的输出

F1    F2
001    1    <as 001 -> [a, b, e] -> [0, 1, 0] -> 1 (if one of the items in the collection ([a, b, e] in this case) is 1, then Column F2 should be 1 )>
002    1    <as 002 -> [c, b] -> [0, 1] -> 1>
003    0    <as 003 -> [a, c] -> [0, 0] -> 0>

我用Hive内置的聚合函数做了很多尝试 collect_set ,但无法解决。我想知道我是否可以不写任何自定义自定义项?

szqfcxe2

szqfcxe21#

不需要 collect_set ```
select t1.c1 as f1
,max(t2.c4) as f2

from sample_table1 t1
join sample_table2 t2
on t1.c2 = t2.c3

group by t1.c1
;

+-----+----+
| f1 | f2 |
+-----+----+
| 001 | 1 |
| 002 | 1 |
| 003 | 0 |
+-----+----+

相关问题