use of org.apache.druid.math.expr.Expr in project druid by druid-io.
the class HyperUniqueExpressionsTest method testEstimateWrongArgTypes.
@Test
public void testEstimateWrongArgTypes() {
expectedException.expect(IAE.class);
expectedException.expectMessage("Function[hyper_unique_estimate] must take a hyper-log-log collector as input");
Expr expr = Parser.parse("hyper_unique_estimate(100)", MACRO_TABLE);
expr.eval(inputBindings);
}
use of org.apache.druid.math.expr.Expr in project druid by druid-io.
the class HyperUniqueExpressionsTest method testCreate.
@Test
public void testCreate() {
Expr expr = Parser.parse("hyper_unique()", MACRO_TABLE);
ExprEval eval = expr.eval(inputBindings);
Assert.assertEquals(HyperUniqueExpressions.TYPE, eval.type());
Assert.assertTrue(eval.value() instanceof HyperLogLogCollector);
Assert.assertEquals(0.0, ((HyperLogLogCollector) eval.value()).estimateCardinality(), 0);
}
use of org.apache.druid.math.expr.Expr in project druid by druid-io.
the class HyperUniqueExpressionsTest method testString.
@Test
public void testString() {
Expr expr = Parser.parse("hyper_unique_add('foo', 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('bar', hyper_unique_add('foo', 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(string, 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(nullString, 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 IPv4AddressMatchExprMacroTest method testInvalidArgType.
@Test
public void testInvalidArgType() {
Expr longArray = ExprEval.ofLongArray(new Long[] { 1L, 2L }).toExpr();
Assert.assertFalse(eval(longArray, SUBNET_192_168));
}
use of org.apache.druid.math.expr.Expr in project druid by druid-io.
the class IPv4AddressMatchExprMacroTest method testSubnetArgInvalid.
@Test
public void testSubnetArgInvalid() {
expectException(IllegalArgumentException.class, "subnet arg has an invalid format");
Expr invalidSubnet = ExprEval.of("192.168.0.1/invalid").toExpr();
apply(Arrays.asList(IPV4, invalidSubnet));
}
Aggregations