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:
A connection to a MaxCompute project is created on MaxCompute Studio. For more information, see Manage project connections.
A MaxCompute Java module is created. For more information, see Create a MaxCompute Java module.
Background information
You can follow the instructions in this topic to develop a UDF, or choose
to directly create a UDF.Write a UDF
In the left-side navigation pane of the Project tab, choose , right-click java, and then choose .
Specify Name, select the UDF class, and then press Enter.
Name: the name of the MaxCompute Java class. If you need to create a package, enter packagename.classname. Then, the system automatically creates a package.
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.
Right-click the Java script that you wrote and select Run.
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 from the drop-down list.
NoteIf 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.
Click OK to run the UDF.
NoteThe 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
Refer to the unit testing examples in the examples directory and write your test case.
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.