Spark SQL UDF with varargs contains null and may return null

287 Views Asked by At

Spark sql default provides a function greatest(Column... exprs) which will "Returns the greatest value of the list of values, skipping null values."

But recently we got a requirement that we needs a function my_greatest(Column... exprs) that

  • if exprs contains null, then return null

  • otherwise return the greatest value of the list of values

I checked the UDF of Spark SQL, it seems that I can not defined varargs contains null and can not return null.

Is there any way to implement this? thank you.

0

There are 0 best solutions below