All Products
Search
Document Center

DataWorks:Create an Aviator function

Last Updated:Jan 06, 2026

This topic explains how to create an Aviator function and use it as an API pre-filter or post-filter.

Prerequisites

Background

In DataService Studio, you can create, test, and deploy functions. After you deploy a function, you can use it as an API filter to process request parameters or returned results. For code examples of common use cases, see Best practices: Use an Aviator function as a filter.

Limitations

  • Aviator functions must run in an exclusive resource group for DataService Studio.

  • When you use a function as an API filter, the function types for the pre-filter and the post-filter must be the same. This means you must use either Aviator functions or Python functions for both.

Usage notes

For security and performance reasons, Aviator functions must run in an exclusive resource group for DataService Studio. Therefore:

  • When you edit or test a function, you must associate it with an exclusive resource group for DataService Studio. For more information, see Manage a function.

  • When you enable a filter and assign a function to it during API development, you must associate the API with an exclusive resource group for DataService Studio. For more information, see Create an API using the codeless UI.

Function structure

The system provides a default template for Aviator functions. For syntax details, see Aviator function syntax.

## --- AviatorScript ---
## $0: the default name of the input param.
## Expressions must be separated by the semicolon ";".

## Example 1:
## $0.a: Get the attribute "a" from the input param "$0".
## $0.b[index]: Retrieve the element at the specified index from array "b" in "$0". The index cannot be an expression or a variable.

## Example 2:
## Input: {"keyA":[1,2],"keyB":"value"}
## Function: $0.keyA[0]=3; $0.keyB="new_value"; return $0;
## Output: {"keyA":[3,2],"keyB":"new_value"}

return $0;

The default input parameter for Aviator functions is $0, which cannot be renamed. $0 represents the entire function input and must be in JSON format.

In DataService Studio, functions act as API filters to process request parameters and return results. Request parameters follow a single-layer JSON structure (depth: 1), while return results use a multi-layer JSON structure (depth: N). Therefore, the input $0 always contains data in JSON format.

When used as an API pre-filter:

  • Input: The system converts API request parameters (or the output of a preceding function) from a key-value map into JSON format and passes this to $0. Note that all values in this JSON object must be strings.

  • Output: The function must return a key-value map. Since this output determines the input parameters for SQL execution, only a single-layer key-value map (depth: 1) is supported.

Go to the DataService Studio page

Log on to the DataWorks console. In the top navigation bar, select the desired region. Then, click DataService Studio in the left-side navigation pane. On the page that appears, select the desired workspace from the drop-down list and click Go to DataService Studio.

Create a function

  1. On the Service Development pane, move the pointer over the image.png icon, and choose Create Function > Create Aviator Function.

    Alternatively, you can find the target workflow, right-click Function, and choose Create Function > Create Aviator Function.

  2. In the Create Aviator Function dialog box, configure the parameters.

    image.png

    Parameter

    Description

    Function Name

    A name for the function, up to 256 characters long.

    Function Template

    Only AviatorScript Standard v1 is supported.

    Function Description

    A brief description of the function. The description can be up to 512 characters long.

    Destination Folder

    The folder where the function will be stored.

    Note

    You must select a specific workflow, folder, or category. If no workflow exists, create one first.

  3. Click OK.

  4. In the Edit Code area, write your function's code.

  5. Configure a resource group for DataService Studio.

    函数

    1. On the right-side navigation pane of the function editing page, click Resource Group. In the Resource Group Type section, you can configure the resource group type used for API calls.

      Currently, you can only select an exclusive resource group for DataService Studio.

      Note

      If the target resource group is not in the list, go to the DataWorks console to associate the resource group with your workspace. You can also purchase a new one. For more information, see Use an exclusive resource group for DataService Studio.

    2. In the Environment Configuration section, set the Memory and Function Timeout.

      Recommended timeout: 100 ms for exclusive resource groups for DataService Studio.

  6. Click the 保存 icon in the toolbar to save and create the function.

After you create the function, you can test and deploy it. You can then use the function as a pre-filter or post-filter for an API.

Next steps