How do I filter rows based on whether a column value is in a Set of Strings in a Spark DataFrame

后端 未结 1 506
情歌与酒
情歌与酒 2021-02-07 18:37

Is there a more elegant way of filtering based on values in a Set of String?

def myFilter(actions: Set[String], myDF: DataFrame): DataFrame = {
  val containsAct         


        
1条回答
  •  野性不改
    2021-02-07 19:31

    How about this:

    myDF.filter("action in (1,2)")
    

    OR

    import org.apache.spark.sql.functions.lit       
    myDF.where($"action".in(Seq(1,2).map(lit(_)):_*))
    

    OR

    import org.apache.spark.sql.functions.lit       
    myDF.where($"action".in(Seq(lit(1),lit(2)):_*))
    

    Additional support will be added to make this cleaner in 1.5

    0 讨论(0)
提交回复
热议问题