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());
}
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));
}
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));
}
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);
}
};
}
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();
}
Aggregations