更新时间:2023-02-15 09:16:17
你可以编写一个 udf
函数来完成你的工作
you can write a udf
function to get your job done
import org.apache.spark.sql.functions._
def stringContains = udf((array: collection.mutable.WrappedArray[String], str: String) => array.contains(str))
df.withColumn("is_designer_present", when(stringContains(col("list_of_designers"), $"dept_resp"),1).otherwise(0))
你可以从udf
函数本身返回适当的值,这样你就不必使用when
函数
You can return appropriate value from udf
function itself so that you don't have to use when
function
import org.apache.spark.sql.functions._
def stringContains = udf((array: collection.mutable.WrappedArray[String], str: String) => if (array.contains(str)) 1 else 0)
df.withColumn("is_designer_present", stringContains(col("list_of_designers"), $"dept_resp"))