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

Prerequisites

Before you begin, perform the following operations:

Background information

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

Write UDFs

  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.
    11
  2. Specify Name and Kind, and click OK.
    • Name: the name of the MaxCompute Java class. If no package is created, enter packagename.classname. The system automatically creates a package.
    • Kind: the category of the MaxCompute Java class. Select UDF. Supported categories include custom functions (UDF, UDAF, and UDTF), MapReduce (Driver, Mapper, and Reducer), and non-structural development frameworks (StorageHandler, Extractor, and Outputer).
  3. After you create a UDF class, develop a UDF Java program in the editor.

    For more information about examples of Java UDFs, see.

Perform local run to debug UDFs

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

  1. Right-click the compiled Java script and select Run.
  2. In the Run/Debug Configurations dialog box, configure the running parameters.
    debug
    • MaxCompute project: the MaxCompute project where the UDF runs. To perform local run, select local.
    • MaxCompute table: the name of the MaxCompute table where the UDF runs.
    • Table columns: the columns in the MaxCompute table where the UDF runs.
  3. Click OK to run the UDF.
    Note
    • The system reads the specified table data 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 UDFs

Refer to the unit test 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 the UDF code. For more information, see Package, upload, and register a Java program.