Help Center/
Data Lake Insight/
SQL Syntax Reference (Paris Region)/
Spark SQL Syntax Reference/
User-Defined Functions/
Creating a Function
Updated on 2025-01-22 GMT+08:00
Creating a Function
Function
DLI allows you to create and use user-defined functions (UDF) and user-defined table functions (UDTF) in Spark jobs.
Syntax
1 2 3 4 5 |
CREATE FUNCTION [db_name.]function_name AS class_name [USING resource,...] resource: : JAR file_uri |
Or
1 2 3 4 5 |
CREATE OR REPLACE FUNCTION [db_name.]function_name AS class_name [USING resource,...] resource: : JAR file_uri |
Precautions
- If a function with the same name exists in the database, the system reports an error.
- Only the Hive syntax can be used to create functions.
- If you specify the same class name for two UDFs, the functions conflict though the package names are different. Avoid this problem because it causes failure of job execution.
Keywords
- USING <resources>: resources to be loaded. It can be a list of JARs, files, or URIs.
Example
Create the mergeBill function.
1 2 |
CREATE FUNCTION mergeBill AS 'com.xxx.hiveudf.MergeBill' using jar 'obs://onlyci-7/udf/MergeBill.jar'; |
Parent topic: User-Defined Functions
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
The system is busy. Please try again later.
For any further questions, feel free to contact us through the chatbot.
Chatbot