[ 
https://issues.apache.org/jira/browse/NIFI-1919?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15305013#comment-15305013
 ] 

ASF GitHub Bot commented on NIFI-1919:
--------------------------------------

GitHub user alopresto opened a pull request:

    https://github.com/apache/nifi/pull/474

    NIFI-1919 Add replaceFirst method to expression language

    I will open an additional Jira for 1.0 to consider renaming the `replace` 
method to `replaceAllLiteral` or something similar, and add logic to 
`StandardFlowSynchronizer` to perform method replacement if this occurs. 
    
    I think there is an opportunity to refactor and consolidate the 
`*Evaluator` classes -- `ReplaceEvaluator`, `ReplaceFirstEvaluator`, and 
`ReplaceAllEvaluator` are identical save for the delegate `String` method that 
is invoked internally. 

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/alopresto/nifi NIFI-1919

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/nifi/pull/474.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #474
    
----
commit 3431fd47bfd5c0f67d3e8ccfb00af7bebdb5a97e
Author: Andy LoPresto <[email protected]>
Date:   2016-05-25T02:05:34Z

    NIFI-1919 Added Groovy unit test to demonstrate issue.
    Added DelegatingMetaClass code to record it (test not complete).

commit 0780fed41b00607fd17b0ff88f9c5d5d49177694
Author: Andy LoPresto <[email protected]>
Date:   2016-05-25T02:12:19Z

    NIFI-1919 Added working unit test to illustrate fix.

commit f34e2836b1acfb2abcb4a6a98fc13374ba498388
Author: Andy LoPresto <[email protected]>
Date:   2016-05-25T02:28:37Z

    NIFI-1918 Ignored failing test because timing is not deterministic and 
should not be used in unit test.
    
    Signed-off-by: Matt Burgess <[email protected]>
    
    This closes #465

commit bd42a8b85c9fdc6ba2d917b718e558885bdc1282
Author: Andy LoPresto <[email protected]>
Date:   2016-05-25T17:37:18Z

    NIFI-1919 Changed ReplaceEvaluator to use String#replaceFirst which 
interprets regex instead of compiling as literal.
    Demonstrative unit test now passes but two existing unit tests fail. I am 
not sure these tests are correct.

commit 15523f826d22aa38fdf40e294044236c76bcd5f3
Author: Andy LoPresto <[email protected]>
Date:   2016-05-25T17:40:07Z

    NIFI-1919 Ignored demonstrative test for replaceAll as it behaves as 
expected.

commit 7cfd960e1bdac8c04db6f2aee3f57baed3dc077a
Author: Andy LoPresto <[email protected]>
Date:   2016-05-27T02:37:28Z

    NIFI-1919 Added replaceFirst to AttributeExpression lexer and parser 
grammar definitions.

commit ba47ef3f916090646ce40542a406289e2cf757a7
Author: Andy LoPresto <[email protected]>
Date:   2016-05-27T02:38:54Z

    NIFI-1919 Reverted changes to ReplaceEvaluator.
    Added ReplaceFirstEvaluator.
    Added replace first logic to Query buildFunctionEvaluator.
    Added unit tests.

commit 8e832be3e29e2291e7adcf058291bc73ba78e94d
Author: Andy LoPresto <[email protected]>
Date:   2016-05-27T22:50:05Z

    NIFI-1919 Updated expression language guide.

----


> Expression Language only evaluates regular expression replacement on 
> replaceAll, not replace
> --------------------------------------------------------------------------------------------
>
>                 Key: NIFI-1919
>                 URL: https://issues.apache.org/jira/browse/NIFI-1919
>             Project: Apache NiFi
>          Issue Type: Bug
>          Components: Core Framework
>    Affects Versions: 0.6.1
>            Reporter: Andy LoPresto
>            Assignee: Andy LoPresto
>             Fix For: 1.0.0, 0.7.0
>
>
> When {{${attribute:replaceAll('\w+', 'replacement')}}} is called, the pattern 
> is matched and applied. However, when {{${attribute:replace('\w+', 
> 'replacement')}}} is called, it is not. I believe this is because 
> {{ReplaceAllEvaluator}} uses {{String#replaceAll(String regex, String 
> replacement)}} while {{ReplaceEvaluator}} uses {{String#replace(CharSequence 
> target, CharSequence replacement)}} which then uses 
> {{Pattern.compile(target.toString(), Pattern.LITERAL)}} instead of compiling 
> for a regular expression. I am writing a unit test to demonstrate this and 
> show the results when {{String#replaceFirst()}} is used instead. 



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to