Support Questions
Find answers, ask questions, and share your expertise
Announcements
Alert: Welcome to the Unified Cloudera Community. Former HCC members be sure to read and learn how to activate your account here.

Not able to apply ifElse keyword in ReplaceText processor

Highlighted

Not able to apply ifElse keyword in ReplaceText processor

New Contributor

I am using below value/configuration in ReplaceText processor

Search Value=(.*),(.*),(.*),(.*),(.*),(.*),,(.*),(.*)

Replacement Value=$1,$2,$3,${'$4':notNull():ifElse('a', 'b')},$5,$6,,$7,$8

i am observing that ifElse statement is not working and processor show below eorror:

ReplaceText[id=a3bb3d35-3a63-15be-ad5f-40a39ece8154] ReplaceText[id=a3bb3d35-3a63-15be-ad5f-40a39ece8154] failed to process session due to org.apache.nifi.attribute.expression.language.exception.AttributeExpressionLanguageException: Invalid Expression: $1,$2,$3,${'$4':notNull():ifElse('a', 'b')},$5,$6,,$7,$8 due to Unexpected token 'ifElse' at line 1, column 17. Query: ${$4:notNull():ifElse(a, b)}: org.apache.nifi.attribute.expression.language.exception.AttributeExpressionLanguageException: Invalid Expression: $1,$2,$3,${'$4':notNull():ifElse('a', 'b')},$5,$6,,$7,$8 due to Unexpected token 'ifElse' at line 1, column 17. Query: ${$4:notNull():ifElse(a, b)}

please suggest how can i use ifElse keyword.

Thanks in Advance.
5 REPLIES 5

Re: Not able to apply ifElse keyword in ReplaceText processor

@Amit Mishra

I just tested this using HDF 3.1.1 and I'm not able to reproduce. I'm using a GenerateFlowFile + ReplaceTextProcessor with the configuration you provided and I don't see any issues. The ifElse expression is working fine. What version of HDF are you using? Do you have any sample input data I can use to test? ( With GenerateFlowFile I'm using simple input data as a,b,c,d,e,f,,g,h )

Re: Not able to apply ifElse keyword in ReplaceText processor

Master Guru

@Amit Mishra

Make sure you are running a new enough version of NiFi that actually contains the ifElse function in the expression language.

-

If you click on hamburger menu in upper right corner and then "help" it will open the embedded NiFi documentation. On the left hand side click on "Expression Language Guide" and make sure the "ifElse" function is listed under the "Boolean Logic" section.
-
If it is not there you will need to upgrade to a newer version of NFi to take advantage of the ifElse function.

-

Thank you,

Matt

Re: Not able to apply ifElse keyword in ReplaceText processor

Master Guru

@Amit Mishra

I should also add that I don't think the "isNull()" function is going to provide you the intended result. The Java regular expression is going to always return the existence of capture group '$4'. The "notNull()" function will then always return "true". My feeling here is that you probably want to be using the "isEmpty()" function instead.

-

Thanks,

Matt

Re: Not able to apply ifElse keyword in ReplaceText processor

Good point! perhaps the ifElse is not part of the HDF version they are using.

Re: Not able to apply ifElse keyword in ReplaceText processor

Master Guru

@Amit Mishra

HCC Forum tip: If you find a provided answer has addressed your question, please take a moment to login and click "accept" below the answer of your choice to close out the question.

Don't have an account?
Coming from Hortonworks? Activate your account here