Reputation: 8957
I am trying to filter the Spark SQL DataFrame with where condition.
For example: [ working one]
df.where(col("pType").isin("type1","type2"))
What I am trying is, instead of hard coding the pType
values, I am trying to build it dynamically. So i build a List(String) with all the pType
values.
For example, if I have List("type1","type2")
, how can I use this list to isin
method?
Upvotes: 1
Views: 2412
Reputation: 37822
You can use Scala's syntax for converting a collection into a "repeated parameter" (AKA "varargs" in Java-speak, as well as other languages), See section 4.6.2 in the Scala Language Specification:
val list = List("type1","type2")
df.where(col("pType").isin(list: _*))
Upvotes: 3