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 #823: METRON-1286 Add MIN & MAX Stellar functions
Date Thu, 30 Nov 2017 01:58:03 GMT
Github user ottobackwards commented on a diff in the pull request:

    https://github.com/apache/metron/pull/823#discussion_r153968584
  
    --- Diff: metron-stellar/stellar-common/src/main/java/org/apache/metron/stellar/dsl/functions/OrdinalFunctions.java
---
    @@ -18,76 +18,91 @@
     
     package org.apache.metron.stellar.dsl.functions;
     
    +import com.google.common.collect.Iterables;
    +import org.apache.metron.stellar.common.utils.ConversionUtils;
     import org.apache.metron.stellar.dsl.BaseStellarFunction;
     import org.apache.metron.stellar.dsl.Stellar;
     
     import java.util.Collections;
     import java.util.List;
    +import java.util.function.BiFunction;
    +import java.util.function.Predicate;
     import java.util.stream.Collectors;
     
     public class OrdinalFunctions {
     
    -    /**
    -     * Stellar Function: MAX
    -     * <p>
    -     * Return the maximum value of a list of input values in a Stellar list
    -     */
    -    @Stellar(name = "MAX"
    -            , description = "Returns the maximum value of a list of input values"
    -            , params = {"list_of_values - Stellar list of values to evaluate. The list
may only contain 1 type of object (only strings or only numbers)" +
    -                        " and the objects must be comparable / ordinal"}
    -            , returns = "The highest value in the list, null if the list is empty or
the input values could not be ordered")
    -    public static class Max extends BaseStellarFunction {
    +  /**
    +   * Stellar Function: MAX
    +   * <p>
    +   * Return the maximum value of a list of input values in a Stellar list
    +   */
    +  @Stellar(name = "MAX"
    +          , description = "Returns the maximum value of a list of input values"
    +          , params = {"list_of_values - Stellar list of values to evaluate. The list
may only contain 1 type of object (only strings or only numbers)" +
    +          " and the objects must be comparable / ordinal"}
    +          , returns = "The highest value in the list, null if the list is empty or the
input values could not be ordered")
    +  public static class Max extends BaseStellarFunction {
     
    -        @Override
    -        public Object apply(List<Object> args) {
    -            if (args.size() < 1 || args.get(0) == null) {
    -                throw new IllegalStateException("MAX function requires at least a Stellar
list of values");
    -            }
    -            List list = (List<Object>) args.get(0);
    -            return orderList(list, true);
    -        }
    +    @Override
    +    public Object apply(List<Object> args) {
    +      if (args.size() < 1 || args.get(0) == null) {
    +        throw new IllegalStateException("MAX function requires at least a Stellar list
of values");
    +      }
    --- End diff --
    
    Ok.  I ok with that, but the documentation in the manual and the Annotation should match
up,
    can should explicitly say that the values need to be the same type, and that type needs
to be comparable.  if you want to give examples that is fine "for example Strings, Numbers...."
    
    Fix that up and I think I'm good. 
    Thanks for all the work on this!


---

Mime
View raw message