use of io.trino.sql.planner.ExpressionInterpreter in project trino by trinodb.
the class ExpressionUtils method constantExpressionEvaluatesSuccessfully.
private static boolean constantExpressionEvaluatesSuccessfully(PlannerContext plannerContext, Session session, Expression constantExpression) {
Map<NodeRef<Expression>, Type> types = getExpressionTypes(plannerContext, session, constantExpression, TypeProvider.empty());
ExpressionInterpreter interpreter = new ExpressionInterpreter(constantExpression, plannerContext, session, types);
Object literalValue = interpreter.optimize(NoOpSymbolResolver.INSTANCE);
return !(literalValue instanceof Expression);
}
use of io.trino.sql.planner.ExpressionInterpreter in project trino by trinodb.
the class SimplifyExpressions method rewrite.
public static Expression rewrite(Expression expression, Session session, SymbolAllocator symbolAllocator, PlannerContext plannerContext, TypeAnalyzer typeAnalyzer) {
requireNonNull(plannerContext, "plannerContext is null");
requireNonNull(typeAnalyzer, "typeAnalyzer is null");
if (expression instanceof SymbolReference) {
return expression;
}
Map<NodeRef<Expression>, Type> expressionTypes = typeAnalyzer.getTypes(session, symbolAllocator.getTypes(), expression);
expression = pushDownNegations(plannerContext.getMetadata(), expression, expressionTypes);
expression = extractCommonPredicates(plannerContext.getMetadata(), expression);
expression = normalizeOrExpression(expression);
expressionTypes = typeAnalyzer.getTypes(session, symbolAllocator.getTypes(), expression);
ExpressionInterpreter interpreter = new ExpressionInterpreter(expression, plannerContext, session, expressionTypes);
Object optimized = interpreter.optimize(NoOpSymbolResolver.INSTANCE);
return new LiteralEncoder(plannerContext).toExpression(session, optimized, expressionTypes.get(NodeRef.of(expression)));
}
use of io.trino.sql.planner.ExpressionInterpreter in project trino by trinodb.
the class TestExpressionInterpreter method optimize.
static Object optimize(Expression parsedExpression) {
Map<NodeRef<Expression>, Type> expressionTypes = getTypes(TEST_SESSION, PLANNER_CONTEXT, SYMBOL_TYPES, parsedExpression);
ExpressionInterpreter interpreter = new ExpressionInterpreter(parsedExpression, PLANNER_CONTEXT, TEST_SESSION, expressionTypes);
return interpreter.optimize(INPUTS);
}
use of io.trino.sql.planner.ExpressionInterpreter in project trino by trinodb.
the class TestSqlToRowExpressionTranslator method simplifyExpression.
private Expression simplifyExpression(Expression expression) {
// Testing simplified expressions is important, since simplification may create CASTs or function calls that cannot be simplified by the ExpressionOptimizer
Map<NodeRef<Expression>, Type> expressionTypes = getExpressionTypes(expression);
ExpressionInterpreter interpreter = new ExpressionInterpreter(expression, PLANNER_CONTEXT, TEST_SESSION, expressionTypes);
Object value = interpreter.optimize(NoOpSymbolResolver.INSTANCE);
return literalEncoder.toExpression(TEST_SESSION, value, expressionTypes.get(NodeRef.of(expression)));
}
use of io.trino.sql.planner.ExpressionInterpreter in project trino by trinodb.
the class FilterStatsCalculator method simplifyExpression.
private Expression simplifyExpression(Session session, Expression predicate, TypeProvider types) {
// TODO reuse io.trino.sql.planner.iterative.rule.SimplifyExpressions.rewrite
Map<NodeRef<Expression>, Type> expressionTypes = getExpressionTypes(plannerContext, session, predicate, types);
ExpressionInterpreter interpreter = new ExpressionInterpreter(predicate, plannerContext, session, expressionTypes);
Object value = interpreter.optimize(NoOpSymbolResolver.INSTANCE);
if (value == null) {
// Expression evaluates to SQL null, which in Filter is equivalent to false. This assumes the expression is a top-level expression (eg. not in NOT).
value = false;
}
return new LiteralEncoder(plannerContext).toExpression(session, value, BOOLEAN);
}
Aggregations