Shankar Shankar - 1 month ago 15
Scala Question

Spark SQL DF - How to pass multiple values dynamically for `isin` method of `Column`

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?

Answer
val list = List("type1","type2")
df.where(col("pType").isin(list: _*)