Search in sources :

Example 1 with RowExpressionInterpreter

use of com.facebook.presto.sql.planner.RowExpressionInterpreter in project presto by prestodb.

the class TestExpressionInterpreter method optimize.

private static Object optimize(RowExpression expression, Level level) {
    return new RowExpressionInterpreter(expression, METADATA, TEST_SESSION.toConnectorSession(), level).optimize(variable -> {
        Symbol symbol = new Symbol(variable.getName());
        Object value = symbolConstant(symbol);
        if (value == null) {
            return new VariableReferenceExpression(Optional.empty(), symbol.getName(), SYMBOL_TYPES.get(symbol.toSymbolReference()));
        }
        return value;
    });
}
Also used : Symbol(com.facebook.presto.sql.planner.Symbol) VariableReferenceExpression(com.facebook.presto.spi.relation.VariableReferenceExpression) RowExpressionInterpreter(com.facebook.presto.sql.planner.RowExpressionInterpreter)

Example 2 with RowExpressionInterpreter

use of com.facebook.presto.sql.planner.RowExpressionInterpreter in project presto by prestodb.

the class FilterStatsCalculator method simplifyExpression.

private RowExpression simplifyExpression(ConnectorSession session, RowExpression predicate) {
    RowExpressionInterpreter interpreter = new RowExpressionInterpreter(predicate, metadata, session, OPTIMIZED);
    Object value = interpreter.optimize();
    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 LiteralEncoder.toRowExpression(predicate.getSourceLocation(), value, BOOLEAN);
}
Also used : RowExpressionInterpreter(com.facebook.presto.sql.planner.RowExpressionInterpreter)

Aggregations

RowExpressionInterpreter (com.facebook.presto.sql.planner.RowExpressionInterpreter)2 VariableReferenceExpression (com.facebook.presto.spi.relation.VariableReferenceExpression)1 Symbol (com.facebook.presto.sql.planner.Symbol)1