繁体   English   中英

我们如何在 Spark 中使用 where 条件来进行 hive 以下查询?

[英]how we can use where condition in spark for below hive query?

我是火花 scala 框架的新手,下面的查询有子查询。 根据我有限的知识,火花不支持子查询,并且按 function 分组一次支持多列?

select id, email from test1 
where country in (select distinct salary from test2)
group by id ,email ;

在 spark 上面的查询转换成这样,但问题是我们如何使用来自不同数据帧的 where 条件。 我们可以在这里使用连接吗? 我们如何将整个查询转换为火花?

  val m = test1.select("id","email")
   val k = test2.select("salary").distinct
   val l =  m.groupby("id","salary")

您可以尝试使用半连接来表示子查询:

val m = test1.select("id","email","country")
val k = test2.select("salary").distinct

val df = m.join(k, m("country") === k("salary"), "left_semi")
val l = df.select("id","salary").distinct()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM