use of io.trino.sql.planner.ExpressionInterpreter in project trino by trinodb.
the class TestExpressionInterpreter method evaluate.
private static Object evaluate(Expression expression) {
Map<NodeRef<Expression>, Type> expressionTypes = getTypes(TEST_SESSION, PLANNER_CONTEXT, SYMBOL_TYPES, expression);
ExpressionInterpreter interpreter = new ExpressionInterpreter(expression, PLANNER_CONTEXT, TEST_SESSION, expressionTypes);
return interpreter.evaluate(INPUTS);
}
use of io.trino.sql.planner.ExpressionInterpreter in project trino by trinodb.
the class FunctionAssertions method interpret.
private Object interpret(Expression expression, Type expectedType, Session session) {
Map<NodeRef<Expression>, Type> expressionTypes = getTypes(session, getPlannerContext(), INPUT_TYPES, expression);
ExpressionInterpreter evaluator = new ExpressionInterpreter(expression, runner.getPlannerContext(), session, expressionTypes);
Object result = evaluator.evaluate(symbol -> {
int position = 0;
int channel = INPUT_MAPPING.get(symbol);
Type type = INPUT_TYPES.get(symbol);
Block block = SOURCE_PAGE.getBlock(channel);
if (block.isNull(position)) {
return null;
}
Class<?> javaType = type.getJavaType();
if (javaType == boolean.class) {
return type.getBoolean(block, position);
} else if (javaType == long.class) {
return type.getLong(block, position);
} else if (javaType == double.class) {
return type.getDouble(block, position);
} else if (javaType == Slice.class) {
return type.getSlice(block, position);
} else if (javaType == Block.class || javaType == Int128.class) {
return type.getObject(block, position);
} else {
throw new UnsupportedOperationException("not yet implemented");
}
});
// convert result from stack type to Type ObjectValue
Block block = Utils.nativeValueToBlock(expectedType, result);
return expectedType.getObjectValue(session.toConnectorSession(), block, 0);
}
Aggregations