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

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


The following commit(s) were added to refs/heads/master by this push:
     new 1beef30bb2 Support  postaggregation function  as in Math.pow() 
(#13703)  (#13704)
1beef30bb2 is described below

commit 1beef30bb29af94156e8cd96407c23eeece2de3a
Author: Tijo Thomas <[email protected]>
AuthorDate: Tue Jan 31 22:55:04 2023 +0530

    Support  postaggregation function  as in Math.pow() (#13703)  (#13704)
    
    Support postaggregation function as in Math.pow()
---
 docs/querying/post-aggregations.md                 |  2 +-
 .../aggregation/post/ArithmeticPostAggregator.java |  9 +++++++
 .../post/ArithmeticPostAggregatorTest.java         | 29 ++++++++++++++++++++++
 3 files changed, 39 insertions(+), 1 deletion(-)

diff --git a/docs/querying/post-aggregations.md 
b/docs/querying/post-aggregations.md
index c75d122eb2..935ca8fbce 100644
--- a/docs/querying/post-aggregations.md
+++ b/docs/querying/post-aggregations.md
@@ -36,7 +36,7 @@ There are several post-aggregators available.
 The arithmetic post-aggregator applies the provided function to the given
 fields from left to right. The fields can be aggregators or other post 
aggregators.
 
-Supported functions are `+`, `-`, `*`, `/`, and `quotient`.
+Supported functions are `+`, `-`, `*`, `/`, `pow` and `quotient`.
 
 **Note**:
 
diff --git 
a/processing/src/main/java/org/apache/druid/query/aggregation/post/ArithmeticPostAggregator.java
 
b/processing/src/main/java/org/apache/druid/query/aggregation/post/ArithmeticPostAggregator.java
index d79682dbff..d36252c181 100644
--- 
a/processing/src/main/java/org/apache/druid/query/aggregation/post/ArithmeticPostAggregator.java
+++ 
b/processing/src/main/java/org/apache/druid/query/aggregation/post/ArithmeticPostAggregator.java
@@ -204,6 +204,7 @@ public class ArithmeticPostAggregator implements 
PostAggregator
       case MINUS:
       case DIV:
       case QUOTIENT:
+      case POW:
         return true;
       default:
         throw new IAE(op.fn);
@@ -246,6 +247,14 @@ public class ArithmeticPostAggregator implements 
PostAggregator
       {
         return lhs / rhs;
       }
+    },
+
+    POW("pow") {
+      @Override
+      public double compute(double lhs, double rhs)
+      {
+        return Math.pow(lhs, rhs);
+      }
     };
 
     private static final Map<String, Ops> LOOKUP_MAP = new HashMap<>();
diff --git 
a/processing/src/test/java/org/apache/druid/query/aggregation/post/ArithmeticPostAggregatorTest.java
 
b/processing/src/test/java/org/apache/druid/query/aggregation/post/ArithmeticPostAggregatorTest.java
index a930344275..7e1d4d112b 100644
--- 
a/processing/src/test/java/org/apache/druid/query/aggregation/post/ArithmeticPostAggregatorTest.java
+++ 
b/processing/src/test/java/org/apache/druid/query/aggregation/post/ArithmeticPostAggregatorTest.java
@@ -183,7 +183,36 @@ public class ArithmeticPostAggregatorTest extends 
InitializedNullHandlingTest
     Assert.assertEquals(Double.POSITIVE_INFINITY, 
agg.compute(ImmutableMap.of("value", 1)));
     Assert.assertEquals(Double.NEGATIVE_INFINITY, 
agg.compute(ImmutableMap.of("value", -1)));
   }
+  @Test
+  public void testPow()
+  {
+    ArithmeticPostAggregator agg = new ArithmeticPostAggregator(
+            null,
+            "pow",
+            ImmutableList.of(
+                    new ConstantPostAggregator("value", 4),
+                    new ConstantPostAggregator("power", .5)
+            ),
+            "numericFirst"
+    );
+    Assert.assertEquals(2.0, agg.compute(ImmutableMap.of("value", 0)));
 
+    agg = new ArithmeticPostAggregator(
+            null,
+            "pow",
+            ImmutableList.of(
+                    new FieldAccessPostAggregator("base", "value"),
+                    new ConstantPostAggregator("zero", 0)
+            ),
+            "numericFirst"
+    );
+
+    Assert.assertEquals(1.0, agg.compute(ImmutableMap.of("value", 0)));
+    Assert.assertEquals(1.0, agg.compute(ImmutableMap.of("value", 
Double.NaN)));
+    Assert.assertEquals(1.0, agg.compute(ImmutableMap.of("value", 1)));
+    Assert.assertEquals(1.0, agg.compute(ImmutableMap.of("value", -1)));
+    Assert.assertEquals(1.0, agg.compute(ImmutableMap.of("value", .5)));
+  }
   @Test
   public void testDiv()
   {


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to