Search in sources :

Example 86 with Expr

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());
}
Also used : Expr(org.apache.druid.math.expr.Expr) Test(org.junit.Test)

Example 87 with Expr

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);
}
Also used : ExprEval(org.apache.druid.math.expr.ExprEval) Expr(org.apache.druid.math.expr.Expr) InitializedNullHandlingTest(org.apache.druid.testing.InitializedNullHandlingTest) Test(org.junit.Test)

Example 88 with Expr

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);
}
Also used : ExprEval(org.apache.druid.math.expr.ExprEval) Expr(org.apache.druid.math.expr.Expr) HyperLogLogCollector(org.apache.druid.hll.HyperLogLogCollector) InitializedNullHandlingTest(org.apache.druid.testing.InitializedNullHandlingTest) Test(org.junit.Test)

Example 89 with Expr

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);
}
Also used : Expr(org.apache.druid.math.expr.Expr) InitializedNullHandlingTest(org.apache.druid.testing.InitializedNullHandlingTest) Test(org.junit.Test)

Example 90 with Expr

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));
}
Also used : Expr(org.apache.druid.math.expr.Expr) Test(org.junit.Test)

Aggregations

Expr (org.apache.druid.math.expr.Expr)104 Test (org.junit.Test)58 ExprEval (org.apache.druid.math.expr.ExprEval)18 InitializedNullHandlingTest (org.apache.druid.testing.InitializedNullHandlingTest)17 IAE (org.apache.druid.java.util.common.IAE)14 ExpressionType (org.apache.druid.math.expr.ExpressionType)8 DruidExpression (org.apache.druid.sql.calcite.expression.DruidExpression)7 ArrayList (java.util.ArrayList)6 Nullable (javax.annotation.Nullable)6 HashSet (java.util.HashSet)5 List (java.util.List)4 HyperLogLogCollector (org.apache.druid.hll.HyperLogLogCollector)4 BloomKFilter (org.apache.druid.query.filter.BloomKFilter)4 InDimFilter (org.apache.druid.query.filter.InDimFilter)4 RexNode (org.apache.calcite.rex.RexNode)3 Filter (org.apache.druid.query.filter.Filter)3 VirtualColumn (org.apache.druid.segment.VirtualColumn)3 FalseFilter (org.apache.druid.segment.filter.FalseFilter)3 OrFilter (org.apache.druid.segment.filter.OrFilter)3 SelectorFilter (org.apache.druid.segment.filter.SelectorFilter)3