Filter spark/scala dataframe if column is present in set

前端 未结 2 973
耶瑟儿~
耶瑟儿~ 2021-01-14 02:55

I\'m using Spark 1.4.0, this is what I have so far:

data.filter($\"myColumn\".in(lit(\"A\"), lit(\"B\"), lit(\"C\"), ...))

The function lit

2条回答
  •  失恋的感觉
    2021-01-14 03:19

    Spark 1.4 or older:

    val validValues = Set("A", "B", "C").map(lit(_))
    data.filter($"myColumn".in(validValues.toSeq: _*))
    

    Spark 1.5 or newer:

    val validValues = Set("A", "B", "C")
    data.filter($"myColumn".isin(validValues.toSeq: _*))
    

提交回复
热议问题