Search in sources :

Example 11 with ExprEval

use of org.apache.druid.math.expr.ExprEval in project druid by druid-io.

the class BloomFilterExpressionsTest method testFilter.

@Test
public void testFilter() {
    Expr expr = Parser.parse("bloom_filter_test(1.234, bloom_filter_add(1.234, bloomy))", macroTable);
    ExprEval eval = expr.eval(inputBindings);
    Assert.assertEquals(ExpressionType.LONG, eval.type());
    Assert.assertTrue(eval.asBoolean());
    expr = Parser.parse("bloom_filter_test(1234, bloom_filter_add(1234, bloomy))", macroTable);
    eval = expr.eval(inputBindings);
    Assert.assertTrue(eval.asBoolean());
    expr = Parser.parse("bloom_filter_test('foo', bloom_filter_add('foo', bloomy))", macroTable);
    eval = expr.eval(inputBindings);
    Assert.assertTrue(eval.asBoolean());
    expr = Parser.parse("bloom_filter_test('bar', bloom_filter_add('foo', bloomy))", macroTable);
    eval = expr.eval(inputBindings);
    Assert.assertFalse(eval.asBoolean());
    expr = Parser.parse("bloom_filter_test(1234, bloom_filter_add('foo', bloomy))", macroTable);
    eval = expr.eval(inputBindings);
    Assert.assertFalse(eval.asBoolean());
    expr = Parser.parse("bloom_filter_test(1.23, bloom_filter_add('foo', bloomy))", macroTable);
    eval = expr.eval(inputBindings);
    Assert.assertFalse(eval.asBoolean());
    expr = Parser.parse("bloom_filter_test(1234, bloom_filter_add(1234, bloom_filter(100)))", macroTable);
    eval = expr.eval(inputBindings);
    Assert.assertTrue(eval.asBoolean());
    expr = Parser.parse("bloom_filter_test(4321, bloom_filter_add(1234, bloom_filter(100)))", macroTable);
    eval = expr.eval(inputBindings);
    Assert.assertFalse(eval.asBoolean());
    expr = Parser.parse("bloom_filter_test(4321, bloom_filter_add(bloom_filter_add(1234, bloom_filter(100)), bloom_filter_add(4321, bloom_filter(100))))", macroTable);
    eval = expr.eval(inputBindings);
    Assert.assertTrue(eval.asBoolean());
}
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 12 with ExprEval

use of org.apache.druid.math.expr.ExprEval in project druid by druid-io.

the class BloomFilterExpressionsTest method testAddDouble.

@Test
public void testAddDouble() {
    Expr expr = Parser.parse("bloom_filter_add(1.234, bloomy)", macroTable);
    ExprEval eval = expr.eval(inputBindings);
    Assert.assertEquals(BloomFilterExpressions.BLOOM_FILTER_TYPE, eval.type());
    Assert.assertTrue(eval.value() instanceof BloomKFilter);
    Assert.assertTrue(((BloomKFilter) eval.value()).testDouble(SOME_DOUBLE));
    expr = Parser.parse("bloom_filter_add(double, bloomy)", macroTable);
    eval = expr.eval(inputBindings);
    Assert.assertEquals(BloomFilterExpressions.BLOOM_FILTER_TYPE, eval.type());
    Assert.assertTrue(eval.value() instanceof BloomKFilter);
    Assert.assertTrue(((BloomKFilter) eval.value()).testDouble(SOME_DOUBLE));
}
Also used : ExprEval(org.apache.druid.math.expr.ExprEval) Expr(org.apache.druid.math.expr.Expr) BloomKFilter(org.apache.druid.query.filter.BloomKFilter) InitializedNullHandlingTest(org.apache.druid.testing.InitializedNullHandlingTest) Test(org.junit.Test)

Example 13 with ExprEval

use of org.apache.druid.math.expr.ExprEval in project druid by druid-io.

the class BloomFilterExpressionsTest method testAddString.

@Test
public void testAddString() {
    Expr expr = Parser.parse("bloom_filter_add('foo', bloomy)", macroTable);
    ExprEval eval = expr.eval(inputBindings);
    Assert.assertEquals(BloomFilterExpressions.BLOOM_FILTER_TYPE, eval.type());
    Assert.assertTrue(eval.value() instanceof BloomKFilter);
    Assert.assertTrue(((BloomKFilter) eval.value()).testString(SOME_STRING));
    expr = Parser.parse("bloom_filter_add(string, bloomy)", macroTable);
    eval = expr.eval(inputBindings);
    Assert.assertEquals(BloomFilterExpressions.BLOOM_FILTER_TYPE, eval.type());
    Assert.assertTrue(eval.value() instanceof BloomKFilter);
    Assert.assertTrue(((BloomKFilter) eval.value()).testString(SOME_STRING));
}
Also used : ExprEval(org.apache.druid.math.expr.ExprEval) Expr(org.apache.druid.math.expr.Expr) BloomKFilter(org.apache.druid.query.filter.BloomKFilter) InitializedNullHandlingTest(org.apache.druid.testing.InitializedNullHandlingTest) Test(org.junit.Test)

Example 14 with ExprEval

use of org.apache.druid.math.expr.ExprEval in project druid by druid-io.

the class ExpressionMultiValueDimensionSelector method makeValueMatcher.

@Override
public ValueMatcher makeValueMatcher(Predicate<String> predicate) {
    return new ValueMatcher() {

        @Override
        public boolean matches() {
            ExprEval evaluated = getEvaluated();
            if (evaluated.isArray()) {
                List<String> array = getArray(evaluated);
                return array.stream().anyMatch(x -> predicate.apply(x));
            }
            return predicate.apply(getValue(evaluated));
        }

        @Override
        public void inspectRuntimeShape(RuntimeShapeInspector inspector) {
            inspector.visit("selector", baseSelector);
            inspector.visit("predicate", predicate);
        }
    };
}
Also used : ExprEval(org.apache.druid.math.expr.ExprEval) ValueMatcher(org.apache.druid.query.filter.ValueMatcher) RuntimeShapeInspector(org.apache.druid.query.monomorphicprocessing.RuntimeShapeInspector)

Example 15 with ExprEval

use of org.apache.druid.math.expr.ExprEval in project druid by druid-io.

the class ExpressionMultiValueDimensionSelector method getRow.

@Override
public IndexedInts getRow() {
    ExprEval evaluated = getEvaluated();
    if (evaluated.isArray()) {
        RangeIndexedInts ints = new RangeIndexedInts();
        Object[] evaluatedArray = evaluated.asArray();
        ints.setSize(evaluatedArray != null ? evaluatedArray.length : 0);
        return ints;
    }
    return ZeroIndexedInts.instance();
}
Also used : ExprEval(org.apache.druid.math.expr.ExprEval) RangeIndexedInts(org.apache.druid.segment.data.RangeIndexedInts)

Aggregations

ExprEval (org.apache.druid.math.expr.ExprEval)19 Expr (org.apache.druid.math.expr.Expr)17 InitializedNullHandlingTest (org.apache.druid.testing.InitializedNullHandlingTest)11 Test (org.junit.Test)11 HyperLogLogCollector (org.apache.druid.hll.HyperLogLogCollector)4 BloomKFilter (org.apache.druid.query.filter.BloomKFilter)4 IAE (org.apache.druid.java.util.common.IAE)2 BigDecimal (java.math.BigDecimal)1 Arrays (java.util.Arrays)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 RelDataType (org.apache.calcite.rel.type.RelDataType)1 RexBuilder (org.apache.calcite.rex.RexBuilder)1 RexExecutor (org.apache.calcite.rex.RexExecutor)1 RexNode (org.apache.calcite.rex.RexNode)1 SqlTypeName (org.apache.calcite.sql.type.SqlTypeName)1 SubnetUtils (org.apache.commons.net.util.SubnetUtils)1 DateTimes (org.apache.druid.java.util.common.DateTimes)1 ExprType (org.apache.druid.math.expr.ExprType)1 InputBindings (org.apache.druid.math.expr.InputBindings)1