Search code examples
expressionapache-nifi

Apache NiFi - RouteOnAttribute expressions and logging


I'm very new to Apache NiFi and I just wanted to try out a small transformation.

This is my file,

product,quantity,identity,cost
apple,10,A,2323
laptop,24,I,1332
tablet,33,B,33121

I want to look for the identity column and if I have 'I', then that row should be rejected the others should be accepted.

I get the file using GetFile processor, and connect to RouteOnAttribute and this is how I have configured my property,

enter image description here

I then connect to

a. LogAttribute for unmatched, I value and then to a PutFile to an error folder.
b. PutFile from RouteOnAttribute on identity to an output folder

I always get the full file in the error folder, it is not rejecting the row based on the expression.

Since I'm very new to this expression languages, I cannot understand if it is really working or not. I need to see what are the expression results? I cannot find anything in the nifi-app.log.

Any help would be appreciated.

Thanks, Ash


Solution

  • Use a QueryRecord processor:

    • Record Reader: CSVReader
    • Record Writer: CSVRecordSetWriter
    • i-match (dynamic property): SELECT * FROM FLOWFILE WHERE "identity"='I'
    • identity (dynamic property): SELECT * FROM FLOWFILE WHERE "identity"<>'I'

    Input (CSV):

    product,quantity,identity,cost
    apple,10,A,2323
    laptop,24,I,1332
    tablet,33,B,33121
    

    Output (i-match):

    product,quantity,identity,cost
    laptop,24,I,1332
    

    Output (identity):

    product,quantity,identity,cost
    apple,10,A,2323
    tablet,33,B,33121