A branch node is a type of control flow node in Data Studio. You can use it to define branching logic and direct tasks to different downstream branches based on specified conditions.
Overview
A branch node evaluates output parameters from upstream nodes using Python comparison operators. This evaluation creates multiple conditional branches, allowing you to run different downstream nodes based on the upstream results.
Prerequisites
The RAM user that you want to use is added to your workspace.
If you want to use a RAM user to develop tasks, you must add the RAM user to your workspace as a member and assign the Develop or Workspace Administrator role to the RAM user. The Workspace Administrator role has more permissions than necessary. Exercise caution when you assign the Workspace Administrator role. For more information about how to add a member and assign roles to the member, see Add members to a workspace.
A serverless resource group is associated with your workspace. For more information, see the topics in the Use serverless resource groups directory.
Before you can configure a branch node, you must create one. For more information, see Create a scheduling workflow node.
Usage notes
Branch nodes are available only in DataWorks Standard Edition or later. For more information about DataWorks editions and how to purchase them, see DataWorks editions.
A single branch node supports a maximum of 50 branches.
Branch nodes are typically used with assignment nodes. For more information, see Assignment node.
If the conditions for a downstream branch are not met, the tasks in that branch enter a dry run state. The log records a message similar to
It's set condition-skip by task.Branch conditions do not support using an empty string (
'') for evaluation. For example, if the branch condition is'${tp_code}' != ''and the parameter value is a space, the space is evaluated as "having a value" (a space is not equal to an empty string), so the branch is still selected. We recommend that you use a special placeholder to represent an empty value. For example, set the default value of the parameter totp_code='NONE', and configure the branch condition as'${tp_code}' != 'NONE'..
Step 1: Develop the branch node
Go to the branch node's configuration page to define the branching logic.
On the Definition page, click Add Branch.
In the Branch Definition dialog box, configure the parameters.
Parameter
Description
Condition
Branch conditions are defined using Python comparison operators.
If an expression evaluates to
trueat runtime, it meets the branch condition.If an expression cannot be parsed at runtime, the entire branch node instance fails.
You can use global variables and parameters defined in the node context within the condition. For example,
${input}can be an input parameter of the branch node.
Associated Node Output
The node output creates dependencies for downstream nodes.
If the branch condition is met, the downstream node dependent on the linked output runs. Its execution also depends on the status of its other upstream nodes.
If the branch condition is not met, the downstream node dependent on the linked output does not run. The status of the node is set to
Not run because branch condition not met.
Description
A brief description of the branch definition. For example, you can define two branches with the conditions ${input}==1 and ${input}>2.
Configure downstream nodes.
You can configure various types of nodes downstream from a branch node. This example uses MySQL nodes.
Create two MySQL nodes named
branch_1andbranch_2, and go to the development page for each node.On the right side of the MySQL node development page, choose , click Add Dependency, select the upstream branch node and its corresponding output, then save the configuration.
After you finish developing the branch node and its downstream nodes, configure their scheduling properties to enable periodic execution. For more information, see Configure scheduling properties for nodes.
Step 2: Deploy and manage nodes
After you complete the scheduling configurations, deploy the nodes to the production environment. For more information, see Deploy nodes and workflows.
After the tasks are deployed, they run periodically based on the configured schedule. You can go to to view the deployed scheduled tasks and perform O&M. For more information, see Introduction to Operation Center.
Appendix: Python comparison operators
Assume that variable a is 10 and variable b is 20.
Operator | Description | Example |
== | Checks if two objects are equal. |
|
!= | Checks if two objects are not equal. |
|
<> | Checks if two objects are not equal. |
|
> | Checks if x is greater than y. |
|
< | Checks if x is less than y. All comparison operators return |
|
>= | Checks if x is greater than or equal to y. |
|
<= | Checks if x is less than or equal to y. |
|