MaxCompute provides many built-in functions to meet the computing requests of a user and a user can also create user-defined functions to meet different computing needs. A User Defined Function (UDF) is similar to an ordinary Built-in Function.
In MaxCompute, you can expand two kinds of UDF:
|UDF (User Defined Scalar Function)||The relationship between input and output is a one-to-one relationship. Read a row data and write an output value.|
|UDTF (User Defined Table Valued Function)||User Defined Table Valued Function (UDTF) is used to solve calling one function to output multiple rows of data. It is a unique defined function which can return multiple fields, while UDF can only output a return value.|
|UDAF(User Defined Aggregation Function)||User Defined Aggregation Function (UDAF), the relationship between its input and output is one-to-many relationships. That is to aggregate multiple input records to an output value. It can be used with ‘Group By’ clause together. For more information, see Aggregation Functions.|
- UDF stands for the set of use-defined functions, including User Defined Scalar Function, User Defined Aggregation Function and User Defined Table Valued Function. In a narrower sense, it represents user User Defined Scalar Function. The document uses this term frequently and the readers can judge the specific meaning according to the context.
- If the system prompts that memory is not enough with an UDF involved in the SQL statement, configure
set odps.sql.udf.joiner.jvm.memory=xxxx;to solve it. The reason is that the amount of data is too large and there is a data skew, so that the memory size occupied by task exceeds the default memory size.
The data types of UDF supported by MaxCompute SQL include: bigint, string, double, Boolean, and datetime.
MaxCompute UDF supports cross-project sharing. A UDF in project_b can be used in project_a. For example, you can write a SQL statement into
select other_project:udf_in_other_project(arg0, arg1) as res from table_t;. For more information about authorization, see Authorization in Security Guide documentation.
Please see UDF Example in Quick Start Volume.