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

ASF subversion and git services commented on NIFI-15628:
--------------------------------------------------------

Commit efb54cb39ffca8347ca5d79076dcbfc62a0a93ad in nifi's branch 
refs/heads/main from mcducks
[ https://gitbox.apache.org/repos/asf?p=nifi.git;h=efb54cb39f ]

NIFI-15628 - Add unique() expression language function

- Added UniqueEvaluator for removing duplicates from delimited strings
- Preserves order of first occurrence using LinkedHashSet
- Handles special regex characters with Pattern.quote()
- Empty strings treated as distinct values
- Added unit tests
- Updated ANTLR grammar (lexer and parser)
- Integrated into ExpressionCompiler with proper type coercion
- Added documentation to expression language guide

This closes #10923.

Signed-off-by: Pierre Villard <[email protected]>


> Add Expression Language function unique(delimiter) to return unique delimited 
> values
> ------------------------------------------------------------------------------------
>
>                 Key: NIFI-15628
>                 URL: https://issues.apache.org/jira/browse/NIFI-15628
>             Project: Apache NiFi
>          Issue Type: Improvement
>          Components: NiFi API
>            Reporter: Richard Scott
>            Priority: Minor
>             Fix For: 2.9.0
>
>          Time Spent: 1.5h
>  Remaining Estimate: 0h
>
> This function returns the *unique values* from a {*}delimited string{*}, 
> {*}preserving the order of first occurrence{*}. The function takes a 
> delimiter argument, splits the subject string on that delimiter, removes 
> duplicate tokens while keeping the first occurrence, and joins the remaining 
> tokens using the same delimiter.
> *Subject Type:* String
> *Arguments:*
>  * {{delimiter}} (String): delimiter used to split and join the subject string
> *Return Type:* String
> h2. Use Case
> Many flows produce list-like attributes (e.g., tags, labels, realms, paths, 
> routing hops) that accumulate duplicates as processing continues. A built-in 
> function to deduplicate while preserving the original order improves 
> readability, consistency, and downstream matching without requiring scripting.
> h2. Examples
> If the {{tags}} attribute has value:
> {{red,blue,red,green,blue,yellow}}
> ||Expression||Value||
> |{{{}$\{tags:unique(','){}}}}|{{red,blue,green,yellow}}|
> |{{{}$\{tags:unique(';'){}}}}|{{red,blue,red,green,blue,yellow}}|



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to