You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@metron.apache.org by "ASF GitHub Bot (JIRA)" <ji...@apache.org> on 2017/08/02 13:46:00 UTC

[jira] [Commented] (METRON-1038) Stellar should have a better collection of basic math operations

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

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

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

    https://github.com/apache/metron/pull/650#discussion_r130879867
  
    --- Diff: metron-stellar/stellar-common/src/main/java/org/apache/metron/stellar/dsl/functions/MathFunctions.java ---
    @@ -19,45 +19,179 @@
      */
     package org.apache.metron.stellar.dsl.functions;
     
    +import org.apache.metron.stellar.common.utils.math.MathOperations;
    +import org.apache.metron.stellar.common.utils.math.StellarMathFunction;
     import org.apache.metron.stellar.dsl.Context;
     import org.apache.metron.stellar.dsl.ParseException;
     import org.apache.metron.stellar.dsl.Stellar;
     import org.apache.metron.stellar.dsl.StellarFunction;
     
     import java.util.List;
    +import java.util.function.Function;
     
     public class MathFunctions {
     
    +
       @Stellar(name="ABS"
               ,description="Returns the absolute value of a number."
               ,params = {
                     "number - The number to take the absolute value of"
                         }
               , returns="The absolute value of the number passed in."
               )
    -  public static class Abs implements StellarFunction {
    +  public static class Abs extends StellarMathFunction{
    +
    +
    +    public Abs() {
    +      super(MathOperations.ABS);
    +    }
    +  }
    +
    +  @Stellar(name="LOG10"
    +          ,description="Returns the log (base 10) of a number."
    +          ,params = {
    +                "number - The number to take the log (base 10) value of"
    +                    }
    +          , returns="The log (base 10) of the number passed in."
    +          )
    +  public static class Log10 extends StellarMathFunction {
    +   public Log10() {
    +      super(MathOperations.LOG10);
    +    }
    +
    +  }
    +
    +  @Stellar(name="LOG2"
    +          ,description="Returns the log (base 2) of a number."
    +          ,params = {
    +                "number - The number to take the log (base 2) value of"
    +                    }
    +          , returns="The log (base 2) of the number passed in."
    +          )
    +  public static class Log2 extends StellarMathFunction {
    +   public Log2() {
    +      super(MathOperations.LOG2);
    +    }
     
    -    @Override
    -    public Object apply(List<Object> args, Context context) throws ParseException {
    -      if(args.size() < 1) {
    -        return Double.NaN;
    -      }
    -      Number n = (Number)args.get(0);
    -      if(n == null) {
    -        return Double.NaN;
    -      }
    -      return Math.abs(n.doubleValue());
    +  }
    +
    +  @Stellar(name="LN"
    +          ,description="Returns the natural log of a number."
    +          ,params = {
    +                "number - The number to take the natural log value of"
    +                    }
    +          , returns="The natural log of the number passed in."
    +          )
    +  public static class Ln extends StellarMathFunction {
    +   public Ln() {
    +      super(MathOperations.LN);
         }
     
    -    @Override
    -    public void initialize(Context context) {
    +  }
     
    +  @Stellar(name="SQRT"
    +          ,description="Returns the square root of a number."
    +          ,params = {
    +                "number - The number to take the square root of"
    +                    }
    +          , returns="The square root of the number passed in."
    +          )
    +  public static class Sqrt extends StellarMathFunction {
    +   public Sqrt() {
    +      super(MathOperations.SQRT);
         }
     
    -    @Override
    -    public boolean isInitialized() {
    -      return true;
    +  }
    +
    +  @Stellar(name="CEIL"
    +          ,description="Returns the ceiling of a number."
    +          ,params = {
    +                "number - The number to take the ceiling of"
    +                    }
    +          , returns="The ceiling of the number passed in."
    +          )
    +  public static class Ceil extends StellarMathFunction {
    +   public Ceil() {
    +      super(MathOperations.CEIL);
         }
    +
       }
     
    +  @Stellar(name="FLOOR"
    +          ,description="Returns the floor of a number."
    +          ,params = {
    +                "number - The number to take the floor of"
    +                    }
    +          , returns="The floor of the number passed in."
    +          )
    +  public static class Floor extends StellarMathFunction {
    +   public Floor() {
    +      super(MathOperations.FLOOR);
    +    }
    +  }
    +
    +  @Stellar(name="SIN"
    +          ,description="Returns the sin of a number."
    +          ,params = {
    +                "number - The number to take the sin of"
    +                    }
    +          , returns="The sin of the number passed in."
    +          )
    +  public static class Sin extends StellarMathFunction {
    +   public Sin() {
    +      super(MathOperations.SIN);
    +    }
    +  }
    +
    +  @Stellar(name="COS"
    +          ,description="Returns the cos of a number."
    +          ,params = {
    +                "number - The number to take the cos of"
    +                    }
    +          , returns="The cos of the number passed in."
    +          )
    +  public static class Cos extends StellarMathFunction {
    +   public Cos() {
    +      super(MathOperations.COS);
    +    }
    +  }
    +
    +  @Stellar(name="TAN"
    +          ,description="Returns the tan of a number."
    +          ,params = {
    +                "number - The number to take the tan of"
    +                    }
    +          , returns="The tan of the number passed in."
    +          )
    +  public static class Tan extends StellarMathFunction {
    +   public Tan() {
    +      super(MathOperations.TAN);
    +    }
    +  }
    +
    +  @Stellar(name="EXP"
    +          ,description="Returns Euler's number raised to the power of the argument"
    +          ,params = {
    +                "number - The power to which e is raised."
    +                    }
    +          , returns="Euler's number raised to the power of the argument."
    +          )
    +  public static class Exp extends StellarMathFunction {
    +   public Exp() {
    +      super(MathOperations.EXP);
    +    }
    +  }
    +
    +  @Stellar(name="ROUND"
    +          ,description="Rounds a number to the nearest integer"
    --- End diff --
    
    Yeah, I documented it in the most recent commit.


> Stellar should have a better collection of basic math operations
> ----------------------------------------------------------------
>
>                 Key: METRON-1038
>                 URL: https://issues.apache.org/jira/browse/METRON-1038
>             Project: Metron
>          Issue Type: Improvement
>            Reporter: Casey Stella
>
> At the moment the math functions are woefully incomplete.  
> We should add at least the ones difficult or impossible to reconstruct using existing stellar primitives/math functions:
> * log10
> * log2
> * ln
> * sqrt
> * ceil
> * floor
> * sin
> * cos
> * tan



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)