pyspark.sql.Catalog.getFunction#

Catalog.getFunction(functionName)[source]#

Get the function with the specified name. This function can be a temporary function or a function. This throws an AnalysisException when the function cannot be found.

New in version 3.4.0.

Parameters
functionNamestr

name of the function to check existence.

Returns
Function

The function found by the name.

Examples

>>> _ = spark.sql(
...     "CREATE FUNCTION my_func1 AS 'test.org.apache.spark.sql.MyDoubleAvg'")
>>> spark.catalog.getFunction("my_func1")
Function(name='my_func1', catalog='spark_catalog', namespace=['default'], ...

Using the fully qualified name for function name.

>>> spark.catalog.getFunction("default.my_func1")
Function(name='my_func1', catalog='spark_catalog', namespace=['default'], ...
>>> spark.catalog.getFunction("spark_catalog.default.my_func1")
Function(name='my_func1', catalog='spark_catalog', namespace=['default'], ...

Throw an analysis exception when the function does not exists.

>>> spark.catalog.getFunction("my_func2")
Traceback (most recent call last):
    ...
AnalysisException: ...