Jackie-Jiang commented on a change in pull request #8304:
URL: https://github.com/apache/pinot/pull/8304#discussion_r834519689



##########
File path: 
pinot-common/src/main/java/org/apache/pinot/common/function/TransformFunctionType.java
##########
@@ -43,7 +43,14 @@
   EXP("exp"),
   FLOOR("floor"),
   LN("ln"),
+  LOG("log"),
   SQRT("sqrt"),
+  LOG2("log2"),

Review comment:
       (minor) put all log functions together

##########
File path: 
pinot-common/src/main/java/org/apache/pinot/common/function/TransformFunctionType.java
##########
@@ -43,7 +43,14 @@
   EXP("exp"),
   FLOOR("floor"),
   LN("ln"),
+  LOG("log"),
   SQRT("sqrt"),
+  LOG2("log2"),
+  LOG10("log10"),
+  SIGN("sign"),
+  ROUND_DECIMAL("round_decimal"),

Review comment:
       Use camel case without underscore for non filter function
   ```suggestion
     ROUNDDECIMAL("roundDecimal"),
   ```

##########
File path: 
pinot-common/src/main/java/org/apache/pinot/common/function/scalar/ArithmeticFunctions.java
##########
@@ -104,4 +106,46 @@ public static double ln(double a) {
   public static double sqrt(double a) {
     return Math.sqrt(a);
   }
+
+  @ScalarFunction
+  public static double sign(double a) {
+    return Math.signum(a);
+  }
+
+  @ScalarFunction
+  public static double power(double a, double b) {
+    return Math.pow(a, b);
+  }
+
+  @ScalarFunction
+  public static double log2(double a) {

Review comment:
       (minor) Keep all log functions together

##########
File path: 
pinot-common/src/main/java/org/apache/pinot/common/function/scalar/ArithmeticFunctions.java
##########
@@ -104,4 +106,46 @@ public static double ln(double a) {
   public static double sqrt(double a) {
     return Math.sqrt(a);
   }
+
+  @ScalarFunction
+  public static double sign(double a) {
+    return Math.signum(a);
+  }
+
+  @ScalarFunction
+  public static double power(double a, double b) {
+    return Math.pow(a, b);
+  }
+
+  @ScalarFunction
+  public static double log2(double a) {
+    return Math.log(a) / Math.log(2);
+  }
+
+  @ScalarFunction
+  public static double log10(double a) {
+    return Math.log10(a);
+  }
+
+  //TODO: The function should ideally be named 'round'
+  // but it is not possible because of existing DateTimeFunction with same 
name.
+  @ScalarFunction
+  public static double roundDecimal(double a, int b) {
+    return BigDecimal.valueOf(a).setScale(b, 
RoundingMode.HALF_UP).doubleValue();
+  }
+
+  @ScalarFunction
+  public static double roundDecimal(double a) {
+    return BigDecimal.valueOf(a).setScale(0, 
RoundingMode.HALF_UP).doubleValue();

Review comment:
       Can we use Math.round() for this function as `BigDecimal` calculation is 
much more costly? If not, please add some comments explaining the reason. Same 
for the one with scale

##########
File path: 
pinot-core/src/main/java/org/apache/pinot/core/operator/transform/function/PowerTransformFunction.java
##########
@@ -0,0 +1,86 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pinot.core.operator.transform.function;
+
+import com.google.common.base.Preconditions;
+import java.util.List;
+import java.util.Map;
+import org.apache.pinot.core.operator.blocks.ProjectionBlock;
+import org.apache.pinot.core.operator.transform.TransformResultMetadata;
+import org.apache.pinot.segment.spi.datasource.DataSource;
+
+
+public class PowerTransformFunction extends BaseTransformFunction {
+  public static final String FUNCTION_NAME = "power";
+  private double[] _result;

Review comment:
       You may use `_doubleValuesSV` from the `BaseTransformFunction`, same for 
other functions

##########
File path: 
pinot-common/src/main/java/org/apache/pinot/common/function/TransformFunctionType.java
##########
@@ -109,7 +116,25 @@
   ST_WITHIN("ST_Within"),
 
   // Geo indexing
-  GEOTOH3("geoToH3");
+  GEOTOH3("geoToH3"),
+
+
+  //Trigonometry
+  SIN("sin"),
+  COS("cos"),
+  TAN("tan"),
+  COT("cot"),
+  ASIN("asin"),
+  ACOS("acos"),
+  ATAN("atan"),
+  ATAN2("atan2"),
+  SINH("sinh"),
+  COSH("cosh"),
+  TANH("tanh"),
+  DEGREES("degrees"),
+  RADIANS("radians");
+

Review comment:
       (minor, format) Avoid consecutive empty lines

##########
File path: 
pinot-core/src/main/java/org/apache/pinot/core/operator/transform/function/PowerTransformFunction.java
##########
@@ -0,0 +1,86 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pinot.core.operator.transform.function;
+
+import com.google.common.base.Preconditions;
+import java.util.List;
+import java.util.Map;
+import org.apache.pinot.core.operator.blocks.ProjectionBlock;
+import org.apache.pinot.core.operator.transform.TransformResultMetadata;
+import org.apache.pinot.segment.spi.datasource.DataSource;
+
+
+public class PowerTransformFunction extends BaseTransformFunction {
+  public static final String FUNCTION_NAME = "power";
+  private double[] _result;
+  private TransformFunction _leftTransformFunction;
+  private TransformFunction _rightTransformFunction;
+  private Double _exponent;

Review comment:
       We may avoid the boxing/unboxing using primitive double and use `NaN` to 
represent not set, same for other functions

##########
File path: 
pinot-common/src/main/java/org/apache/pinot/common/function/scalar/ArithmeticFunctions.java
##########
@@ -104,4 +106,46 @@ public static double ln(double a) {
   public static double sqrt(double a) {
     return Math.sqrt(a);
   }
+
+  @ScalarFunction
+  public static double sign(double a) {
+    return Math.signum(a);
+  }
+
+  @ScalarFunction
+  public static double power(double a, double b) {
+    return Math.pow(a, b);
+  }
+
+  @ScalarFunction
+  public static double log2(double a) {
+    return Math.log(a) / Math.log(2);
+  }
+
+  @ScalarFunction
+  public static double log10(double a) {
+    return Math.log10(a);
+  }
+
+  //TODO: The function should ideally be named 'round'
+  // but it is not possible because of existing DateTimeFunction with same 
name.
+  @ScalarFunction
+  public static double roundDecimal(double a, int b) {
+    return BigDecimal.valueOf(a).setScale(b, 
RoundingMode.HALF_UP).doubleValue();
+  }
+
+  @ScalarFunction
+  public static double roundDecimal(double a) {
+    return BigDecimal.valueOf(a).setScale(0, 
RoundingMode.HALF_UP).doubleValue();
+  }
+
+  @ScalarFunction
+  public static double truncate(double a, int b) {
+    return BigDecimal.valueOf(a).setScale(b, RoundingMode.DOWN).doubleValue();

Review comment:
       Can this handle negative values correctly? Can we use `Math.floor` for 
it?

##########
File path: 
pinot-common/src/main/java/org/apache/pinot/common/function/TransformFunctionType.java
##########
@@ -109,7 +116,25 @@
   ST_WITHIN("ST_Within"),
 
   // Geo indexing
-  GEOTOH3("geoToH3");
+  GEOTOH3("geoToH3"),
+

Review comment:
       (minor, format) Avoid consecutive empty lines (we might want to add a 
checkstyle rule later)

##########
File path: 
pinot-core/src/main/java/org/apache/pinot/core/operator/transform/function/SingleParamMathTransformFunction.java
##########
@@ -161,4 +162,53 @@ protected void applyMathOperator(double[] values, int 
length) {
       }
     }
   }
+
+  public static class Log2TransformFunction extends 
SingleParamMathTransformFunction {

Review comment:
       (minor) put log functions together

##########
File path: 
pinot-common/src/main/java/org/apache/pinot/common/function/scalar/ArithmeticFunctions.java
##########
@@ -104,4 +106,46 @@ public static double ln(double a) {
   public static double sqrt(double a) {
     return Math.sqrt(a);
   }
+
+  @ScalarFunction
+  public static double sign(double a) {
+    return Math.signum(a);
+  }
+
+  @ScalarFunction
+  public static double power(double a, double b) {
+    return Math.pow(a, b);
+  }
+
+  @ScalarFunction
+  public static double log2(double a) {
+    return Math.log(a) / Math.log(2);
+  }
+
+  @ScalarFunction
+  public static double log10(double a) {
+    return Math.log10(a);
+  }
+
+  //TODO: The function should ideally be named 'round'
+  // but it is not possible because of existing DateTimeFunction with same 
name.
+  @ScalarFunction
+  public static double roundDecimal(double a, int b) {

Review comment:
       Rename the second parameter to `scale` for readability

##########
File path: 
pinot-core/src/main/java/org/apache/pinot/core/operator/transform/function/TransformFunctionFactory.java
##########
@@ -83,7 +97,17 @@ private TransformFunctionFactory() {
           put(canonicalize(TransformFunctionType.EXP.getName().toLowerCase()), 
ExpTransformFunction.class);
           
put(canonicalize(TransformFunctionType.FLOOR.getName().toLowerCase()), 
FloorTransformFunction.class);
           put(canonicalize(TransformFunctionType.LN.getName().toLowerCase()), 
LnTransformFunction.class);
+          put(canonicalize(TransformFunctionType.LOG.getName().toLowerCase()), 
LnTransformFunction.class);
           
put(canonicalize(TransformFunctionType.SQRT.getName().toLowerCase()), 
SqrtTransformFunction.class);
+          
put(canonicalize(TransformFunctionType.LOG2.getName().toLowerCase()), 
Log2TransformFunction.class);

Review comment:
       (minor) put log functions together




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org
For additional commands, e-mail: commits-h...@pinot.apache.org

Reply via email to