Jackie-Jiang commented on code in PR #8582:
URL: https://github.com/apache/pinot/pull/8582#discussion_r864096070


##########
pinot-common/src/main/java/org/apache/pinot/common/function/scalar/ComparisonFunctions.java:
##########
@@ -0,0 +1,65 @@
+/**
+ * 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.common.function.scalar;
+
+import org.apache.pinot.spi.annotations.ScalarFunction;
+
+public class ComparisonFunctions {
+
+  private static final double DOUBLE_COMPARISON_TOLERANCE = 1e-7d;
+
+  private ComparisonFunctions() {
+  }
+
+  @ScalarFunction
+  public static boolean greaterThan(double a, double b) {
+    return a > b;
+  }
+
+  @ScalarFunction
+  public static boolean greaterThanOrEqual(double a, double b) {
+    return a >= b;
+  }
+
+  @ScalarFunction
+  public static boolean lessThan(double a, double b) {
+    return a < b;
+  }
+
+  @ScalarFunction
+  public static boolean lessThanOrEqual(double a, double b) {
+    return a <= b;
+  }
+
+  @ScalarFunction
+  public static boolean notEquals(double a, double b) {
+    return (Math.abs(a - b) >= DOUBLE_COMPARISON_TOLERANCE);
+  }
+
+  @ScalarFunction
+  public static boolean equals(double a, double b) {
+    // To avoid approximation errors
+    return (Math.abs(a - b) < DOUBLE_COMPARISON_TOLERANCE);
+  }
+
+  @ScalarFunction
+  public static boolean between(double val, double a, double b) {
+    return (val > a) && (val < b);

Review Comment:
   (nit)
   ```suggestion
       return val > a && val < b;
   ```



##########
pinot-common/src/main/java/org/apache/pinot/common/function/scalar/ComparisonFunctions.java:
##########
@@ -0,0 +1,65 @@
+/**
+ * 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.common.function.scalar;
+
+import org.apache.pinot.spi.annotations.ScalarFunction;
+
+public class ComparisonFunctions {
+
+  private static final double DOUBLE_COMPARISON_TOLERANCE = 1e-7d;
+
+  private ComparisonFunctions() {
+  }
+
+  @ScalarFunction
+  public static boolean greaterThan(double a, double b) {
+    return a > b;
+  }
+
+  @ScalarFunction
+  public static boolean greaterThanOrEqual(double a, double b) {
+    return a >= b;
+  }
+
+  @ScalarFunction
+  public static boolean lessThan(double a, double b) {
+    return a < b;
+  }
+
+  @ScalarFunction
+  public static boolean lessThanOrEqual(double a, double b) {
+    return a <= b;
+  }
+
+  @ScalarFunction
+  public static boolean notEquals(double a, double b) {
+    return (Math.abs(a - b) >= DOUBLE_COMPARISON_TOLERANCE);

Review Comment:
   (nit)
   ```suggestion
       return Math.abs(a - b) >= DOUBLE_COMPARISON_TOLERANCE;
   ```



##########
pinot-common/src/main/java/org/apache/pinot/common/function/scalar/ObjectFunctions.java:
##########
@@ -0,0 +1,37 @@
+/**
+ * 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.common.function.scalar;
+
+import org.apache.pinot.spi.annotations.ScalarFunction;
+
+
+public class ObjectFunctions {
+  private ObjectFunctions() {
+  }
+
+  @ScalarFunction(nullableParameters = true)
+  public static boolean isNull(Object obj) {
+    return obj == null;
+  }
+
+  @ScalarFunction(nullableParameters = true)
+  public static boolean isNotNull(Object obj) {

Review Comment:
   (minor)
   ```suggestion
     public static boolean isNotNull(@Nullable Object obj) {
   ```



##########
pinot-segment-local/src/main/java/org/apache/pinot/segment/local/function/InbuiltFunctionEvaluator.java:
##########
@@ -68,17 +69,27 @@ private ExecutableNode planExecution(ExpressionContext 
expression) {
           childNodes[i] = planExecution(arguments.get(i));
         }
         String functionName = function.getFunctionName();
-        FunctionInfo functionInfo = 
FunctionRegistry.getFunctionInfo(functionName, numArguments);
-        if (functionInfo == null) {
-          if (FunctionRegistry.containsFunction(functionName)) {
-            throw new IllegalStateException(
-              String.format("Unsupported function: %s with %d parameters", 
functionName, numArguments));
-          } else {
-            throw new IllegalStateException(
-              String.format("Unsupported function: %s not found", 
functionName));
-          }
+        switch (functionName) {
+          case "and":
+            return new AndExecutionNode(childNodes);
+          case "or":
+            return new OrExecutionNode(childNodes);
+          case "not":
+            Preconditions.checkState(numArguments == 1, "Unsupported number of 
arguments for NOT operator");

Review Comment:
   (minor)
   ```suggestion
               Preconditions.checkState(numArguments == 1, "NOT function 
expects 1 argument, got: %s", numArguments);
   ```



##########
pinot-common/src/main/java/org/apache/pinot/common/function/scalar/ComparisonFunctions.java:
##########
@@ -0,0 +1,65 @@
+/**
+ * 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.common.function.scalar;
+
+import org.apache.pinot.spi.annotations.ScalarFunction;
+
+public class ComparisonFunctions {
+
+  private static final double DOUBLE_COMPARISON_TOLERANCE = 1e-7d;
+
+  private ComparisonFunctions() {
+  }
+
+  @ScalarFunction
+  public static boolean greaterThan(double a, double b) {
+    return a > b;
+  }
+
+  @ScalarFunction
+  public static boolean greaterThanOrEqual(double a, double b) {
+    return a >= b;
+  }
+
+  @ScalarFunction
+  public static boolean lessThan(double a, double b) {
+    return a < b;
+  }
+
+  @ScalarFunction
+  public static boolean lessThanOrEqual(double a, double b) {
+    return a <= b;
+  }
+
+  @ScalarFunction
+  public static boolean notEquals(double a, double b) {
+    return (Math.abs(a - b) >= DOUBLE_COMPARISON_TOLERANCE);
+  }
+
+  @ScalarFunction
+  public static boolean equals(double a, double b) {
+    // To avoid approximation errors
+    return (Math.abs(a - b) < DOUBLE_COMPARISON_TOLERANCE);

Review Comment:
   (nit)
   ```suggestion
       return Math.abs(a - b) < DOUBLE_COMPARISON_TOLERANCE;
   ```



##########
pinot-common/src/main/java/org/apache/pinot/common/function/scalar/ObjectFunctions.java:
##########
@@ -0,0 +1,37 @@
+/**
+ * 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.common.function.scalar;
+
+import org.apache.pinot.spi.annotations.ScalarFunction;
+
+
+public class ObjectFunctions {
+  private ObjectFunctions() {
+  }
+
+  @ScalarFunction(nullableParameters = true)
+  public static boolean isNull(Object obj) {

Review Comment:
   (minor)
   ```suggestion
     public static boolean isNull(@Nullable Object obj) {
   ```



-- 
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