1

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?

zero323
  • 322,348
  • 103
  • 959
  • 935
Shankar
  • 8,529
  • 26
  • 90
  • 159

1 Answers1

3

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: _*))
zero323
  • 322,348
  • 103
  • 959
  • 935
Tzach Zohar
  • 37,442
  • 3
  • 79
  • 85