use of org.apache.druid.math.expr.Expr in project druid by druid-io.
the class TimestampShiftMacroTest method testPeriodMinute.
@Test
public void testPeriodMinute() {
Expr expr = apply(ImmutableList.of(ExprEval.of(timestamp.getMillis()).toExpr(), ExprEval.of("PT1M").toExpr(), ExprEval.of(1).toExpr()));
Assert.assertEquals(timestamp.withPeriodAdded(Minutes.ONE, 1).getMillis(), expr.eval(InputBindings.nilBindings()).asLong());
}
use of org.apache.druid.math.expr.Expr in project druid by druid-io.
the class HyperUniqueExpressionsTest method testEstimateRound.
@Test
public void testEstimateRound() {
Expr expr = Parser.parse("hyper_unique_round_estimate(hyper_unique_add(1.234, hyper_unique()))", MACRO_TABLE);
ExprEval eval = expr.eval(inputBindings);
Assert.assertEquals(ExpressionType.LONG, eval.type());
Assert.assertEquals(1L, eval.asLong(), 0.01);
}
use of org.apache.druid.math.expr.Expr in project druid by druid-io.
the class HyperUniqueExpressionsTest method testLong.
@Test
public void testLong() {
Expr expr = Parser.parse("hyper_unique_add(1234, hyper_unique())", MACRO_TABLE);
ExprEval eval = expr.eval(inputBindings);
Assert.assertEquals(HyperUniqueExpressions.TYPE, eval.type());
Assert.assertTrue(eval.value() instanceof HyperLogLogCollector);
Assert.assertEquals(1.0, ((HyperLogLogCollector) eval.value()).estimateCardinality(), 0.01);
expr = Parser.parse("hyper_unique_add(1234, hyper_unique_add(5678, hyper_unique()))", MACRO_TABLE);
eval = expr.eval(inputBindings);
Assert.assertEquals(HyperUniqueExpressions.TYPE, eval.type());
Assert.assertTrue(eval.value() instanceof HyperLogLogCollector);
Assert.assertEquals(2.0, ((HyperLogLogCollector) eval.value()).estimateCardinality(), 0.01);
expr = Parser.parse("hyper_unique_add(long, hyper_unique())", MACRO_TABLE);
eval = expr.eval(inputBindings);
Assert.assertEquals(HyperUniqueExpressions.TYPE, eval.type());
Assert.assertTrue(eval.value() instanceof HyperLogLogCollector);
Assert.assertEquals(1.0, ((HyperLogLogCollector) eval.value()).estimateCardinality(), 0.01);
expr = Parser.parse("hyper_unique_add(nullLong, hyper_unique())", MACRO_TABLE);
eval = expr.eval(inputBindings);
Assert.assertEquals(HyperUniqueExpressions.TYPE, eval.type());
Assert.assertTrue(eval.value() instanceof HyperLogLogCollector);
Assert.assertEquals(NullHandling.replaceWithDefault() ? 1.0 : 0.0, ((HyperLogLogCollector) eval.value()).estimateCardinality(), 0.01);
}
use of org.apache.druid.math.expr.Expr in project druid by druid-io.
the class HyperUniqueExpressionsTest method testAddWrongArgType.
@Test
public void testAddWrongArgType() {
expectedException.expect(IAE.class);
expectedException.expectMessage("Function[hyper_unique_add] must take a hyper-log-log collector as the second argument");
Expr expr = Parser.parse("hyper_unique_add(long, string)", MACRO_TABLE);
expr.eval(inputBindings);
}
use of org.apache.druid.math.expr.Expr in project druid by druid-io.
the class IPv4AddressMatchExprMacroTest method testNotIpAddress.
@Test
public void testNotIpAddress() {
Expr notIpAddress = ExprEval.of("druid.apache.org").toExpr();
Assert.assertFalse(eval(notIpAddress, SUBNET_192_168));
}
Aggregations