scala Spark SQL - IN 子句
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/40218473/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-22 08:46:37 来源:igfitidea点击:
Spark SQL - IN clause
提问by Shankar
I would like to add where condition for a column with Multiple values in DataFrame.
我想为 DataFrame 中具有多个值的列添加 where 条件。
Its working for single value, for example.
例如,它适用于单个值。
df.where($"type".==="type1" && $"status"==="completed").
How can i add multiple values for the same column like below.
我如何为同一列添加多个值,如下所示。
df.where($"type" IN ("type1","type2") && $"status" IN ("completed","inprogress")
回答by Raphael Roth
the method you are looking for is isin:
您正在寻找的方法是isin:
import sqlContext.implicits._
df.where($"type".isin("type1","type2") and $"status".isin("completed","inprogress"))
Typically, you want to do something like this
通常,你想做这样的事情
val types = Seq("type1","type2")
val statuses = Seq("completed","inprogress")
df.where($"type".isin(types:_*) and $"status".isin(statuses:_*))

