The 'If' component can evaluate an expression involving variables and direct the flow of an orchestration job depending upon whether the expression evaluates to 'true' or 'false'.
The component has 3 output connectors. A Blue connector is followed when the expression evaluates to 'true'. An orange connector is followed when the expression evaluates to 'false'. The usual 'Red' connector is followed if a runtime error occurs during evaluation.
Variables involved in the expression must be declared in advance. Some general help on defining and using variables is available here
Note that two dates are unlikely to be exactly equal, unless neither has a time element. In such cases, two conditions can be used with a combination of Less than and Greater than to ensure the datetime falls within a range. Date constants should be entered as 'yyyy-MM-dd', 'yyyy-MM-dd HH:mm' or 'yyyy-MM-dd HH:mm:ss' depending upon the level of precision required.
|Name||Text||The descriptive name for the component.|
|Condition (Simple Mode)||Input Variable||The variable to use in the comparison.|
|Qualifier||Select Is or Not. Not reverses the meaning of the Comparator, for example changing an Equals to a Not Equals expression.|
Less than - To test if the input variable is less than the value
Less than or equals to - To test if the input variable is less than or equal to the value
Equal to - To test if the input variable is exactly equal to the value
Greater than or equal to - To test if the input variable is greater than or equal to the value
Greater than - To test if the input variable is greater than the value
Blank - To test if the input variable is blank. If the input variable is null, it will be considered blank.
|Value||Most commonly, a constant value, but can also be a variable reference or expression. The value is parsed according to the type of the input variable.|
|Combine Conditions||Select||And or Or. For a single Condition this makes no difference. For multiple conditions, this specifies whether to 'And' or 'Or' them together. For a more complex mixture or And and Or, use the Advanced Mode where you may use parenthesis to group conditions together.|
This example loads data from S3 and checks that at least 1,000 rows were loaded. We define an expression that tests if the number of loaded rows is greater than 1,000, and when this is false an alert is sent via SNS (and the job is marked as failed).
A numeric variable called "loaded_rows" is defined, with a default value of 0.
The "Row Count" from the S3 Load is exported into the new "loaded_rows" variable. This is on the 'Export' tab after selecting the S3 Load component.
The "If" component can then be configured
The configuration is simple in this case. Notice we are checking that the loaded rows are greater than 1000 - the flow shows that when this is false (the orange connector) then the alert is sent.
In this example we load data in from a Query component to perform some statistical analysis. However, this analysis is really only meaningful if we have over 200 rows of data to work with. In light of this, we use an If Component to decide whether or not to transform our loaded data. The job is shown below.
We want to the If Component to compare the number of rows to a value so our first action is to create a variable to hold the number of rows loaded. Navigate to Project→Manage Environment Variables and add a new variable of Numeric Type.
This variable can now be used to hold the rowcount in our Query component (in this case, JIRA Query) by navigating to the component's 'Export' tab and clicking 'Edit'. Select the source as Row Count and the target variable is our newly created Numeric variable.
Our If Component is set up as below. We have set the mode to Advanced.
Advanced mode allows us to write our own conditional statements in the 'Condition' property. Shown below, we ensure our rowcount exceeds 200.
When this job is run, the Task panel will confirm that the If Component has been evaluated as true.
For the sake of example, requiring over 1200 rows will result in a failure, since our JIRA Query component has been limited to 1000 records. In this case, the Task panel will report that the condition has not been met.
In this example, we use the If component to branch a job into one of several paths based on the state of a variable. The variable 'sftp_inbound_path' is a string that is 'data_google_campaign' if we're looking at data from Google or 'data_bing_campaign' if we're looking at data from bing. We don't want to transform both data sets the same way so this is an ideal way of creating a job that can handle both and choose an appropriate course of action. The job is shown below.
The If component has 3 possible outcomes: either our condition is met, it is valid but not met, or the condition is invalid (an error occurs). The If component properties and Condition is shown below. Here, we have used the 'contains' java function to compare our variable string to 'google_campaign'.
So if our variable is 'data_google_campaign' this contains 'google_campaign' and will be true and lead to the GoogleTransform job. If our variable is 'data_bing_campaign' the If component will evaluate false and lead to the BingTransform job. However, if this variable is not defined, we will receive an error and the job will terminate gracefully by leading to the End Failure component. The Task log output for each outcome (Success, Failure, Error from top to bottom) is shown below.
filename.indexOf('data2016.csv') > -1 || filename.indexOf('data18.csv') > -1 || filename.indexOf('data_current.csv') > -1