Search code examples
apache-nifi

NiFi - How can i change ReplacementValue on ReplaceText?


I'm using ExecuteSQL,SplitAvro,ConvertAvroToJSON,EvaluateJsonPath,ReplaceText,ExecuteSQL.

I am trying to replace the content in the flowfile using replaceText processor.

Now, i can replace like this. -> INSERT INTO values (${id},'${name}') . ReplaceText process send excute sql like this :

INSERT into x values(1,'xx')

INSERT into x values(2,'yy')

INSERT into x values(3,'zz')

I'm sending INSERT query for each line.

But i want to send executesql process like this

INSERT INTO x values (1,'xx'),(2,'yy'),(3,'zz')


Solution

  • i'm not sure it's the best approach but you could do this:

    SplitAvro           # i guess you are splitting the records here (here you should get fragment.* attributes)
    ConvertAvroToJSON   # converting each record to json
    EvaluateJsonPath    # getting id,name values from json
    ReplaceText         # (${id}, '${name}')
    MergeContent        # merge rows back to single file with header and delimiter
       Binary Concatenation
       Header = Insert into X values
       Demarcator = ,
    ExecuteSQL