use of org.apache.druid.math.expr.Expr in project druid by druid-io.
the class IPv4AddressParseExprMacroTest method testNullStringArg.
@Test
public void testNullStringArg() {
Expr nullString = ExprEval.of(null).toExpr();
Assert.assertSame(NULL, eval(nullString));
}
use of org.apache.druid.math.expr.Expr in project druid by druid-io.
the class IPv4AddressParseExprMacroTest method testValidStringArgUnsignedInt.
@Test
public void testValidStringArgUnsignedInt() {
Expr unsignedInt = ExprEval.of("3232235521").toExpr();
Assert.assertEquals(NULL, eval(unsignedInt));
}
use of org.apache.druid.math.expr.Expr in project druid by druid-io.
the class HyperUniqueExpressionsTest method testRoundEstimateWrongArgTypes.
@Test
public void testRoundEstimateWrongArgTypes() {
expectedException.expect(IAE.class);
expectedException.expectMessage("Function[hyper_unique_round_estimate] must take a hyper-log-log collector as input");
Expr expr = Parser.parse("hyper_unique_round_estimate(string)", MACRO_TABLE);
expr.eval(inputBindings);
}
use of org.apache.druid.math.expr.Expr in project druid by druid-io.
the class HyperUniqueExpressionsTest method testEstimate.
@Test
public void testEstimate() {
Expr expr = Parser.parse("hyper_unique_estimate(hyper_unique_add(1.234, hyper_unique()))", MACRO_TABLE);
ExprEval eval = expr.eval(inputBindings);
Assert.assertEquals(ExpressionType.DOUBLE, eval.type());
Assert.assertEquals(1.0, eval.asDouble(), 0.01);
}
use of org.apache.druid.math.expr.Expr in project druid by druid-io.
the class HyperUniqueExpressionsTest method testDouble.
@Test
public void testDouble() {
Expr expr = Parser.parse("hyper_unique_add(1.234, 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(1.234, hyper_unique_add(5.678, 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(double, 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(nullDouble, 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);
}
Aggregations