Assignment nodes support MaxCompute SQL, SHELL, and Python languages and come with the outputs parameter. You can define the output of the last line of the code for an assignment node as the value of the input parameter of a child node in the node context.

Prerequisites

DataWorks Standard Edition or a more advanced edition is activated so that you can use assignment nodes.

Background information

For EMR Hive, EMR Spark SQL, ODPS Script, Hologres SQL, and AnalyticDB for PostgreSQL nodes that are created in the China (Shanghai) and China (Shenzhen) regions, you can create output parameters on the Properties tab to pass specified values to child nodes. For more information, see Context-based parameters.
For different languages, the outputs parameter has the following limits:
  • The value of the outputs parameter is taken only from the output of the last line of the code.
    • If you use MaxCompute SQL for an assignment node, the output of the SELECT statement in the last line is used.
    • If you use SHELL for an assignment node, the output of the ECHO statement in the last line is used.
    • If you use Python for an assignment node, the output of the PRINT statement in the last line is used.
  • The passed value of the outputs parameter is limited to 2 MB in size. If the output of the assignment statement exceeds this limit, the assignment node fails to run.
Note
  • If you use Python or SHELL, the value of the outputs parameter is a one-dimensional array where elements are separated with commas (,). If you use MaxCompute SQL, the value of the outputs parameter is passed to child nodes as a two-dimensional array.
  • If you use an assignment node as the parent node of other nodes, commit the assignment node first so that the outputs parameter can be parsed when you configure child nodes.

Create an assignment node

  1. Log on to the DataWorks console.
  2. In the left-side navigation pane, click Workspaces.
  3. After you select the region where the required workspace resides, find the workspace and click Data Analytics.
  4. Move the pointer over the Create icon and choose General > Assignment Node.
    Alternatively, you can click the required workflow, right-click General, and then choose Create > Assignment Node.
  5. In the Create Node dialog box, set the Node Name and Location parameters.
    Notice The node name must be 1 to 128 characters in length. It can contain letters, digits, underscores (_), and periods (.).

    This topic describes how to pass data from assignment nodes that separately use the Python, MaxCompute SQL, and SHELL languages to a child node named comparison_shell. In this example, the output of the last line of the code for each assignment node is passed to the child node by using context-based parameters.

    After the assignment nodes that use the Python, MaxCompute SQL, and SHELL languages are created, you must set the dependencies so that the child node can reference the parameter values that are passed by these nodes. For more information about workflows, see Manage workflows.

  6. Click Commit.

Configure the child node to reference the output of the last line of the code for the assignment node that uses MaxCompute SQL

  1. Find the required workflow and double-click the assignment node fuzhi_sql that uses MaxCompute SQL.
  2. On the configuration tab of the fuzhi_sql node that appears, click the Properties tab in the right-side navigation pane.
  3. Configure the fuzhi_sql node.
    The fuzhi_sql node assigns the results that are queried from a specified table to the outputs parameter.fuzhi_sql node
  4. Double-click the comparison_shell node, which is the child node of the fuzhi_sql node.
  5. On the configuration tab of the comparison_shell node that appears, click the Properties tab in the right-side navigation pane and configure the node.
    The comparison_shell node depends on the fuzhi_sql node and uses the value of the outputs parameter of the fuzhi_sql node as the value of its input parameter sql_inputs.
    echo '${sql_inputs}';
    echo 'Use the value in the first line in the output of the fuzhi_sql node as the input'${sql_inputs[0]};
    echo 'Use the value in the second line in the output of the fuzhi_sql node as the input'${sql_inputs[1]};
    echo 'Use the value of the second field in the first line in the output of the fuzhi_sql node as the input'${sql_inputs[0][1]};
    echo 'Use the value of the third field in the second line in the output of the fuzhi_sql node as the input'${sql_inputs[1][2]};
  6. Click the Run icon in the toolbar.
  7. In the Warning message, click Continue to Run.
  8. View the result.

Configure the child node to reference the output of the assignment node that uses Python

  1. Find the required workflow and double-click the assignment node fuzhi_python that uses Python.
  2. On the configuration tab of the fuzhi_python node that appears, click the Properties tab in the right-side navigation pane.
  3. Configure the fuzhi_python node.
    The fuzhi_python node assigns the values a,b,c to the outputs parameter.Python
  4. Double-click the comparison_shell node, which is the child node of the fuzhi_python node.
  5. On the configuration tab of the comparison_shell node that appears, click the Properties tab in the right-side navigation pane and configure the node.
    The comparison_shell node depends on the fuzhi_python node and uses the value of the outputs parameter of the fuzhi_python node as the value of its input parameter python_inputs.
    echo 'The output of the fuzhi_python node'${python_inputs};
    echo 'Use the first value in the output of the fuzhi_python node as the input'${python_inputs[0]};
    echo 'Use the second value in the output of the fuzhi_python node as the input'${python_inputs[1]};[1]}
  6. Click the Run icon in the toolbar.
  7. In the Warning message, click Continue to Run.
  8. View the result.

Configure the child node to reference the output of the assignment node that uses SHELL

  1. Find the required workflow and double-click the assignment node fuzhi_shell that uses SHELL.
  2. On the configuration tab of the fuzhi_shell node that appears, click the Properties tab in the right-side navigation pane.
  3. Configure the fuzhi_shell node.
    The fuzhi_shell node assigns the values hello,world to the outputs parameter.SHELL
  4. Double-click the comparison_shell node, which is the child node of the fuzhi_shell node.
  5. On the configuration tab of the comparison_shell node that appears, click the Properties tab in the right-side navigation pane and configure the node.
    The comparison_shell node depends on the fuzhi_shell node and uses the value of the outputs parameter of the fuzhi_shell node as the value of its input parameter shell_inputs.
    echo 'The output of the fuzhi_shell node'${shell_inputs};
    echo 'Use the first value in the output of the fuzhi_shell node as the input'${shell_inputs[0]};
    echo 'Use the second value in the output of the fuzhi_shell node as the input'${shell_inputs[1]};
  6. Click the Run icon in the toolbar.
  7. In the Warning message, click Continue to Run.
  8. View the result.