Filter an array column based on a provided list

后端 未结 1 681
攒了一身酷
攒了一身酷 2021-01-23 17:53

I have the following types in a dataframe:

 root
 |-- id: string (nullable = true)
 |-- items: array (nullable = true)
          


        
相关标签:
1条回答
  • 2021-01-23 18:25

    You code is almost right. All you have to do is replace List with Seq

    def filterItems(flist: List[String]) = udf {
      (recs: Seq[String]) => recs.filter(item => flist.contains(item))
    }
    

    It would also make sense to change signature from List[String] => UserDefinedFunction to SeqString] => UserDefinedFunction, but it is not required.

    Reference SQL Programming Guide - Data Types.

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