This topic describes how to develop a user-defined functions (UDF) in MaxCompute Studio. This includes how to write and debug a UDF.


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

Background information

You can follow the instructions in this topic to develop a UDF, or choose MaxCompute > Create UDF to directly create a UDF.

Write a UDF

  1. In the Project tool window, expand your MaxCompute Java module and choose src > main > java. Then, right-click java and choose New > MaxCompute Java.
  2. Specify Name, select the UDF type, and press Enter.
    Create a MaxCompute java class
    • Name: the name of the MaxCompute Java class. If no package is created, enter packagename.classname. The system automatically creates a package.
    • Select the UDF type.
  3. After you create a MaxCompute java class, develop a Java program in the editor.
    Develop a program

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 compiled Java script and select Run.
  2. In the Run/Debug Configurations dialog box, configure the runtime parameters.
    • MaxCompute project: the MaxCompute project in which the UDF runs. To perform a local run, select local.
    • 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 run the UDF.
    • 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.
    • The system downloads the table data from the specified MaxCompute project to the warehouse directory. If the data is already downloaded, the system does not perform this step.

Perform unit testing to debug the UDF

Refer to the unit testing examples in the examples directory and write your test case. **

What to do next

After you write and debug a UDF, you must package, upload, and register UDF code. For more information, see Package, upload, and register a Java program.