multiple conditions for filter in spark data frames

前端 未结 11 1138
醉酒成梦
醉酒成梦 2020-12-03 04:41

I have a data frame with four fields. one of the field name is Status and i am trying to use a OR condition in .filter for a dataframe . I tried below queries but no luck.

11条回答
  •  情歌与酒
    2020-12-03 05:23

    If we want partial match just like contains, we can chain the contain call like this :

    def getSelectedTablesRows2(allTablesInfoDF: DataFrame, tableNames: Seq[String]): DataFrame = {
    
        val tableFilters = tableNames.map(_.toLowerCase()).map(name => lower(col("table_name")).contains(name))
        val finalFilter = tableFilters.fold(lit(false))((accu, newTableFilter) => accu or newTableFilter)
        allTablesInfoDF.where(finalFilter)
    
      }
    

提交回复
热议问题