use of org.apache.druid.math.expr.Expr in project druid by druid-io.
the class IPv4AddressParseExprMacroTest method testNullLongArg.
@Test
public void testNullLongArg() {
Expr nullLong = ExprEval.ofLong(null).toExpr();
Assert.assertEquals(NULL, eval(nullLong));
}
use of org.apache.druid.math.expr.Expr in project druid by druid-io.
the class IPv4AddressParseExprMacroTest method eval.
private Object eval(Expr arg) {
Expr expr = apply(Collections.singletonList(arg));
ExprEval eval = expr.eval(InputBindings.nilBindings());
return eval.value();
}
use of org.apache.druid.math.expr.Expr in project druid by druid-io.
the class ExpressionVectorSelectorsTest method setup.
@Before
public void setup() {
Expr parsed = Parser.parse(expression, ExprMacroTable.nil());
outputType = parsed.getOutputType(new ColumnInspector() {
@Nullable
@Override
public ColumnCapabilities getColumnCapabilities(String column) {
return QueryableIndexStorageAdapter.getColumnCapabilities(INDEX, column);
}
});
if (outputType == null) {
outputType = ExpressionType.STRING;
}
}
use of org.apache.druid.math.expr.Expr in project druid by druid-io.
the class Expressions method toQueryGranularity.
/**
* Converts an expression to a Granularity, if possible. This is possible if, and only if, the expression
* is a timestamp_floor function on the __time column with literal parameters for period, origin, and timeZone.
*
* @return granularity or null if not possible
*/
@Nullable
public static Granularity toQueryGranularity(final DruidExpression expression, final ExprMacroTable macroTable) {
final TimestampFloorExprMacro.TimestampFloorExpr expr = asTimestampFloorExpr(expression, macroTable);
if (expr == null) {
return null;
}
final Expr arg = expr.getArg();
final Granularity granularity = expr.getGranularity();
if (ColumnHolder.TIME_COLUMN_NAME.equals(arg.getBindingIfIdentifier())) {
return granularity;
} else {
return null;
}
}
use of org.apache.druid.math.expr.Expr in project druid by druid-io.
the class ExpressionFilter method makeVectorMatcher.
@Override
public VectorValueMatcher makeVectorMatcher(VectorColumnSelectorFactory factory) {
final Expr theExpr = expr.get();
DruidPredicateFactory predicateFactory = new DruidPredicateFactory() {
@Override
public Predicate<String> makeStringPredicate() {
return Evals::asBoolean;
}
@Override
public DruidLongPredicate makeLongPredicate() {
return Evals::asBoolean;
}
@Override
public DruidFloatPredicate makeFloatPredicate() {
return Evals::asBoolean;
}
@Override
public DruidDoublePredicate makeDoublePredicate() {
return Evals::asBoolean;
}
// The hashcode and equals are to make SubclassesMustOverrideEqualsAndHashCodeTest stop complaining..
// DruidPredicateFactory currently doesn't really need equals or hashcode since 'toString' method that is actually
// called when testing equality of DimensionPredicateFilter, so it's the truly required method, but that seems
// a bit strange. DimensionPredicateFilter should probably be reworked to use equals from DruidPredicateFactory
// instead of using toString.
@Override
public int hashCode() {
return super.hashCode();
}
@Override
public boolean equals(Object obj) {
return super.equals(obj);
}
};
final ExpressionType outputType = theExpr.getOutputType(factory);
// effectively constant
if (outputType == null) {
// false matcher
if (NullHandling.sqlCompatible()) {
return BooleanVectorValueMatcher.of(factory.getReadableVectorInspector(), false);
}
// or not.
return BooleanVectorValueMatcher.of(factory.getReadableVectorInspector(), theExpr.eval(InputBindings.nilBindings()).asBoolean());
}
// if we got here, we really have to evaluate the expressions to match
switch(outputType.getType()) {
case LONG:
return VectorValueMatcherColumnProcessorFactory.instance().makeLongProcessor(ColumnCapabilitiesImpl.createSimpleNumericColumnCapabilities(ColumnType.LONG), ExpressionVectorSelectors.makeVectorValueSelector(factory, theExpr)).makeMatcher(predicateFactory);
case DOUBLE:
return VectorValueMatcherColumnProcessorFactory.instance().makeDoubleProcessor(ColumnCapabilitiesImpl.createSimpleNumericColumnCapabilities(ColumnType.DOUBLE), ExpressionVectorSelectors.makeVectorValueSelector(factory, theExpr)).makeMatcher(predicateFactory);
case STRING:
return VectorValueMatcherColumnProcessorFactory.instance().makeObjectProcessor(ColumnCapabilitiesImpl.createSimpleSingleValueStringColumnCapabilities(), ExpressionVectorSelectors.makeVectorObjectSelector(factory, theExpr)).makeMatcher(predicateFactory);
default:
throw new UOE("Vectorized expression matchers not implemented for type: [%s]", outputType);
}
}
Aggregations