Summary

Last Updated: Sep 27, 2017

The full name of UDF is User Defined Function. ODPS provides many built-in functions to meet user’s computing requests and user can also create user-defined functions to meet different computing needs. UDF in use is similar with ordinary Built-in Function.

User who uses Maven can search “odps-sdk-udf” from Maven to get different versions of Java SDK. The configuration information is shown as follows:

  1. <dependency>
  2. <groupId>com.aliyun.odps</groupId>
  3. <artifactId>odps-sdk-udf</artifactId>
  4. <version>0.20.7-public</version>
  5. </dependency>

In ODPS, user can expand two kinds of UDF:

UDF Class Description
User Defined Scalar Function (also called UDF). User Defined Scalar Function also called UDF. The relationship between input and output is one-to-one relationship. Read a row data and write an output value.
UDTF(User Defined Table Valued Function) User Defined Table Valued Function, used to solve the scene that calling one function is to output multiple rows of data. It is a unique defined function which can return multiple fields, while UDF only outputs a return value.
UDAF(User Defined Aggregation Function) User Defined Aggregation Function, the relationship between its input and output is one-to-many relationship. That is to aggregate multiple input records to an output value. It can be used with ‘Group By’ clause together. For details, refer to Aggregation Functions.

Notes:

  • Broadly speaking, 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 narrow sense, it just represents user Defined Scalar Function. The document will use this term frequently and the readers should judge the specific meaning according to the context.

Parameter and Return Value Type

The data types of UDF supported by ODPS SQL include: bigint, string, double, Boolean and datetime. The correspondence of ODPS data types and Java types is shown as follows:

ODPS SQL Type Bigint String Double Boolean Datetime
Java Type Long String Double Boolean Date

Note:

  • NULL value in SQL is represented by NULL value in Java, so it is not allowed to use ‘Java primitive type’, which can not represent NULL value in SQL.

UDF Example

Please refer to UDF Example in Quick Start Volume.

Thank you! We've received your feedback.