All Products
Search
Document Center

MaxCompute:Develop a UDF

Last Updated:Jun 20, 2026

If the built-in functions provided by MaxCompute cannot meet your business requirements, you can develop user-defined functions (UDFs) in MaxCompute Studio to implement business features. This topic describes how to use MaxCompute Studio to develop and debug Java UDFs.

Prerequisites

Before you begin, make sure that you have completed the following operations:

Background information

You can develop a UDF by following the steps in this topic, or create one directly by selecting MaxCompute > Create UDF.

Write a UDF

  1. In the Project pane, right-click the source code directory of the module (that is, src > main > java), and select New > MaxCompute Java.

  2. Enter a Name and select the type as UDF, then press Enter.

    In the Create new MaxCompute java class dialog box, you can also select other class types, including UDAF, UDTF, Driver, mapper, reducer, StorageHandler, Extractor, and Outputer.

    Name: The name of the MaxCompute Java class. To create a package, you can enter the name in the format of packagename.classname. This action automatically creates a package.

  3. After you create a MaxCompute Java class, develop a Java program in the editor.

Perform a local run to debug the UDF

Perform a local run to test the UDF and check whether the results meet your expectations.

  1. Right-click the Java script and select Run.

  2. On the Run/Debug Configurations page, configure the run parameters.

    For this example, set MaxCompute table to wc_in1, Table columns to col1, and Download Record limit to 100.

    • MaxCompute project: Specifies the MaxCompute project to use for the UDF. For a local run, select local.

      Note
      • If you want to use table data in a MaxCompute project, you must modify the endpoint and specify a project name in the MaxCompute project field. If the table data in the MaxCompute project is not downloaded to the warehouse directory, the data is downloaded first. If the data is already downloaded, skip this step.

      • If you select local from the drop-down list of MaxCompute project, interaction between MaxCompute data or resources and the local project is not required. This way, you can develop, test, and debug UDFs in the local environment.

    • MaxCompute table: the name of the MaxCompute table in which the UDF runs.

    • Table columns: the columns in the MaxCompute table in which the UDF runs.

  3. Click OK to start running.

    Note
    • The system reads data from the specified table in warehouse as the input during the local run. You can view the log output in the console.

Perform unit testing to debug the UDF

You can write test cases based on the unit testing examples in the examples directory.

What to do next

After you develop and debug a UDF, you must package, upload, and register the UDF code to make the UDF available in MaxCompute. For more information, see Package a Java program, upload the package, and create a MaxCompute UDF.

References

For more information about how to use Python to develop UDFs in MaxCompute Studio, see Develop a Python UDF.