A branch node determines which downstream nodes run and which are skipped based on the output of its upstream node. Typical scenarios include selecting different processing strategies based on data volume, or running different follow-up workflows based on business status codes.
Overview
A branch node uses Python comparison operators to evaluate the output parameters of its upstream node and routes the result to different branches. Each branch can be associated with different downstream nodes. Downstream nodes of a branch whose condition is met run normally, while downstream nodes of a branch whose condition is not met are skipped (dry run).
Typical scenario
Suppose you have a daily data synchronization task and need to select different downstream processing strategies based on the number of rows in the source table:
-
Step 1: The upstream Data profiling node (an assignment node) queries the number of rows in the source table and assigns the result to the output parameter
row_count. -
Step 2: The branch node receives the
row_countparameter and defines two branch conditions:-
Branch 1:
${row_count} > 10000(more than 10,000 rows) -
Branch 2:
${row_count} <= 10000(10,000 rows or fewer)
-
-
Step 3: Branch 1 is associated with a downstream Batch synchronization node (processes large data volumes in batches), and Branch 2 is associated with a downstream Full synchronization node (synchronizes small data volumes in one pass). At runtime, only the downstream nodes of the branch whose condition is met run.
The overall flow is as follows:
Data profiling (outputs row_count) → Branch node (evaluates row_count) → Downstream nodes whose conditions are met run
The following sections use this scenario as an example to describe how to create and configure a branch node.
Dry run mechanism: In a branch node, if a branch does not meet its branch condition at runtime, the downstream nodes of that branch are set to the dry run state, and the log prints a message similar to It's set condition-skip by task. Because the dry run property propagates to downstream nodes, do not place self-dependent tasks on a branch path. For more information about whether to inherit the dry run property from an upstream node, see Inherit the dry run property from upstream nodes.
Prerequisites
-
To use the branch node feature, you must purchase DataWorks Standard Edition or higher. For more information, see DataWorks edition comparison.
-
A branch node is typically used with an assignment node. The upstream assignment node passes the parameters required for evaluation (such as the number of data rows or a status code) to the branch node, which then evaluates the condition based on the parameter value. For more information, see Assignment node.
Precautions
-
Maximum number of branches: A branch node can have a maximum of 50 branches.
-
Empty string evaluation pitfall: Branch conditions do not support evaluation using an empty string (
''). For example, when 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. Use a special placeholder instead of an empty value. For example, set the default parameter value totp_code='NONE'and configure the branch condition as'${tp_code}' != 'NONE'. -
Multiple branch matches: When multiple branch conditions are met at the same time, the downstream nodes of all matching branches run. Ensure that the branch conditions are mutually exclusive, or clarify the business logic for when multiple branches are met simultaneously.
Procedure
-
Log on to the DataWorks console. In the target region, click in the left-side navigation pane. Select a workspace from the drop-down list and click Go to Data Development.
-
Hover over the
icon and choose .Alternatively, you can open the target workflow, right-click a blank area, and choose .
-
In the Create Node dialog box, enter a node name and select a path.
- Click Confirm.
-
Define the branch logic.
-
On the Definition page, click Add Branch.
-
In the Branch Definition dialog box, configure the parameters.
Parameter
Description
Condition
The condition that determines whether this branch runs. Note the following rules:
-
You can only use Python comparison operators to define the logical condition.
-
If the expression evaluates to true at runtime, the corresponding branch condition is met.
-
If an error occurs while parsing the expression at runtime, the entire branch node fails.
-
You can use global variables and parameters defined in the node context in branch conditions. For example, ${input} can be an input parameter defined on the branch node.
Associated Node Output
The output that downstream nodes reference to establish dependencies:
-
Downstream nodes reference this output to declare dependencies.
-
When a branch condition is met, downstream nodes that depend on the associated output run, provided their other upstream dependencies are also met.
-
If a branch condition is not met, the downstream nodes that depend on the corresponding output do not run. DataWorks sets these nodes to the
Not run because the branch condition is not metstate.
Description
Enter a brief description of the branch. For example, you can define two branches with the conditions ${input}==1 and ${input}>2.
Example of configuring the Associated Node Output parameter (using the typical scenario above):
The branch node has two downstream nodes: Batch synchronization and Full synchronization. Associate Branch 1 (condition:
${row_count} > 10000) with the node outputdata_sync.branch_large, and associate Branch 2 (condition:${row_count} <= 10000) with the node outputdata_sync.branch_small. The downstream Batch synchronization node depends ondata_sync.branch_large, and the Full synchronization node depends ondata_sync.branch_small. At runtime, only the downstream nodes of the branch whose condition is met run. -
-
Click OK.
After you add a branch, you can Modify or Delete it.
-
Click Modify to modify the branch settings. DataWorks updates the related dependencies accordingly.
-
Click Delete to remove the branch. DataWorks also updates the related dependencies.
-
-
-
In the right-side pane, click Scheduling Settings to configure the scheduling properties for the node.
After you define the branch conditions, DataWorks automatically adds the output names to the Output Name of Current Node section on the tab. Downstream nodes can use these output names to declare dependencies.
NoteIf you create a dependency by drawing a line to establish a node context and the output name does not appear in Scheduling Settings, you must manually enter the output name.
-
Commit and deploy the node.
-
Click the
icon on the toolbar to save the node. -
Click the
icon on the toolbar to commit the node. -
In the Submission dialog box, enter a Change Description.
-
Click OK.
If you use a workspace in standard mode, you must deploy the task to the production environment after you commit it. Click Deploy Task in the upper-left corner of the top menu bar. For more information, see Deploy tasks.
-
-
View scheduled tasks.
-
In the upper-right corner of the editor, click O&M Personnel to open the production environment's Operation Center.
-
View the scheduled tasks that are running. For more information, see Manage scheduled tasks.
To view more details about scheduled tasks, click Operation Center in the top menu bar. For more information, see Operation Center overview.
-
Example: Select a synchronization strategy based on data volume
The following example shows how to build a complete branch node workflow: the upstream Data profiling node counts the rows in the source table → the branch node selects a synchronization strategy based on the row count → the downstream node runs the corresponding synchronization task.
Step 1: Prepare the upstream assignment node
Create a Data profiling assignment node that queries the number of rows in the source table and assigns the result to the output parameter row_count. The output name of the assignment node is data_sync.probe_output, and the output value is the row count (for example, 15000).
Step 2: Configure the branch node
Create a branch node and set the output data_sync.probe_output of the upstream Data profiling node as the input parameter row_count of the branch node. Then define two branches:
-
Branch 1: The condition is
${row_count} > 10000, associated with the node outputdata_sync.branch_large, with the description "Batch synchronization for large data volumes". -
Branch 2: The condition is
${row_count} <= 10000, associated with the node outputdata_sync.branch_small, with the description "Full synchronization for small data volumes".
Step 3: Configure the downstream nodes
Create two downstream nodes, each depending on a different output of the branch node:
-
Batch synchronization node: In the Scheduling Dependency panel, set the Output Name of Parent Node of the upstream node to
data_sync.branch_large. This node runs only when the data volume exceeds 10,000 rows. -
Full synchronization node: Set the Output Name of Parent Node of the upstream node to
data_sync.branch_small. This node runs only when the data volume is 10,000 rows or fewer.
Step 4: View the runtime results
After you commit and deploy the task, view the runtime results in Operation Center. Assume the source table has 15,000 rows this time (the Branch 1 condition is met):
-
Branch whose condition is met: Branch 1 (
15000 > 10000is true) → the Batch synchronization node runs normally. You can view the execution log and runtime results of this node in the Operational Logs. -
Branch whose condition is not met: Branch 2 (
15000 <= 10000is false) → the Full synchronization node is skipped. Its runtime log displays a yellow message:It's set condition-skip by task, indicating that the node is skipped by the branch condition and the runtime duration is 0s.
This workflow lets you automatically select the most appropriate downstream processing strategy based on the actual state of the upstream data, avoiding unnecessary full or batch processing.
Appendix: Supported Python comparison operators
The following examples assume that variable a is 10 and variable b is 20.
|
Operator |
Description |
Example |
|
== |
Equal to: Checks whether two objects are equal. |
(a == b) returns false. |
|
!= |
Not equal to: Checks whether two objects are not equal. |
(a != b) returns true. |
|
<> |
Not equal to: 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. |
(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. |