metron-dev mailing list archives

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

    https://github.com/apache/metron/pull/742#discussion_r137913487
  
    --- 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 --
    
    Well, this is consistent throughout stellar functions, if the value is null, we pass back
null.  If it's invalid input structurally (i.e. not the correct number of arguments), then
an exception is returned.  We should add a little blurb that talks about this in the stellar-common
README.md


---

Mime
View raw message