When MaxCompute's built-in functions don't cover your data processing logic, create a user-defined function (UDF) and register it in DataWorks. Once registered, reference it by name in any SQL statement just like a built-in function.
Creation methods
DataWorks supports three methods. Choose based on your workflow:
| Method | Best for |
|---|---|
| DataWorks console (this guide) | Teams managing UDFs through a centralized UI |
| MaxCompute Studio | Developers working in an IDE plugin |
| MaxCompute CLI | Script-based or automated workflows |
UDFs registered through MaxCompute Studio or the CLI are not automatically visible in DataWorks. To manage them in the DataWorks console, use the MaxCompute function feature in DataStudio to load them manually. See Manage MaxCompute functions.
Prerequisites
Before you begin, ensure that you have:
-
An uploaded or created MaxCompute resource (JAR package or Python file) that contains your UDF implementation. See Create and use MaxCompute resources
-
Access to a DataWorks workspace with DataStudio
To prepare your resource file, see Develop a UDF in Java or Develop a UDF in Python 3.
Register a function
Step 1: Go to DataStudio
Log in to the DataWorks console. In the top navigation bar, select a region. In the left-side navigation pane, choose Data Development and O&M > Data Development. Select a workspace, then click Go to Data Development.
Step 2: Create a workflow
Create an auto triggered workflow if you don't already have one. See Create an auto triggered workflow.
Step 3: Create and configure the function
-
In the Scheduled Workflow pane, expand a workflow, right-click MaxCompute, and select Create Function.
-
In the Create Function dialog box, enter a Name and a Path, then click Create.
-
In the Register Function section of the configuration tab, fill in the parameters:
Parameter Description Function type The category of the function: Mathematical Operation Functions, Aggregate Functions, String Processing Functions, Date Functions, Window Functions, or Other Functions. See Use built-in functions for descriptions of each category. Engine Instance MaxCompute The compute engine. Read-only. Function name The name used to call the function in SQL statements. Must be globally unique. Cannot be changed after registration. Owner The function owner. Defaults to the account used to log in. Editable. Class name The class that implements the UDF. See Class name format below — this field is the most common source of registration errors. Resources The resource files associated with the UDF. See Select resources below. Description A description of the UDF. Expression syntax The call syntax of the function. Example: test.Parameter description Descriptions of the input and output parameters. Return value (Optional) The return value. Example: 1.Example (Optional) A usage example. 
Class name format
The Class name field links your UDF to the implementing class in the resource file. This is the most common source of registration errors — use the format and examples below carefully.
Format: resource-name.class-name
| Resource type | Format | Example |
|---|---|---|
| JAR package | JAR-package-name.actual-class-name |
com.aliyun.odps.examples.udf.UDAFExample |
| Python resource | Python-resource-name.actual-class-name |
LcLognormDist_sh.LcLognormDist_sh |
Omit the.jaror.pyfile extension in the resource name. To find the class name for a JAR package, runCopy Referencein IntelliJ IDEA. The resource must be committed and deployed before you can use it here. See Create and use MaxCompute resources.
Select resources
In the Resources field, choose a selection mode:
| Mode | When to use |
|---|---|
| Visual mode | Lists only resources that have been uploaded or added to DataWorks. Use this for most cases. |
| Code editor | Lists all resources in the MaxCompute compute engine. Use this to reference resources not yet added to DataWorks. |
To reference multiple resources, separate the resource names with commas.
Step 4: Save and commit
-
Click the
icon in the top toolbar to save. -
Click the
icon to commit. -
In the Submit dialog box, enter a comment in the Change description field, then click Confirm.
To view registered functions, check their change history, or perform other management operations, see Manage MaxCompute functions.
Use a UDF in a node
Reference the UDF by its function name directly in SQL code. To insert it quickly:
-
In the Scheduled Workflow pane, right-click the UDF name.
-
Select Insert Function.
The UDF appears in the configuration tab of the node.
View and manage UDFs
View all UDFs
Run the following command in an ODPS SQL node or SQL Query in DataAnalysis to list all registered UDFs in the MaxCompute project:
SHOW FUNCTIONS;
View UDF details
You can run the DESCRIBE or abbreviated DESC command followed by a UDF name to view the details of a UDF:
DESC FUNCTION <function_name>;
View version history and roll back
In the MaxCompute folder in the Business Flow section in the Scheduled Workflow pane, right-click a function name and select View Earlier Versions to see previous versions or roll back to an earlier one.
FAQ
After registering a UDF in the DataWorks console, can I use it in SQL Query of DataAnalysis?
Yes. UDFs registered in the DataWorks console are stored in MaxCompute projects, so they're available wherever you can run SQL against that project — including ODPS SQL nodes in DataStudio and SQL Query in DataAnalysis.
What's next
-
Grant access to a specific UDF to a specified user — Set up access control on your UDF after creation.
-
Package a Java program, upload the package, and create a MaxCompute UDF — End-to-end walkthrough for Java-based UDFs.