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.

Prerequisites

Make sure that the following operations are performed:
  1. Install MaxCompute Studio.
  2. Establish a connection to a MaxCompute project.
  3. Create a MaxCompute Java module.

Procedure

  1. Write a UDF in Java
    1. In the left-side navigation pane of the Project tab, choose src > main > java, right-click java, and then choose New > MaxCompute Java.
      Create a Java class
    2. 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.
      Create new MaxCompute java class

      Name: the name of the MaxCompute Java class. If no package is created, enter packagename.classname. The system automatically generates a package.

    3. Write code in the code editor.
      Code editorSample 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();
          }
      }
  2. Debug the UDF to check whether the code is run as expected.
    1. In the java directory, right-click the Java script that you wrote and select Run.
    2. In the Run/Debug Configurations dialog box, configure the required parameters.
      debug
      • 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.
    3. Click OK. The following figure shows the return result.
  3. Create a MaxCompute UDF.
    1. Right-click the UDF Java file and select Deploy to server....
    2. 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.
    3. Click OK.
  4. 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. Call the UDFSample 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.