def myFunction(df: DataFrame): DataFrame = {
val myList= List("a","b","c")
df
.withColumn("myFlag",
if (myList.contains(df.select(col("columnName1")))) lit("true") else lit(false))
}
I want to write a function, that takes a Dataframe, and adds a column to it, named "myFlag".
I want "myFlag" to be true if the corresponding "columnName1" has a value that is an element of "myList", false otherwise.
For simplicity, "columnName1" values and "myList" only contain Strings.
My function above will not work. Any suggestions?