MaxCompute SQL supports two categories of functions: built-in functions and user-defined functions (UDFs). Built-in functions cover common data processing and aggregation tasks out of the box. When built-in functions don't meet your requirements, use the Java or Python APIs to create UDFs with custom logic.
Built-in functions
Built-in functions are ready to use in any MaxCompute SQL statement with no setup required. They handle common tasks such as string manipulation, math operations, date processing, and aggregation.
For the full list, see Built-in functions.
User-defined functions (UDFs)
UDFs extend MaxCompute with custom logic written in Java or Python. Use them when built-in functions don't cover your specific requirements.
MaxCompute supports three types of UDFs:
| Type | Description |
|---|---|
| User-defined scalar function (UDF) | Takes one input row and returns one output row. Use for row-level transformations. |
| User-defined aggregate function (UDAF) | Operates across multiple input rows and returns a single result. Use for custom aggregation logic such as weighted averages or complex statistical calculations. |
| User-defined table-valued function (UDTF) | Takes one input row and returns zero or more output rows. Use when a single input row needs to produce multiple output rows. |
Once registered, call a UDF the same way you call a built-in function—by name and parameters in a SQL statement.
Develop and register a UDF
To make a UDF available in MaxCompute SQL:
-
Write the UDF code using the MaxCompute UDF API.
-
Package the code by compiling it into a JAR package (for Java UDFs).
-
Upload the package to MaxCompute as a resource.
-
Register the UDF in MaxCompute with a name and the resource reference.
For step-by-step instructions, see Create a UDF.