So my generated dataframe df looks like this:
+---------------------------------------------------------------------+-----------------+
|constraint_message |constraint_status|
+---------------------------------------------------------------------+-----------------+
| |Success |
|Value: 8.109213053982745E-6 does not meet the constraint requirement!|Failure |
| |Success |
| |Success |
|Value: 0.98 does not meet the constraint requirement! |Failure |
+---------------------------------------------------------------------+-----------------+
I want to have a new column in this dataframe, the logic for which I've defined in the function:
def metric = (status: String, valu:Double) => {
if (status == "Success"){ 1 }
else{ valu }
}
val putMetric = spark.udf.register("Metric",metric)
Now when I'm calling it like this: [Note: I'll later replace the 0 by a Double variable]
df.withColumn("Metric",putMetric(col("constraint_status"),0)).show()
I get the error:
try.scala:48: error: type mismatch;
found : Int(0)
required: org.apache.spark.sql.Column
df.withColumn("Metric",putMetric(col("constraint_status"),0))
How to rectify this? I tried putting col(0) but that didn't work either