pyspark.sql.SparkSession.udf

property SparkSession.udf

Returns a UDFRegistration for UDF registration.

New in version 2.0.0.

Changed in version 3.4.0: Supports Spark Connect.

Returns
UDFRegistration

Examples

Register a Python UDF, and use it in SQL.

>>> strlen = spark.udf.register("strlen", lambda x: len(x))
>>> spark.sql("SELECT strlen('test')").show()
+------------+
|strlen(test)|
+------------+
|           4|
+------------+