Manage functions with the visual editor

更新时间:
复制 MD 格式

Project Explorer in MaxCompute Studio provides a visual editor to quickly create a user-defined function (UDF) in a MaxCompute project. You can also use it to view the code of a MaxCompute UDF or delete the function.

Background

The following table describes the operations you can perform on functions in MaxCompute Studio.

Actions

Built-in function

MaxCompute UDF

Description

Create a function

未开通

已开通

N/A

View the syntax or code of a function

已开通

已开通

  • Built-in function: You can view the syntax, but not the code.

  • MaxCompute UDF: You can view both the syntax and the code.

Modify a function

未开通

未开通

  • Built-in function: Cannot be modified.

  • MaxCompute UDF: To modify a MaxCompute UDF, you must delete it, modify the code, and then package, upload, and re-create the function.

Delete a function

未开通

已开通

N/A

Create a function

Note

Before you create a function, ensure that you have uploaded the required resource files to the MaxCompute project. For more information, see Add a resource.

  1. In the top menu bar of IntelliJ IDEA, choose MaxCompute > Create UDF.

  2. In the Create Function dialog box, configure the parameters that are described in the following table.

    Parameter

    Description

    MaxCompute project

    The MaxCompute project in which you want to create the function.

    If MaxCompute Studio is connected to the target project, you can select it from the drop-down list. If the project is not listed, click the 添加 icon on the right to add it.

    Function name

    The name of the function. You can use this name to call the function in SQL statements. The function name must be unique within the project.

    To view existing function names, click Project Explorer in the left-side navigation pane and find the Functions folder in the target MaxCompute project.

    Using resources

    The resource files on which the function depends. You can click a resource file to select it. To select multiple files, hold down the Ctrl key and click the files that you want to use.

    Main class

    The class name of the function. The class is defined in the dependent JAR or PY file.

    Force update if already exists

    If you select this option, the function is overwritten if a function with the same name already exists.

  3. In the Create Function dialog box, click OK to create the function.

  4. In the Project Explorer pane, right-click the Functions folder in the target MaxCompute project and select Refresh meta. The new function appears in the list.

View a function

  • Built-in function

    In the Project Explorer pane on the left, go to the Functions > Builtln folder in your project. Double-click a built-in function to view its syntax.

  • MaxCompute UDF

    In the Project Explorer pane, go to the Functions > UserDefined folder in your project. To view the function code, double-click the function, or right-click the function and select Show function detail. To view the function syntax, click the function.

    //
    // Source code recreated from a .class file by IntelliJ IDEA
    // (powered by Fernflower decompiler)
    //
    package com.aliyun.odps.udf.example;
    import com.aliyun.odps.udf.UDF;
    public final class Lower extends UDF {
        public Lower() {
        }
        public String evaluate(String s) { return s == null ? null : s.toLowerCase(); }
    }

Delete a function

  1. In the Project Explorer pane, go to the Functions folder in your project. Right-click the function that you want to delete and select Delete function from server.

  2. In the Confirmation Required dialog box, click OK to delete the function from the MaxCompute project.

  3. Right-click the Functions folder and select Refresh meta. The function is removed from the list.