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

ASF GitHub Bot commented on METRON-830:
---------------------------------------

Github user anandsubbu commented on a diff in the pull request:

    https://github.com/apache/incubator-metron/pull/516#discussion_r111098953
  
    --- Diff: 
metron-platform/metron-common/src/main/java/org/apache/metron/common/dsl/functions/StringFunctions.java
 ---
    @@ -343,4 +343,89 @@ public Object apply(List<Object> args) {
           return String.format(format, formatArgs);
         }
       }
    +
    +  @Stellar( name="CHOP"
    +          , description = "Remove the last character from a String"
    +          , params = { "the String to chop last character from, may be 
null"}
    +          , returns = "String without last character, null if null String 
input"
    +  )
    +  public static class chop extends BaseStellarFunction {
    +
    +    @Override
    +    public Object apply(List<Object> strings) {
    +
    +      if(strings.size() == 0) {
    +        throw new IllegalArgumentException("[CHOP] missing argument: 
string to be chopped");
    --- End diff --
    
    Hi @mattf-horton , with the above change where we check for `strings.get(0) 
== null || strings.get(0).toString().length() `, the following test results in 
a failure:
    
    `Assert.assertEquals("abc",  run("CHOP(msg)", ImmutableMap.of("msg", 
"abc\r\n")));`
    
    Pardon my limited understanding, but this is what I inferred:
    - The `if` condition for null and 0 length check occurs twice.
    - In the case of the `msg` test case where we check for `\n\r`, the initial 
contents of the `strings` is null and the variable substitution for `msg` 
occurs subsequently. So, this would end up failing for the 1st check. 
    
    Due to this, I will modify the checks to only verify for `strings == null` 
and `string.size() == 0`. Please let me know if there is a better way this can 
be done.


> Adding StringFunctions to Stellar - chop, prependifmissing, appendifmissing 
> and countmatches
> --------------------------------------------------------------------------------------------
>
>                 Key: METRON-830
>                 URL: https://issues.apache.org/jira/browse/METRON-830
>             Project: Metron
>          Issue Type: Bug
>    Affects Versions: 0.3.1
>            Reporter: Anand Subramanian
>            Assignee: Anand Subramanian
>             Fix For: Next + 1
>
>
> Enhance Stellar by adding the following apache common string functions.
> - chop -> Remove the last character from a String.
> - prependifmissing -> Prepends the prefix to the start of the string if the 
> string does not already start with any of the prefixes.
> - appendifmissing -> Appends the suffix to the end of the string if the 
> string does not already end with any of the suffixes.
> - countmatches -> Counts how many times the substring appears in the larger 
> string.



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)

Reply via email to