I am new to apache nifi, expression languages. I have a requirement to validate the flow file attribute value and route based on that.
Here is what I have as an requirement.
UPDATE: Detailed requirement:
- The Nifi workflow will read a json/csv data and process each record at a time. At the moment, we are working with considering the input data in json format.
- Each json object will have attrs as (i have stripped down few other attrs which are not necessary for my question/this topic)
{
"REC_YEAR": 2020,
"DESCRIPTION": "test",
"CURRENCY_CD": "USD",
"CALCULATED_FLAG": "N",
"CUR_IND": "Y",
"START_DT": "2020-12-19 17:33:35",
"END_DT": "9999-12-31 00:00:00"
}
Using "EvaluateJsonPath" processor, I read the json attrs into the flowfile attribute.
One of the attribute called CURRENCY_CD which can be either NULL/empty or if its not empty, then it should be of length 3 chars --> this is one of the key requirement (for validation of the incoming data).
So VALID data use cases are CURRENCY_CD can be null, empty or any 3 char string. Any other value for that attr is considered as INVALID input data and route to logging processor flow.
I am using "UpdateAttribute" processor to evaluate some logic using expression language query and store them under the flowfile attributes.
I came up with the below logic to validate CURRENCY_CD requirement as:
${ ${CURRENCY_CD:isEmpty()} :or(${CURRENCY_CD:isEmpty():not():and(${CURRENCY_CD:length():equals(3)})}) }
Then i use "RouteOnAttribute" processor to check the value of this attribute and route accordingly to invalid flow (for logging) or pass the incoming data for further processing workflow stages.
Input data: Now, when I supply the input data as empty string in json, I'd expect it to be TRUE. but it ends up in FALSE always. what am I doing wrong here?
Input Sample #1
{
"CURRENCY_CD": ""
}
Input Sample #2
{
"CURRENCY_CD": null
}
For either of these values, empty string or null, nifi marks those respective attributes with values as "Empty string set".
If I try to break this logic into multiple attributes to check the expression boolean conditions separately, it does evaluates correctly. The Or() condition to combine them is where I expect to be true but it evaluates to false.
Then, i tried using like this as well,
${
${Is-CURRENCY_CD-Empty:equals(true)}
:or(${Is-CURRENCY_CD-NotEmptyAndLen3:equals(true)})
}
and store it in an attr "Is_CurrencyCode_Valid" and expect it to be true, but in turn, it comes with false.