I have a function that adds 2 columns:
def sum_num (num1: Int, num2: Int): Int = {
return num1 + num2
}
I have a dataframe df with below values
+----+----+----+
|col1|col2|col3|
+----+----+----+
|1 |2 |5 |
|7 |4 |4 |
+----+----+----+
I want to add a column and pass column names to the function but the below code is not working. It gives error found Column required is Int
val newdf = df.withColumn("sum_of_cols1", sum_num($col1, $ col2))
.withColumn("sum_of_cols2", sum_num($col1, $ col3))