使用数组类型的列值我有两列,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