Search in sources :

Example 6 with ExpressionInterpreter

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);
}
Also used : NodeRef(io.trino.sql.tree.NodeRef) CharType.createCharType(io.trino.spi.type.CharType.createCharType) Type(io.trino.spi.type.Type) DecimalType.createDecimalType(io.trino.spi.type.DecimalType.createDecimalType) VarbinaryType(io.trino.spi.type.VarbinaryType) VarcharType.createVarcharType(io.trino.spi.type.VarcharType.createVarcharType) ExpressionInterpreter(io.trino.sql.planner.ExpressionInterpreter)

Example 7 with ExpressionInterpreter

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);
}
Also used : NodeRef(io.trino.sql.tree.NodeRef) DecimalType.createDecimalType(io.trino.spi.type.DecimalType.createDecimalType) RowType(io.trino.spi.type.RowType) DecimalType(io.trino.spi.type.DecimalType) Type(io.trino.spi.type.Type) Slice(io.airlift.slice.Slice) ExpressionInterpreter(io.trino.sql.planner.ExpressionInterpreter) BlockAssertions.createShortDecimalsBlock(io.trino.block.BlockAssertions.createShortDecimalsBlock) BlockAssertions.createDoublesBlock(io.trino.block.BlockAssertions.createDoublesBlock) BlockAssertions.createIntsBlock(io.trino.block.BlockAssertions.createIntsBlock) BlockAssertions.createRowBlock(io.trino.block.BlockAssertions.createRowBlock) BlockAssertions.createStringsBlock(io.trino.block.BlockAssertions.createStringsBlock) BlockAssertions.createSlicesBlock(io.trino.block.BlockAssertions.createSlicesBlock) BlockAssertions.createTimestampsWithTimeZoneMillisBlock(io.trino.block.BlockAssertions.createTimestampsWithTimeZoneMillisBlock) Block(io.trino.spi.block.Block) BlockAssertions.createLongDecimalsBlock(io.trino.block.BlockAssertions.createLongDecimalsBlock) BlockAssertions.createLongsBlock(io.trino.block.BlockAssertions.createLongsBlock) BlockAssertions.createBooleansBlock(io.trino.block.BlockAssertions.createBooleansBlock) Int128(io.trino.spi.type.Int128)

Aggregations

Type (io.trino.spi.type.Type)7 ExpressionInterpreter (io.trino.sql.planner.ExpressionInterpreter)7 NodeRef (io.trino.sql.tree.NodeRef)7 DecimalType.createDecimalType (io.trino.spi.type.DecimalType.createDecimalType)4 CharType.createCharType (io.trino.spi.type.CharType.createCharType)2 VarbinaryType (io.trino.spi.type.VarbinaryType)2 VarcharType.createVarcharType (io.trino.spi.type.VarcharType.createVarcharType)2 LiteralEncoder (io.trino.sql.planner.LiteralEncoder)2 Slice (io.airlift.slice.Slice)1 BlockAssertions.createBooleansBlock (io.trino.block.BlockAssertions.createBooleansBlock)1 BlockAssertions.createDoublesBlock (io.trino.block.BlockAssertions.createDoublesBlock)1 BlockAssertions.createIntsBlock (io.trino.block.BlockAssertions.createIntsBlock)1 BlockAssertions.createLongDecimalsBlock (io.trino.block.BlockAssertions.createLongDecimalsBlock)1 BlockAssertions.createLongsBlock (io.trino.block.BlockAssertions.createLongsBlock)1 BlockAssertions.createRowBlock (io.trino.block.BlockAssertions.createRowBlock)1 BlockAssertions.createShortDecimalsBlock (io.trino.block.BlockAssertions.createShortDecimalsBlock)1 BlockAssertions.createSlicesBlock (io.trino.block.BlockAssertions.createSlicesBlock)1 BlockAssertions.createStringsBlock (io.trino.block.BlockAssertions.createStringsBlock)1 BlockAssertions.createTimestampsWithTimeZoneMillisBlock (io.trino.block.BlockAssertions.createTimestampsWithTimeZoneMillisBlock)1 Block (io.trino.spi.block.Block)1