Search code examples
apache-nifi

Apache Ni-Fi expression using ifElse function and condition defined with equals() function returns wrong results for true values


I am working at an Apache Ni-Fi flow that fetches data from a MySQL database and, after some data transformations, it writes data into a Timescale (postgreSQL) database.

I use UpdateRecord 1.15.2 processor to do the data transformations. Those include adding the column /mvalue whose value is calculated according to the following expression:

${metric:equals(18):ifElse(${valueSum}, 9)}

What should happen is that, when the value of column metric is 18, then mvalue should take the value of the column valueSum. Else, the value should be 9.

However, this is not what I get since I get the value 9 for all the rows.

metric is a renamed column that in the original MySQL database is int(11) and in the target database is smallint.

valueSum is double in MySQL and numeric in postgreSQL.

the new calculated column mvalue is numeric in postgreSQL.

What I am doing wrong?

Thanks,

Bernardo


Solution

  • Use a QueryRecord processor:

    • update (dynamic attribute): SELECT *, CASE WHEN metric=18 THEN ${valueSum} ELSE 0 END AS mvalue FROM FLOWFILE