A branch node is a logical control node in DataStudio. It can define the branch logic and the direction of branches under different logical conditions.

Prerequisites

  • DataWorks Standard Edition or a more advanced edition is activated. Then, you can use branch nodes.
  • Generally, branch nodes need to be used together with assignment nodes. For more information, see Configure an assignment node.

Create a branch node

  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. Move the pointer over the Create icon and choose General > Branch Node.
    Alternatively, find the required workflow, right-click General, and then choose Create > Branch Node.
  3. In the Create Node dialog box, set the Node Name and Location parameters.
    Note The node name must be 1 to 128 characters in length and can contain letters, digits, underscores (_), and periods (.).
  4. Click Commit.
  5. Define the branch logic.
    1. In the Definition section, click Add Branch.
    2. In the Branch Definition dialog box, set the parameters.
      Specify branch definition
      Parameter Description
      Condition The following information describes the condition of the branch:
      • You can use only Python comparison operators to define logical conditions for the branch node.
      • If the result of the expression is true when the node is running, the corresponding branch condition is met.
      • If the expression fails to be parsed when the node is running, the whole branch node fails.
      • To define branch conditions, you can use global variables and the parameters that are defined in the node context. For example, the ${input} variable can be used as an input parameter of the branch node.
      Associated Node Output The following information describes the associated node output:
      • The node output is used to configure dependencies between the child nodes and the branch node.
      • If the branch condition is met, the child node that depends on the node output is run. If the child node also depends on the output of other nodes, the status of these nodes also matters.
      • If the branch condition is not met, the child node that depends on the node output is not run. The child node is set to the Not Running state because the branch condition is not met.
      Description The description of the branch. For example, the branches ${input}==1 and ${input}>2 are defined.

      The following example shows associated node outputs.

      Assume that a branch node is associated with two child nodes. The names of the child nodes are qqqq and wwww. If the condition of Branch 1 is met, the qqqq node is run. If the condition of Branch 2 is met, the wwww node is run. When you configure the branch node, you can configure associated node outputs as needed. Assume that the associated node output of Branch 1 is 1234, and the associated node output of Branch 2 is 2324. Both 1234 and 2324 are used as the output names of the branch node. The qqqq node must be associated with the branch node based on the output name 1234. The wwww node must be associated with the branch node based on the output name 2324.

    3. Click OK.
      After you add a branch, you can click Change or Delete.
      • Click Change to modify the branch and related dependencies.
      • Click Delete to delete the branch and related dependencies.
  6. Click the Properties tab in the right-side navigation pane and set the scheduling properties for the node.
    After the branch conditions are defined, the output names are automatically added to the output name list in the Dependencies section of the Properties tab. Then, you can associate child nodes with the branch node based on the output names.
    Note
    • Child nodes inherit dry-run properties of the parent node. Therefore, we recommend that you do not create a node that depends on its last-cycle instance as the branch.
    • The dependencies that are established by drawing lines between nodes are not recorded on the Properties tab. You must manually specify these dependencies.
  7. Commit the node.
    Notice You must set the Rerun and Parent Nodes parameters before you can commit the node.
    1. Click the Commit icon in the toolbar.
    2. In the Commit Node dialog box, enter your comments in the Change description field.
    3. Click OK.
    In a workspace in standard mode, you must click Deploy in the upper-right corner after you commit the do-while node.
  8. Test the node. For more information, see View auto triggered nodes.

Example: Configure child nodes for a branch node

You can associate child nodes with different outputs of a branch node to define the branches under different conditions. For example, in the workflow that is shown in the following figure, the branches Branch_1 and Branch_2 are defined as the child nodes of the branch node. Configure child nodes for a branch node
Branch_1 depends on the output that is named autotest.fenzhi121902_1. Branch_1
Branch_2 depends on the output that is named autotest.fenzhi121902_2. Branch_2
Commit the branch node and run it in Operation Center. In this example, the condition of Branch_1 is met. Branch_1 depends on the autotest.fenzhi121902_1 output of the branch node. The following figures show the operational logs.
  • The condition of Branch_1 is met. The child node of this branch is run. You can select the branch and view the running details of the child node on the Runtime Log tab.
  • The condition of Branch_2 is not met. The child node of this branch is skipped. You can select the branch and view relevant information on the Runtime Log tab.

Supported Python comparison operators

Assume that the value of Variable a is 10 and that of Variable b is 20 in the following table.
Operator Description Example
== Equal: checks whether two objects are equal. (a==b) returns false.
! = Not equal: checks whether two objects are not equal. (a!=b) returns true.
<> Not equal: checks whether two objects are not equal. (a<>b) returns true. This operator is similar to !=.
> Greater than: checks whether x is greater than y. (a>b) returns false.
< Less than: checks whether x is less than y. If the returned result is 1 or 0, 1 indicates true and 0 indicates false. The results 1 and 0 are equivalent to the special variables true and false. (a<b) returns true.
>= Greater than or equal to: checks whether x is greater than or equal to y. (a>=b) returns false.
<= Less than or equal to: checks whether x is less than or equal to y. (a<=b) returns true.