User Defined Functions - Scala

This notebook contains examples of a UDF and how to register them for use in Spark SQL.

Register the function as a UDF

val squared = (s: Int) => {
  s * s
}
spark.udf.register("square", squared)

Call the UDF in Spark SQL

spark.range(1, 20).registerTempTable("test")
%sql select id, square(id) as id_squared from test