metron-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ottobackwards <...@git.apache.org>
Subject [GitHub] metron pull request #742: METRON-1168: Add SUBSTRING method to stellar
Date Sat, 09 Sep 2017 00:30:56 GMT
Github user ottobackwards commented on a diff in the pull request:

    https://github.com/apache/metron/pull/742#discussion_r137912941
  
    --- Diff: metron-stellar/stellar-common/src/main/java/org/apache/metron/stellar/dsl/functions/StringFunctions.java
---
    @@ -321,6 +321,46 @@ public Object apply(List<Object> args) {
         }
       }
     
    +  @Stellar( name="SUBSTRING"
    +          , description = "Returns a substring of a string"
    +          , params = {
    +                "input - The string to take the substring of",
    +                "start - The starting position (0-based and inclusive)",
    +                "end? - The ending position (0-based and exclusive)"
    +                     }
    +          , returns = "The substring of the input"
    +  )
    +  public static class Substring extends BaseStellarFunction {
    +
    +    @Override
    +    public Object apply(List<Object> strings) {
    +
    +      if(strings == null || strings.size() < 2 ) {
    +        throw new IllegalArgumentException("[SUBSTRING] required 2 arguments: the input
and the start position (inclusive)");
    +      }
    +      String var = strings.get(0) == null?null: (String) strings.get(0);
    +      Integer start = strings.get(1) == null?null:(Integer)strings.get(1);
    +      Integer end = null;
    +      if(strings.size() > 2) {
    +         end = strings.get(2) == null ? null : (Integer) strings.get(2);
    +      }
    +      if(var == null || start == null) {
    --- End diff --
    
    We are again looking at the behavior with regards to invalid arguments, exception vs default
return....   We need some clarification document.  It seems to come up every addition to Stellar


---

Mime
View raw message