MaxCompute allows you to write user-defined functions (UDFs) in Java or Python to extend the capabilities of MaxCompute functions and accommodate your business requirements. This topic describes the types, limits, usage notes, and development process of UDFs. This topic also describes how to use UDFs.

Background information

UDFs are suitable for scenarios in which the input and output have a one-to-one mapping. If a UDF is called, the UDF reads one row of data and returns a value. MaxCompute supports two types of UDFs based on the programming language: Java UDFs and Python UDFs. The following table describes the two types of UDFs.
UDF typeDescription
Java UDFThis type of UDF is written in Java to implement the function logic. For more information, see Java UDFs.
Python UDFThis type of UDF is written in Python to implement the function logic. Python UDFs are classified into Python 2 UDFs and Python 3 UDFs.
  • Python 2 UDFs: Python 2.7 is used. For more information, see Python 2 UDFs.
  • Python 3 UDFs: CPython 3.7.3 is used. For more information, see Python 3 UDFs.


You cannot access the Internet by using UDFs. If you want to access the Internet by using UDFs, fill in the network connection application from based on your business requirements and submit the application. After the application is approved, the MaxCompute technical support team will contact you and help you establish network connections. For more information about how to fill in the network connection application form, see Network connection process.

Usage notes

Before you use UDFs, take note of the following items:
  • UDFs cannot compete with built-in functions in performance. We recommend that you preferentially use built-in functions to implement your business logic.
  • If you use a UDF in SQL statements, the memory usage of a computing job may exceed the default allocated memory size if a large amount of data is computed and data skew occurs. In this case, you can run the set odps.sql.udf.joiner.jvm.memory=xxxx; command at the session level to resolve the issue. For more information about the MaxCompute UDF FAQ, see FAQ about MaxCompute UDFs.
  • If the name of a UDF is the same as that of a built-in function, the UDF is preferentially called. For example, if UDF CONCAT and built-in function CONCAT both exist in MaxCompute, the system automatically calls UDF CONCAT instead of the built-in function CONCAT. If you want to call the built-in function, you must add the symbol :: before the built-in function, for example, select ::concat('ab', 'c');.

Development process

This section describes the development process of a UDF.


Use the following methods to call UDFs:
  • Use a UDF in a MaxCompute project: The method is similar to that of using built-in functions.
  • Use a UDF across projects: Use a UDF of Project B in Project A. The following statement shows an example: select B:udf_in_other_project(arg0, arg1) as res from table_t;. For more information about resource sharing across projects, see Cross-project resource access based on packages.