我有两个具有以下模式的表作为示例:
DELETE
t1
FROM teh t1
JOIN teh t2 ON t2.col1 = t1.col1 AND t2.col2 = t1.col2 AND t2.id < t1.id
我想获取df2中的所有col1,其中col2数组中的元素等于df1中的id。诸如df3之类的内容输出:
scala> df1.printSchema
root
|-- id: string (nullable = true)
AND
scala> df2.printSchema
root
|-- col1: string (nullable = true)
|-- col2: array (nullable = true)
| |-- element: string (containsNull = true)
其中df3.c2基本上是df1.id,而df3.c1是满足上述相等性的所有df2.col1的数组。
任何SQL(配置单元)或Scala解决方案都非常有用。
答案 0 :(得分:4)
在Hive中:
select collect_set(df2.col1) as col1, df1.id as col2
from df1
inner join
(
select --explode col2 array
col1, s.c2 as col2
from df2 lateral view explode(col2) s as c2
) df2 on df1.id = df2.col2
group by df1.id;
答案 1 :(得分:1)
我认为您不需要为此的子查询:
{{1}}