This is an automated email from the ASF dual-hosted git repository.

jackie pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pinot.git


The following commit(s) were added to refs/heads/master by this push:
     new 834909e2bd overload divide function to allow a default value when 
denominator==0 (#9196)
834909e2bd is described below

commit 834909e2bd8570205e9de7421fc3f043fa377ecb
Author: wli-git <mail....@gmail.com>
AuthorDate: Fri Aug 12 14:53:36 2022 -0700

    overload divide function to allow a default value when denominator==0 
(#9196)
---
 .../org/apache/pinot/common/function/scalar/ArithmeticFunctions.java | 5 +++++
 .../org/apache/pinot/core/data/function/ArithmeticFunctionsTest.java | 5 +++++
 2 files changed, 10 insertions(+)

diff --git 
a/pinot-common/src/main/java/org/apache/pinot/common/function/scalar/ArithmeticFunctions.java
 
b/pinot-common/src/main/java/org/apache/pinot/common/function/scalar/ArithmeticFunctions.java
index 36d7511fd5..e6d73b0cc4 100644
--- 
a/pinot-common/src/main/java/org/apache/pinot/common/function/scalar/ArithmeticFunctions.java
+++ 
b/pinot-common/src/main/java/org/apache/pinot/common/function/scalar/ArithmeticFunctions.java
@@ -50,6 +50,11 @@ public class ArithmeticFunctions {
     return a / b;
   }
 
+  @ScalarFunction
+  public static double divide(double a, double b, double defaultValue) {
+    return (b == 0) ? defaultValue : a / b;
+  }
+
   @ScalarFunction
   public static double mod(double a, double b) {
     return a % b;
diff --git 
a/pinot-core/src/test/java/org/apache/pinot/core/data/function/ArithmeticFunctionsTest.java
 
b/pinot-core/src/test/java/org/apache/pinot/core/data/function/ArithmeticFunctionsTest.java
index fb46ecedff..404444933e 100644
--- 
a/pinot-core/src/test/java/org/apache/pinot/core/data/function/ArithmeticFunctionsTest.java
+++ 
b/pinot-core/src/test/java/org/apache/pinot/core/data/function/ArithmeticFunctionsTest.java
@@ -96,6 +96,11 @@ public class ArithmeticFunctionsTest {
     inputs.add(new Object[]{"sign(a)", Lists.newArrayList("a"), row6, 1.0});
     inputs.add(new Object[]{"sign(a)", Lists.newArrayList("a"), row7, -1.0});
 
+    GenericRow row8 = new GenericRow();
+    row8.putValue("a", 9.5);
+    row8.putValue("b", 0);
+    inputs.add(new Object[]{"divide(a, b, 0)", Lists.newArrayList("a", "b"), 
row8, 0.0});
+
     return inputs.toArray(new Object[0][]);
   }
 }


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

Reply via email to