All Products
Search
Document Center

DataWorks:Branch node

Last Updated:Feb 26, 2024

Branch nodes are a type of logical control node in DataStudio. A branch node can define the branch logic and the direction of branches under different logical conditions.

Precautions

  • Only DataWorks Standard Edition and a more advanced edition support branch nodes. For information about DataWorks editions, see Differences among DataWorks editions.

  • A maximum of 50 branches can be attached to a branch node.

  • In most cases, branch nodes need to be used together with assignment nodes. For more information about assignment nodes, see Configure an assignment node.

Create a branch node

  1. Go to the DataStudio page.

    Log on to the DataWorks console. In the left-side navigation pane, choose Data Modeling and Development > DataStudio. On the page that appears, select the desired workspace from the drop-down list and click Go to DataStudio.

  2. Move the pointer over the 新建 icon and choose Create Node > General > Branch Node.

    Alternatively, you can find the desired workflow, right-click General and then choose Create Node > Branch Node.

  3. In the Create Node dialog box, configure the Name and Path parameters.

  4. Click Confirm.
  5. Define the branch logic.

    1. In the Definition section on the configuration tab of the node, click Add Branch.

    2. In the Branch Definition dialog box, configure the parameters. The following table describes the parameters.

      配置分支定义

      Parameter

      Description

      Condition

      The following information describes the branch conditions:

      • 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 a 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 is also considered.

      • If the branch condition is not met, the child node that depends on the node output is not run. The child node enters 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 the associated node output.

      A branch node is associated with two child nodes named 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 output based on your business requirements. If 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 modify or delete the branch.

      • Click Change to modify the branch. The related dependencies are also modified.

      • Click Delete to delete the branch. The related dependencies are also deleted.

  6. Click the Properties tab in the right-side navigation pane and configure 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. We recommend that you do not create a node that depends on its last-cycle instance as the branch. For more information, see Configure cross-cycle scheduling dependencies.

    • 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 and deploy the node.

    1. Click the 保存 icon in the top toolbar to save the node.

    2. Click the 提交 icon in the top toolbar to commit the node.

    3. In the Submit dialog box, configure the Change description parameter.

    4. Click Confirm.

    If you use a workspace in standard mode, you must deploy the node to the production environment after you commit the node. In the top navigation bar, click Deploy. For more information, see Deploy nodes.

  8. View the node.

    1. Click Operation Center in the upper-right corner of the configuration tab of the node to go to Operation Center in the production environment.

    2. View the scheduled node. For more information, see View and manage auto triggered nodes.

    To view more information about the node, click Operation Center in the top navigation bar of the DataStudio page. For more information, see Overview.

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.下游挂载

Branch_1 depends on the output that is named autotest.fenzhi121902_1.分支1

Branch_2 depends on the output that is named autotest.fenzhi121902_2.分支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. 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.