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
Go to the DataStudio page.
Log on to the DataWorks console. In the top navigation bar, select the desired region. In the left-side navigation pane, choose . On the page that appears, select the desired workspace from the drop-down list and click Go to Data Development.
Move the pointer over the icon and choose .
Alternatively, you can find the desired workflow, right-click the workflow name and choose
.In the Create Node dialog box, configure the Name and Path parameters.
- Click Confirm.
Define the branch logic.
In the Definition section on the configuration tab of the node, click Add Branch.
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.
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.
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.
NoteChild 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.
Commit and deploy the node.
Click the icon in the top toolbar to save the node.
Click the icon in the top toolbar to commit the node.
In the Submit dialog box, configure the Change description parameter.
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.
View the task.
Click Operation Center in the upper-right corner of the configuration tab of the corresponding node to go to Operation Center in the production environment.
View the scheduled task. For more information, see View and manage auto triggered tasks.
To view more information about the task, 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.
Branch_2 depends on the output that is named autotest.fenzhi121902_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. |