Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.
Originally posted by: rabbott***NOTE: This is a retroactive post for posterity. The issue is already resolved, but worth noting for the community.
***
Question:
Using a Filter node, when attempting to evaluate whether two fields in the same record do not contain "null" values, and to output just those records where this condition is true, placing this logic in a "where" clause has the expected results, whereas the same logic when used in an "if/then" statement does not.
The attached provides two sets of examples. In the first set of three, in the left-hand box, the top node uses the "where" clauses and has the expected results. The bottom two use the "isNotNull()" and "notEquals(null)" operators, each with the same unexpected result set.
In the right-hand box, the top node uses the "where" clause and has the expected result, whereas the bottom node uses an "if/then" statement with the same logic and has unexpected results.
Answer:
This is working as expected due to the way BRAINscript variables are initialized and their scope.
As an example, one of the filter nodes reported as working incorrectly has the script:
if col1.isNotNull() and col2.isNotNull() then test="BothNotNull"
emit *, test
where test.equals("BothNotNull")
The variable "test" will be uninitialized until a record is hit which contains both a not NULL col1 and not NULL col2.
Up until this point, the test.equals("BothNotNull") will evaluate to false.
However, the test variable is then never reset, so for all executions after this point, it will remain as "BothNotNull" and all records after this point will be output.
To work as intended, the script should be changed to something like:
if col1.isNotNull() and col2.isNotNull() then
test="BothNotNull"
else
test="BothNull"
emit *, test
where test.equals("BothNotNull")
Attachments:
If_And_Null_Statement_Test.brg