mirror of https://github.com/apache/druid.git
Support postaggregation function as in Math.pow()
This commit is contained in:
parent
51dfde0284
commit
1beef30bb2
|
@ -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**:
|
||||
|
||||
|
|
|
@ -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<>();
|
||||
|
|
|
@ -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()
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue