You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@nifi.apache.org by "Otto Fowler (JIRA)" <ji...@apache.org> on 2018/05/29 13:51:00 UTC
[jira] [Commented] (NIFI-4272) ReplaceText processor does not
properly iterate multiple replacement values when EL is used
[ https://issues.apache.org/jira/browse/NIFI-4272?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16493546#comment-16493546 ]
Otto Fowler commented on NIFI-4272:
-----------------------------------
I have a test to reproduce this issue, and I understand why it is happening.
The EL get's evaluated before the regex, so the regex ends up NOT having the first capture group $1 in it, but instead after the EL has NAME, thus no replacement down the line.
Without el the replacement ( String.replaceAll(REGEX)) regex has new$1 in it so it works.
I am looking at how to resolve this, I think I have a methodology, but I don't think it can be implemented as things currently stand in the frameworks.
Basically, we need to evaluate the EL AFTER we do the regex replacement.
{code:java}
@Test
public void testWithELInReplacement() throws IOException {
final TestRunner runner = getRunner();
runner.setProperty(ReplaceText.SEARCH_VALUE, "\"([a-z]+)\":\"(\\w+)\"");
runner.setProperty(ReplaceText.REPLACEMENT_VALUE, "${'$1':toUpper()}:$2");
//runner.setProperty(ReplaceText.REPLACEMENT_VALUE, "\"new$1\":\"$2\"");
runner.enqueue("{\"name\":\"Smith\",\"middle\":\"nifi\",\"firstname\":\"John\"}");
runner.run();
runner.assertAllFlowFilesTransferred(ReplaceText.REL_SUCCESS, 1);
final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).get(0);
out.assertContentEquals("{\"NAME\":\"Smith\",\"MIDDLE\":\"nifi\",\"FIRSTNAME\":\"John\"}");
}
{code}
> ReplaceText processor does not properly iterate multiple replacement values when EL is used
> -------------------------------------------------------------------------------------------
>
> Key: NIFI-4272
> URL: https://issues.apache.org/jira/browse/NIFI-4272
> Project: Apache NiFi
> Issue Type: Bug
> Components: Core Framework
> Affects Versions: 1.1.0, 1.2.0, 1.3.0
> Reporter: Matthew Clarke
> Priority: Major
>
> I am using the ReplaceText processor to take a string input (example: {"name":"Smith","middle":"nifi","firstname":"John"} ) and change all the filed names to all uppercase.
> Using above input as an example, I expect output like {"NAME":"Smith","MIDDLE":"nifi","FIRSTNAME":"John"}
> I expect I should be able to do this with ReplaceText processor; however, I see some unexpected behavior:
> -------
> Test 1: (uses EL in the replacement value property)
> Search value: \"([a-z]+?)\":\"(.+?)\"
> Replacement Value: \"*${'$1':toUpper()}*":\"$2\"
> Result: {"NAME":"Smith","NAME":"nifi","NAME":"John"}
> -------
> Test 2: (Does not use EL in the replacement Value property)
> Search value: \"([a-z]+?)\":\"(.+?)\"
> Replacement Value: \"new$1":\"$2\"
> Result: {"newname":"Smith","newmiddle":"nifi","newfirstname":"John"}
> --------
> As you can see if I use a NiFi expression Language statement in the Replacement Value property it no longer iterates as expect through the various $1 captured values. It repeatedly uses the EL result from the first EL evaluation in every iteration while $2 correctly iterates through the search values.
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)