use of io.prestosql.sql.tree.NodeRef in project hetu-core by openlookeng.
the class TestingRowExpressionTranslator method simplifyExpression.
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, TypeProvider.empty());
ExpressionInterpreter interpreter = ExpressionInterpreter.expressionOptimizer(expression, metadata, TEST_SESSION, expressionTypes);
Object value = interpreter.optimize(NoOpSymbolResolver.INSTANCE);
return literalEncoder.toExpression(value, expressionTypes.get(NodeRef.of(expression)));
}
use of io.prestosql.sql.tree.NodeRef in project hetu-core by openlookeng.
the class TestExpressionInterpreter method optimize.
private static Object optimize(@Language("SQL") String expression) {
assertRoundTrip(expression);
Expression parsedExpression = FunctionAssertions.createExpression(expression, METADATA, SYMBOL_TYPES);
Map<NodeRef<Expression>, Type> expressionTypes = TYPE_ANALYZER.getTypes(TEST_SESSION, SYMBOL_TYPES, parsedExpression);
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(UTC).getMillis();
case "bound_time":
return new LocalTime(3, 4, 5, 321).toDateTime(new DateTime(0, UTC)).getMillis();
case "bound_timestamp":
return new DateTime(2001, 8, 22, 3, 4, 5, 321, 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, UTC).getMillis(), getTimeZoneKey("Z"));
case "bound_varbinary":
return Slices.wrappedBuffer((byte) 0xab);
case "bound_decimal_short":
return 12345L;
case "bound_decimal_long":
return Decimals.encodeUnscaledValue(new BigInteger("12345678901234567890123"));
default:
break;
}
return toSymbolReference(symbol);
});
}
use of io.prestosql.sql.tree.NodeRef in project hetu-core by openlookeng.
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 = ExpressionInterpreter.expressionOptimizer(expression, metadata, TEST_SESSION, expressionTypes);
Object value = interpreter.optimize(NoOpSymbolResolver.INSTANCE);
return literalEncoder.toExpression(value, expressionTypes.get(NodeRef.of(expression)));
}
use of io.prestosql.sql.tree.NodeRef in project hetu-core by openlookeng.
the class TestExpressionInterpreter method evaluate.
private static Object evaluate(Expression expression) {
Map<NodeRef<Expression>, Type> expressionTypes = TYPE_ANALYZER.getTypes(TEST_SESSION, SYMBOL_TYPES, expression);
ExpressionInterpreter interpreter = expressionInterpreter(expression, METADATA, TEST_SESSION, expressionTypes);
return interpreter.evaluate();
}
use of io.prestosql.sql.tree.NodeRef in project hetu-core by openlookeng.
the class PlanBuilder method rowExpression.
public RowExpression rowExpression(String sql) {
Expression expression = expression(sql);
Map<NodeRef<Expression>, Type> expressionTypes = ExpressionAnalyzer.analyzeExpressions(TEST_SESSION, metadata, new SqlParser(), getTypes(), ImmutableList.of(expression), ImmutableList.of(), WarningCollector.NOOP, false).getExpressionTypes();
return SqlToRowExpressionTranslator.translate(expression, SCALAR, expressionTypes, ImmutableMap.of(), metadata.getFunctionAndTypeManager(), TEST_SESSION, false);
}
Aggregations