Search in sources :

Example 1 with ConstantExprEvalSelector

use of org.apache.druid.segment.ConstantExprEvalSelector in project druid by druid-io.

the class ExpressionSelectors method makeExprEvalSelector.

public static ColumnValueSelector<ExprEval> makeExprEvalSelector(ColumnSelectorFactory columnSelectorFactory, ExpressionPlan plan) {
    if (plan.is(ExpressionPlan.Trait.SINGLE_INPUT_SCALAR)) {
        final String column = plan.getSingleInputName();
        final ColumnType inputType = plan.getSingleInputType();
        if (inputType.is(ValueType.LONG)) {
            return new SingleLongInputCachingExpressionColumnValueSelector(columnSelectorFactory.makeColumnValueSelector(column), plan.getExpression(), // __time doesn't need an LRU cache since it is sorted.
            !ColumnHolder.TIME_COLUMN_NAME.equals(column));
        } else if (inputType.is(ValueType.STRING)) {
            return new SingleStringInputCachingExpressionColumnValueSelector(columnSelectorFactory.makeDimensionSelector(new DefaultDimensionSpec(column, column, ColumnType.STRING)), plan.getExpression());
        }
    }
    final Expr.ObjectBinding bindings = createBindings(columnSelectorFactory, plan);
    // Optimization for constant expressions
    if (bindings.equals(InputBindings.nilBindings())) {
        return new ConstantExprEvalSelector(plan.getExpression().eval(bindings));
    }
    // per row basis
    if (plan.any(ExpressionPlan.Trait.UNKNOWN_INPUTS, ExpressionPlan.Trait.INCOMPLETE_INPUTS)) {
        return new RowBasedExpressionColumnValueSelector(plan, bindings);
    }
    // generic expression value selector for fully known input types
    return new ExpressionColumnValueSelector(plan.getAppliedExpression(), bindings);
}
Also used : ColumnType(org.apache.druid.segment.column.ColumnType) Expr(org.apache.druid.math.expr.Expr) ConstantExprEvalSelector(org.apache.druid.segment.ConstantExprEvalSelector) DefaultDimensionSpec(org.apache.druid.query.dimension.DefaultDimensionSpec)

Aggregations

Expr (org.apache.druid.math.expr.Expr)1 DefaultDimensionSpec (org.apache.druid.query.dimension.DefaultDimensionSpec)1 ConstantExprEvalSelector (org.apache.druid.segment.ConstantExprEvalSelector)1 ColumnType (org.apache.druid.segment.column.ColumnType)1