apache-spark - 如何将 OR 约束与多个半连接一起使用?
问题描述
如何在 SparkSQL 或 Dataframe API 中使用 semijoin 实现以下 SQL?
select *
from foo
left join a on foo.id = a.id
left join b on foo.id = b.id
where exists (select 1 from a x where foo.id = x.id)
or exists (select 1 from b x where foo.id = x.id)
;
我已经尝试过了,但它的功能是 AND
.join(loincDF, foo("id") <=> a("id"), "leftsemi")
.join(loincDF, foo("id") <=> b("id"), "leftsemi")
解决方案
你可以尝试这样的事情:
foo.join(a, Seq("id"), "leftsemi")
.union( foo.join(b, Seq("id"), "leftsemi") )
.distinct
推荐阅读
- esp8266 - How to retrieve the flashed binary in ESP8266
- r - R:apply() 中的错误?
- django - show and create object from many2one relation in related model's template
- javascript - Adonis.js populate all with related tables data
- css - Is It possible to make a string reverse using css without using "rtl" ?
- python - Python AES-CTR is not compatible with Golang
- mysql - 在 mysql 中,如何获取通过一个月内任何日期的所有数据范围?
- java - 复制到其他计算机时无法加载DLL
- gcc - 未知的伪操作:`.pushsection'。作为版本 2.29.1
- code-analysis - 这是 for 循环 O(1) 还是 O(n)?