IntelliJ IDEA is an integrated development environment (IDE) that is written in Java.
IntelliJ IDEA helps you develop Java programs. This topic describes how to use MaxCompute
Studio to develop a user-defined function (UDF) that is used to convert uppercase
letters into lowercase letters. MaxCompute Studio is a plug-in that is developed based
on IntelliJ IDEA.
Procedure
- Write a UDF in Java
- In the left-side navigation pane of the Project tab, choose , right-click java, and then choose .
- In the Create new MaxCompute java class dialog box, click UDF, enter a class name in the Name field, and then press Enter. In this example, the class is named Lower.
Name: the name of the MaxCompute Java class. If no package is created, enter packagename.classname. The system automatically generates a package.
- Write code in the code editor.
Sample code:
package <packagename>;
import com.aliyun.odps.udf.UDF;
public final class Lower extends UDF {
public String evaluate(String s) {
if (s == null) {
return null;
}
return s.toLowerCase();
}
}
- Debug the UDF to check whether the code is run as expected.
- In the java directory, right-click the Java script that you wrote and select Run.
- In the Run/Debug Configurations dialog box, configure the required parameters.
- MaxCompute project: the MaxCompute project in which the UDF runs. To perform a local run, select local from the drop-down list.
- 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. The following figure shows the return result.
- Create a MaxCompute UDF.
- Right-click the UDF Java file and select Deploy to server....
- In the Package a jar, submit resource and register function dialog box, configure the parameters.
- MaxCompute project: the name of the MaxCompute project to which the UDF belongs. Retain the default
value, which indicates that the connection to the MaxCompute project is established
when you write the UDF.
- Resource file: the path of the resource file on which the UDF depends. Retain the default value.
- Resource name: the name of the resource on which the UDF depends. Retain the default value.
- Function name: the name of the UDF that you want to create. This name is used in the SQL statements
that are used to call the UDF. Example: Lower_test.
- Click OK.
- Call the UDF.
In the left-side navigation pane, click the
Project Explore tab. Right-click the MaxCompute project to which the UDF belongs, select
Open in Console, enter the SQL statement that is used to call the UDF, and then press Enter to execute
the SQL statement.
Sample statement:
select Lower_test('ALIYUN');
The following figure shows the result that the preceding statement returns. The result
indicates that the Java UDF
Lower_test runs as expected.