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.

Note
  • You can only use branch nodes in DataWorks Standard Edition or higher.
  • Generally, branch nodes need to be used with assignment nodes. For more information about assignment nodes, see Assignment node.

Create a branch node

  1. Log on to the DataWorks console. In the left-side navigation pane, click Workspaces. On the Workspaces page, find the target workspace and click Data Analytics in the Actions column.
  2. On the Data Analytics tab that appears, move the pointer over the Create icon icon and choose General > Branch Node.

    Alternatively, you can click a workflow in the left-side navigation pane, right-click General, and then choose Create > Branch Node.

  3. In the Create Node dialog box that appears, set Node Name and Location.
    Note The node name must be 1 to 128 characters in length.
  4. Click Commit.

Define the branch logic

  1. After the branch node is created, the node configuration tab appears.
  2. In the Definition section, click Add Branch. In the Branch Definition dialog box that appears, set the parameters.
    Parameter Description
    Condition
    • The condition of the branch. You can only use 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 parameters 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 associated node output of the branch. The node output is used to configure dependencies for the child nodes of the branch node.
    • If the branch condition is met, the child node corresponding to the node output is run. If the child node also depends on the output of other nodes, the status of these nodes is considered.
    • If the branch condition is not met, the child node corresponding to the node output is not run. The child node is set to the Not Running state.
    Description The description of the branch. For example, the branches ${input}==1 and ${input}>2 are defined. They are described as 1 and 2, respectively.Define branches
  3. After the parameters are set, click OK.
    After adding a branch, you can click Change or Delete in the Actions column of the branch to edit or delete it.
    • Click Change to modify the branch and related dependencies.
    • Click Delete to delete the branch and related dependencies.

Configure the node properties

After the branch conditions are defined, the output names are automatically added to the Outputs section on the Properties tab. Then, you can associate child nodes with the branch node based on the output names.Configure the node properties
Note The dependencies established by drawing lines between nodes on the dashboard of a workflow are not recorded on the Properties tab. You must manually enter these dependencies.

Example: Configure child nodes for a branch node

You can associate child nodes with different output results of a branch node to define the branches under different conditions. For example, in the workflow shown in the following figure, the branches Branch_1 and Branch_2 are defined as child nodes of the branch node.Configure child nodes for a branch node
Branch_1 depends on the output named autotest.fenzhi121902_1, as shown in the following figure.Branch_1
Branch_2 depends on the output named autotest.fenzhi121902_2, as shown in the following figure.Branch_2

Commit and run the branch node

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 condition of Branch_1 is met. The child node of this branch is run. You can select the branch and view the running details 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

In the following table, assume that the value of the a variable is 10 and that of the b variable is 20.
Comparison 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 the variable on the left side of the operator is greater than that on the right side. (a>b) returns false.
< Less than: checks whether the variable on the left side of the operator is less than that on the right side. If the return result is 0 or 1, 0 indicates false and 1 indicates true. These two results are equivalent to the special variables true and false, respectively. (a<b) returns true.
>= Greater than or equal to: checks whether the variable on the left side of the operator is greater than or equal to that on the right side. (a>=b) returns false.
<= Less than or equal to: checks whether the variable on the left side of the operator is less than or equal to that on the right side. (a<=b) returns true.