CREATE FUNCTION
Description
The CREATE FUNCTION
statement is used to create a temporary or permanent function
in Spark. Temporary functions are scoped at a session level where as permanent
functions are created in the persistent catalog and are made available to
all sessions. The resources specified in the USING
clause are made available
to all executors when they are executed for the first time. In addition to the
SQL interface, spark allows users to create custom user defined scalar and
aggregate functions using Scala, Python and Java APIs. Please refer to
scalar_functions and
aggregate functions for more information.
Syntax
Parameters
OR REPLACE
-
If specified, the resources for the function are reloaded. This is mainly useful
to pick up any changes made to the implementation of the function. This
parameter is mutually exclusive to
IF NOT EXISTS
and can not be specified together. TEMPORARY
-
Indicates the scope of function being created. When
TEMPORARY
is specified, the created function is valid and visible in the current session. No persistent entry is made in the catalog for these kind of functions. IF NOT EXISTS
-
If specified, creates the function only when it does not exist. The creation
of function succeeds (no error is thrown) if the specified function already
exists in the system. This parameter is mutually exclusive to
OR REPLACE
and can not be specified together. function_name
-
Specifies a name of funnction to be created. The function name may be
optionally qualified with a database name.
Syntax:[database_name.]function_name
class_name
-
Specifies the name of the class that provides the implementation for function to be created.
The implementing class should extend one of the base classes as follows:
- Should extend
UDF
orUDAF
inorg.apache.hadoop.hive.ql.exec
package. - Should extend
AbstractGenericUDAFResolver
,GenericUDF
, orGenericUDTF
inorg.apache.hadoop.hive.ql.udf.generic
package. - Should extend
UserDefinedAggregateFunction
inorg.apache.spark.sql.expressions
package.
- Should extend
resource_locations
-
Specifies the list of resources that contain the implementation of the function
along with its dependencies.
Syntax:USING { { (JAR | FILE ) resource_uri} , ...}