DataWorks allows you to develop functions in Python and Java. This topic describes how to create a MaxCompute function.

Prerequisites

Required resources are uploaded.

Procedure

  1. Go to the DataStudio page.
    1. Log on to the DataWorks console.
    2. In the left-side navigation pane, click Workspaces.
    3. In the top navigation bar, select the region where your workspace resides, find the workspace, and then click Data Analytics in the Actions column.
  2. Create a workflow. For more information, see Create a workflow.
  3. Write Java code in an offline Java environment, compress the code to a JAR package, and then upload the package as a JAR resource to DataWorks. For more information, see Create, reference, and download MaxCompute resources.
  4. Create a function.
    1. Find the created workflow, right-click MaxCompute, and then choose New > Function.
    2. In the New function dialog box, set the Function name and Destination folder parameters.
    3. Click Submit.
    4. In the Register function section of the configuration tab that appears, set the parameters.
      Register function section
      Parameter Description
      Function type The type of the function. Valid values: Mathematical operation function, Aggregate function, String processing function, Date function, Window function, and Other functions.
      MaxCompute Engine instance The MaxCompute engine that is bound to the current workspace. By default, you cannot change the engine.
      Function name The name of the function. You can reference the function in SQL statements by using the function name. The function name must be globally unique and cannot be changed after the function is created.
      Responsible Person The owner of the function. This parameter is automatically set.
      Class name Required. The name of the class for implementing the function.
      Note If the resource type is Python, enter the class name in the Python resource name.Class name format. Do not include the .py extension in the resource name.
      Resource List Required. The list of resources. You can search for existing resources in the current workspace in fuzzy match mode.
      Description The description of the function.
      Command format The syntax of the function. Example: test.
      Parameter description The description of the input and output parameters that are supported by the function.
      Return value Optional. The value to return. Example: 1.
      Example Optional. An example of the function.
  5. Click the Save icon icon in the toolbar.
  6. Commit the function.
    1. Click the Submit icon icon in the toolbar.
    2. In the Submit New version dialog box, enter your comments in the Change description field.
    3. Click OK.