| Change type | Description |
|---|---|
| Introduced in version 3.18 | A new Do While node with Python script support is now available for use in data flows. |
Executes a user-defined Python script and passes the result to an optional execution path, looping while the specified condition is met.
To use this node, start by connecting the input data to the initialInput input pin, which provides the initial input into the Do While loop.
There are two Python script properties ConfigureFields and ProcessRecords. Together, these properties define the way that the node maps, filters and transforms the input records to the node outputs.
Connect the outputToLoop and inputFromLoop pins to a chain of nodes to execute during each loop iteration. These pins may be connected directly to each other if all of the data manipulation occurs in the Script.
Finally, connect the finalOutput pin to the rest of the data flow.
Example Script: use the reschedule method to continue looping until the
count field is greater than or equal to 5 on all rows.
# Check if the count of in1 is less than 5
if in1.count < 5:
# Add in1 to out1
out1 += in1
# Update the count of out1 to be one more than in1's count
out1.count = in1.count + 1
# Reschedule the node such that the loop continues, and preserve the data on the first output
node.reschedule(1)
Properties
ConfigureFields
Configure the output metadata of the node, either as fields which are mapped from an input field, or as new fields. This script is executed prior to reading any records, and must define all of the output fields and their properties (i.e. name, data type).
ProcessRecords
Write the script to execute during each loop iteration. If the reschedule
method is called during a loop iteration, this ensures that all nodes downstream from the
outputToLoop are run again. The argument to the
reschedule method determines which, if any, outputs are preserved. The
script is called once per input record and produces output records by transforming these
input records. Alternatively, if you wish to simply copy values straight over from inputs to
outputs, this can be done as part of the initial mapping in ConfigureFields.
if in1.count<5:out1 += in1out1.count = in1.count + 1node.reschedule(1)AccumulateLoopOutput
Optionally specify whether to include the output from each pass through the loop in the final output.
The default value is False.
For example, assume the following:1. The loop increments the input field 'count' by one each pass through the loop.2. The loop will terminate once 'count' equals five.3. The input pin has a single row like so:
|count|
| 1 |
If AccumulateLoopOutput is false, the final value in the 'count' column is 5 and there is only one row:
|count|
| 5 |
If AccumulateLoopOutput is true, a row is added for each pass through the loop:
|count|
| 1 |
| 2 |
| 3 |
| 4 |
| 5 |
Example data flows
A number of sample Data Flows are available from the Samples workspace, found in the Analyze Directory page.
In the Directory under the /Data360 Samples/Node Examples/ folder, you will find "Looping with Do While nodes", which shows examples of how to use this node.
Inputs and outputs
Inputs: initialInput, inputFromLoop.
Outputs: finalOutput, outputToLoop.