pyspark.sql.UDFRegistration.registerJavaUDAF

UDFRegistration.registerJavaUDAF(name: str, javaClassName: str) → None[source]

Register a Java user-defined aggregate function as a SQL function.

New in version 2.3.0.

Changed in version 3.4.0: Supports Spark Connect.

namestr

name of the user-defined aggregate function

javaClassNamestr

fully qualified name of java class

Examples

>>> spark.udf.registerJavaUDAF("javaUDAF", "test.org.apache.spark.sql.MyDoubleAvg")
... 
>>> df = spark.createDataFrame([(1, "a"),(2, "b"), (3, "a")],["id", "name"])
>>> df.createOrReplaceTempView("df")
>>> q = "SELECT name, javaUDAF(id) as avg from df group by name order by name desc"
>>> spark.sql(q).collect()  
[Row(name='b', avg=102.0), Row(name='a', avg=102.0)]