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);
}
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();
});
}
Aggregations