使用數組類型的列值我有兩列,listA
存儲爲Seq[String]
和valB
存儲爲String
一個數據幀。我想創建一個第三列valC
,這將是int型的,其價值是
iff valB is present in listA then 1 otherwise 0
如何CASE語句
我試圖做以下幾點:
val dfWithAdditionalColumn = df.withColumn("valC", when($"listA".contains($"valB"), 1).otherwise(0))
但是星火未能執行這一點,給了以下錯誤:
cannot resolve 'contains('listA', 'valB')' due to data type mismatch: argument 1 requires string type, however, 'listA' is of array type.;
如何在CASE語句中使用數組類型列值?
感謝, Devj