Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NiFi EL How do I get a substring "up to" certain length?

Tags:

apache-nifi

I have this expression to print the first N chars of the flow file content. The problem is when the content length is less than N. What's a good way to say "up to first N chars". That is I will not get an index out of bounds error when the size is less than N.

${incoming_content.0:substring(0,100)}

Here my N=100

Thank you.

like image 280
Vijay Kumar Avatar asked Oct 27 '25 03:10

Vijay Kumar


1 Answers

If the content of your flow files are not too big, you can use ExtractText to convert contents of flowfile as attribute and then use UpdateAttribute processor to run following logic

${incoming.0:length():le(100):ifElse(${incoming.0},${incoming.0:substring(0,100)})}

which is essentially checks if length of flowfile contents (in attribute) is less than equals to 100, if true, return entire string as is, else return substring up to 100 characters

like image 62
Pushkr Avatar answered Oct 29 '25 00:10

Pushkr