I'm repeating a lot of code that looks like the following:
trim(concat(ifnull(`field1`, ''), ' ', ifnull(`field2`, ''))) as my_field
It would be nice to be able to define a function called trim_and_concat that takes an arbitrary number of fields, concatenates them, and trims the result. I could write a UDF, but then I would lose out on all the PySpark optimization.
Is it possible to define a function that combines native SparkSQL methods such that the typical loss of opitimization associated with UDFs is avoided?
I know about the create_function syntax, but as far as I can tell this is just another way to create UDFs, and still requires that the functions be written in scala or Python.