You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@druid.apache.org by ab...@apache.org on 2023/01/31 17:25:19 UTC
[druid] branch master updated: Support postaggregation function as in Math.pow() (#13703) (#13704)
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 <ti...@users.noreply.github.com>
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: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org