Support Questions

Find answers, ask questions, and share your expertise
Announcements
Celebrating as our community reaches 100,000 members! Thank you!

how to manipulate string value

avatar
Contributor

Screenshot from 2022-07-19 18-02-20.pngHi,

I want to manipulate below string in updateAttribute  processor. I tried replace function etc but it is not working for me. Can anyone suggest to modify below string to change DBName and TableName as per expected output.

query = ${query:replace('nrpuserorgdb2306.status', 'nrpreportdb.user_org_status')}

 

query : "ALTER TABLE `nrpuserorgdb2306`.`status` \nADD COLUMN `is_deleted` TINYINT NULL AFTER `code`"

Expected output:

query : ALTER TABLE `nrpreportdb`.`user_org_status` ADD COLUMN `is_test` TINYINT NULL AFTER `code`

1 ACCEPTED SOLUTION

avatar

@AbhishekSingh It looks like the issue with the Replace Expression Language was just the ` around the database and table name.  That works for me as follows:

 

${query:replace('`nrpuserorgdb2306`.`status`', '`nrpreportdb`.`user_org_status`')}

 

Here is my flow to test:

 

Screen Shot 2022-07-20 at 7.55.44 AM.png

Notice the use of a simple flow to test the concept.  I also set query in GenerateFlowfile and define a separate query2 in UpdateAttribute.  I always work in ways that prove functionality, then when the concept is working, take the lesson learned into real flows.  

 

Some additional Screen Shots:

Screen Shot 2022-07-20 at 7.55.54 AM.png

Screen Shot 2022-07-20 at 7.55.36 AM.png

Screen Shot 2022-07-20 at 7.54.46 AM.png

 

 

Template and Flow Definition File on my GitHub:

https://github.com/cldr-steven-matison/NiFi-Templates

 

 

 

 

View solution in original post

1 REPLY 1

avatar

@AbhishekSingh It looks like the issue with the Replace Expression Language was just the ` around the database and table name.  That works for me as follows:

 

${query:replace('`nrpuserorgdb2306`.`status`', '`nrpreportdb`.`user_org_status`')}

 

Here is my flow to test:

 

Screen Shot 2022-07-20 at 7.55.44 AM.png

Notice the use of a simple flow to test the concept.  I also set query in GenerateFlowfile and define a separate query2 in UpdateAttribute.  I always work in ways that prove functionality, then when the concept is working, take the lesson learned into real flows.  

 

Some additional Screen Shots:

Screen Shot 2022-07-20 at 7.55.54 AM.png

Screen Shot 2022-07-20 at 7.55.36 AM.png

Screen Shot 2022-07-20 at 7.54.46 AM.png

 

 

Template and Flow Definition File on my GitHub:

https://github.com/cldr-steven-matison/NiFi-Templates