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. Create JAR or Python resources, and commit and deploy them. For more information, see Create MaxCompute resources.
  4. Create a function.
    1. Find the created workflow, right-click MaxCompute, and then choose Create > Function.
    2. In the Create Function dialog box, set the Function Name and Location parameters.
    3. Click Create.
    4. In the Register Function section, set the parameters.
      Register Function section
      Parameter Description
      Function Type The type of the function. Valid values: Mathematical Function, Aggregate Function, String Function, Date Function, Analytic Function, and Other Functions.
      Engine Instance MaxCompute By default, the parameter cannot be modified.
      Function Name The name of the user defined function (UDF). 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.
      Owner This parameter is automatically set.
      Class Name Required. The name of the class that implements 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. You can use a Python resource after the resource is committed and deployed. For more information, see Create MaxCompute resources.
      Resources Required. You can search for existing resources in the current workspace in fuzzy match mode.
      Description The brief description of the current UDF.
      Expression Syntax The syntax of the UDF. Example: test.
      Parameter Description The descriptions of the input and output parameters that are supported.
      Return Value Optional. The value to return. Example: 1.
      Example Optional. An example of the function.
  5. Click the Save icon in the toolbar.
  6. Commit the function.
    1. Click the Commit icon icon in the toolbar.
    2. In the Commit Node dialog box, enter your comments in the Change description field.
    3. Click OK.