How to remove extra comma at end in Nifi Attribute value?

Viewed 364

I am working on Apache Nifi where I do have requirement like remove extra comma at the end.

I would like to join 3 attributes using join method. If all the attribute is having value then it will work perfectly but any of the attribute is not having value then it will add extra comma at the end.

I am using like this

${allAttributes("Attr1", "Attr2", "Attr3"):join(",")}

I have also used trim() function but it will only remove space not common.

Do we have anything equal to trimend() in Nifi

1 Answers

@chandra

There are 2 approaches here:

  1. Assemble the combined attribute and then check if combined attributes ends with , and then remove the last comma using substringBeforeLast. This may require 2 processor steps but may not resolve your problem if all of the original attributes are empty.
  2. Write a more complicated expression language that checks isEmpty/isNull on each attribute before it is combined. You can chain expression languages together and use and/or/ifelse

You will need to experiment with #2 as this will use a chained combination of expression language conditions. My suggestion is to create a simple flow to test with GenerateFlowFile of your string, and updateAttribute with multiple tests per execution.

Also recommend you study the Expression Lanugage guide and keep it bookmarked:

https://nifi.apache.org/docs/nifi-docs/html/expression-language-guide.html

Related