- Subscribe to RSS Feed
- Mark Question as New
- Mark Question as Read
- Float this Question for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page
Nifi Padding string ?
- Labels:
-
Apache NiFi
Created ‎04-28-2017 08:58 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Is there a function or an expression in NIFI to left pad character strings
Created on ‎05-01-2017 04:01 PM - edited ‎08-17-2019 08:19 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You are correct that a function does not exist at this time for padding left or right of a string.
That being said, You can easily accomplish string padding using a simple flow consisting of a RouteOnAttribute" and "UpdateAttribute" processor.
The RouteOnAttribute would contain one routing rule that checks the length of an attributes value and if it is not long enough routes it to the update attribute where you add one character of padding.
My rule looks like this:
-- "10" is the length I want my attribute to be.
-- "test" is the attribute that I am calculating the length of.
My UpdateAttribute processor then simply pads the value assigned to"test" with a single character.
FlowFiles will continue in this loop until the value of "test" has reached 10 charatcters in length.
Any FlowFile where the value associated to "test" has a length longer then 10 is just passed on without any change.
Thanks,
Matt
Created ‎04-28-2017 09:02 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Is there an standard padding function in NIFI to pad a string , as in leftpad or rightpad functions provided with other languages. I see toRadix come close to Leftpad for numbers resulting in the number getting padded with zeroes to the left.
Created on ‎05-01-2017 04:01 PM - edited ‎08-17-2019 08:19 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You are correct that a function does not exist at this time for padding left or right of a string.
That being said, You can easily accomplish string padding using a simple flow consisting of a RouteOnAttribute" and "UpdateAttribute" processor.
The RouteOnAttribute would contain one routing rule that checks the length of an attributes value and if it is not long enough routes it to the update attribute where you add one character of padding.
My rule looks like this:
-- "10" is the length I want my attribute to be.
-- "test" is the attribute that I am calculating the length of.
My UpdateAttribute processor then simply pads the value assigned to"test" with a single character.
FlowFiles will continue in this loop until the value of "test" has reached 10 charatcters in length.
Any FlowFile where the value associated to "test" has a length longer then 10 is just passed on without any change.
Thanks,
Matt
Created ‎06-01-2022 12:22 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Anyone coming to look at this now (Jun 2022) - You can simply use UpdateAttribute with ${test:padLeft(10, '0')} to pad a string with zeroes.
