Configure scheduling parameters for different types of nodes

更新时间:
复制 MD 格式

You configure scheduling parameters the same way for most node types, such as a MaxCompute SQL node. However, the process differs for common shell and PyODPS nodes. This topic provides configuration examples for various node types.

SQL nodes and batch synchronization nodes

The configuration for SQL nodes and batch synchronization nodes is representative of most node types. This example uses a MaxCompute SQL node to demonstrate assigning values to built-in system variables and custom parameters, and then referencing them in your code.

Note

Not all nodes support scheduling parameters. To check if a specific node supports them, see the node development documentation.

  • Define parameters

    Parameter

    Value

    var1

    $bizdate

    var2

    ${yyyymmdd}

    var3

    $cyctime

    var4

    ${yyyymmddhh24:mi:ss}

    var5

    abc

  • Use parameters

    -- Get the data timestamp
    SELECT '${var1}' '${var2}';
    -- Get the scheduling time
    SELECT '${var3}' '${var4}';
    -- Get a constant
    SELECT '${var5}';

After assigning values in the Scheduling Parameters section, you can reference them in your code. The example shows references to the built-in system variables var1 and var3, the custom parameters var2 and var4, and the constant var5 with the following assignments:

  • Assign a data timestamp to the parameter var1: var1=$bizdate

  • Assign a scheduling time to the parameter var3: var3=$cyctime

  • Assign a data timestamp to the parameter var2: var2=${yyyymmdd}

  • Assign a scheduling time to the parameter var4: var4=$[yyyymmddhh24:mi:ss]

  • Assign the constant abc to the parameter var5: var5=abc

For more information, see Configure node scheduling parameters and Sources and expressions of scheduling parameters.

PyODPS node

To prevent direct modification of your code, PyODPS nodes do not support string substitution with the ${param_name} format. Instead, you retrieve scheduling parameters from the global args dictionary object.

  • Define parameters

    Parameter

    Value

    var1

    $bizdate

    var2

    ${yyyymmdd}

    var3

    $[yyyymmdd]

  • Use parameters

    # Custom parameter: var1 retrieves a built-in parameter value.
    a =args['var1']
    print (format(a))
    # Custom parameter: var2 retrieves a value using ${...} format.
    b =args['var2']
    print (format(b))
    # Custom parameter: var3 retrieves a value using $[...] format.
    c =args['var3']
    print (format(c))

As shown in the preceding example, you assign values in the Scheduling Parameters section. In your code, you reference the parameters by using the dictionary object, such as args['var1'], args['var2'], and args['var3']. The following examples show the assignments:

  • Assign a data timestamp to the parameter var1: var1=$bizdate

  • Assign a data timestamp to the parameter var2: var2=${yyyymmdd}

  • Assign a data timestamp to the parameter var3: var3=$[yyyymmdd]

For more information, see Configure node scheduling parameters and Sources and expressions of scheduling parameters.

Python node

Python nodes receive scheduling parameters as command-line arguments. You list the parameter values in order in the Scheduling Parameters section, and the system passes them to the script at runtime. In the code, you can access these values by using indexes such as sys.argv[1] and sys.argv[2].

Note

Unlike PyODPS nodes, Python nodes do not support referencing parameters directly by name, such as $var1. Instead, parameters are read positionally using sys.argv.

  • Define parameters

    For Python nodes, you assign values as a space-separated list. The values can be expressions or constants, and they map to the script's arguments by position.

    $[yyyymmdd] abc
  • Use parameters

    import sys
    
    # Print all received parameters
    print("Current received parameters:", sys.argv)
    
    # Get the first and second parameters
    param1 = sys.argv[1]
    param2 = sys.argv[2]
    print("Parameter 1:", param1)
    print("Parameter 2:", param2)

As shown in the preceding example, assign values to parameters in the Scheduling Parameters section, separated by spaces. Then, access the values in your code by using indexes like sys.argv[1] and sys.argv[2]. The following examples show the assignments:

  • Assign a scheduling time to the first parameter: $[yyyymmdd].

  • Assign the constant abc to the second parameter: abc.

For more information, see Configure node scheduling parameters and Sources and expressions of scheduling parameters.

Common shell node

Common shell nodes use positional parameters (such as $1, $2, and $3) instead of named variables. For parameters beyond the ninth, use the ${10} syntax.

  • Define parameters

    For common shell nodes, you assign values as a space-separated list. The order of the values must correspond to the order of the positional parameters in your script.

    $bizdate ${yyyymmdd} $[yyyymmdd]
  • Use parameters

    # Positional parameter: Get a built-in parameter value.
    echo $1
    # Positional parameter: Get a value using ${...} format.
    echo $2
    # Positional parameter: Get a value using $[...] format.
    echo $3

After assigning values in the Scheduling Parameters section, you reference them in your code as positional parameters $1, $2, and $3. The assignments in the example are:

  • Assign a data timestamp to the positional parameter $1: $bizdate

  • Assign a data timestamp to the positional parameter $2: ${yyyymmdd}

  • Assign a scheduling time to the positional parameter $3: $[yyyymmdd]

For more information, see Configure node scheduling parameters and Sources and expressions of scheduling parameters.