Search in sources :

Example 1 with ExpressionInterpreter

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

the class TestExpressionInterpreter method evaluate.

private static Object evaluate(Expression expression) {
    IdentityLinkedHashMap<Expression, Type> expressionTypes = getExpressionTypes(TEST_SESSION, METADATA, SQL_PARSER, SYMBOL_TYPES, expression, emptyList());
    ExpressionInterpreter interpreter = expressionInterpreter(expression, METADATA, TEST_SESSION, expressionTypes);
    return interpreter.evaluate((RecordCursor) null);
}
Also used : VarbinaryType(com.facebook.presto.spi.type.VarbinaryType) VarcharType.createVarcharType(com.facebook.presto.spi.type.VarcharType.createVarcharType) Type(com.facebook.presto.spi.type.Type) ExpressionFormatter.formatExpression(com.facebook.presto.sql.ExpressionFormatter.formatExpression) Expression(com.facebook.presto.sql.tree.Expression) ExpressionInterpreter(com.facebook.presto.sql.planner.ExpressionInterpreter)

Example 2 with ExpressionInterpreter

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

the class TestExpressionInterpreter method optimize.

private static Object optimize(@Language("SQL") String expression) {
    assertRoundTrip(expression);
    Expression parsedExpression = FunctionAssertions.createExpression(expression, METADATA, SYMBOL_TYPES);
    IdentityLinkedHashMap<Expression, Type> expressionTypes = getExpressionTypes(TEST_SESSION, METADATA, SQL_PARSER, SYMBOL_TYPES, parsedExpression, emptyList());
    ExpressionInterpreter interpreter = expressionOptimizer(parsedExpression, METADATA, TEST_SESSION, expressionTypes);
    return interpreter.optimize(symbol -> {
        switch(symbol.getName().toLowerCase(ENGLISH)) {
            case "bound_integer":
                return 1234L;
            case "bound_long":
                return 1234L;
            case "bound_string":
                return utf8Slice("hello");
            case "bound_double":
                return 12.34;
            case "bound_date":
                return new LocalDate(2001, 8, 22).toDateMidnight(DateTimeZone.UTC).getMillis();
            case "bound_time":
                return new LocalTime(3, 4, 5, 321).toDateTime(new DateTime(0, DateTimeZone.UTC)).getMillis();
            case "bound_timestamp":
                return new DateTime(2001, 8, 22, 3, 4, 5, 321, DateTimeZone.UTC).getMillis();
            case "bound_pattern":
                return utf8Slice("%el%");
            case "bound_timestamp_with_timezone":
                return new SqlTimestampWithTimeZone(new DateTime(1970, 1, 1, 1, 0, 0, 999, DateTimeZone.UTC).getMillis(), getTimeZoneKey("Z"));
            case "bound_varbinary":
                return Slices.wrappedBuffer((byte) 0xab);
        }
        return symbol.toSymbolReference();
    });
}
Also used : VarbinaryType(com.facebook.presto.spi.type.VarbinaryType) VarcharType.createVarcharType(com.facebook.presto.spi.type.VarcharType.createVarcharType) Type(com.facebook.presto.spi.type.Type) SqlTimestampWithTimeZone(com.facebook.presto.spi.type.SqlTimestampWithTimeZone) LocalTime(org.joda.time.LocalTime) ExpressionFormatter.formatExpression(com.facebook.presto.sql.ExpressionFormatter.formatExpression) Expression(com.facebook.presto.sql.tree.Expression) ExpressionInterpreter(com.facebook.presto.sql.planner.ExpressionInterpreter) LocalDate(org.joda.time.LocalDate) DateTime(org.joda.time.DateTime)

Aggregations

Type (com.facebook.presto.spi.type.Type)2 VarbinaryType (com.facebook.presto.spi.type.VarbinaryType)2 VarcharType.createVarcharType (com.facebook.presto.spi.type.VarcharType.createVarcharType)2 ExpressionFormatter.formatExpression (com.facebook.presto.sql.ExpressionFormatter.formatExpression)2 ExpressionInterpreter (com.facebook.presto.sql.planner.ExpressionInterpreter)2 Expression (com.facebook.presto.sql.tree.Expression)2 SqlTimestampWithTimeZone (com.facebook.presto.spi.type.SqlTimestampWithTimeZone)1 DateTime (org.joda.time.DateTime)1 LocalDate (org.joda.time.LocalDate)1 LocalTime (org.joda.time.LocalTime)1