Search in sources :

Example 41 with BytecodeNode

use of io.airlift.bytecode.BytecodeNode in project trino by trinodb.

the class JoinCompiler method generateIsSortChannelPositionNull.

private static void generateIsSortChannelPositionNull(ClassDefinition classDefinition, List<FieldDefinition> channelFields, Optional<Integer> sortChannel) {
    Parameter blockIndex = arg("blockIndex", int.class);
    Parameter blockPosition = arg("blockPosition", int.class);
    MethodDefinition isSortChannelPositionNullMethod = classDefinition.declareMethod(a(PUBLIC), "isSortChannelPositionNull", type(boolean.class), blockIndex, blockPosition);
    if (sortChannel.isEmpty()) {
        isSortChannelPositionNullMethod.getBody().append(newInstance(UnsupportedOperationException.class)).throwObject();
        return;
    }
    Variable thisVariable = isSortChannelPositionNullMethod.getThis();
    int index = sortChannel.get();
    BytecodeExpression block = thisVariable.getField(channelFields.get(index)).invoke("get", Object.class, blockIndex).cast(Block.class);
    BytecodeNode isNull = block.invoke("isNull", boolean.class, blockPosition).ret();
    isSortChannelPositionNullMethod.getBody().append(isNull);
}
Also used : Variable(io.airlift.bytecode.Variable) MethodDefinition(io.airlift.bytecode.MethodDefinition) Parameter(io.airlift.bytecode.Parameter) BytecodeNode(io.airlift.bytecode.BytecodeNode) BytecodeExpression(io.airlift.bytecode.expression.BytecodeExpression)

Example 42 with BytecodeNode

use of io.airlift.bytecode.BytecodeNode in project trino by trinodb.

the class CoalesceCodeGenerator method generateExpression.

@Override
public BytecodeNode generateExpression(BytecodeGeneratorContext generatorContext) {
    List<BytecodeNode> operands = new ArrayList<>();
    for (RowExpression expression : arguments) {
        operands.add(generatorContext.generate(expression));
    }
    Variable wasNull = generatorContext.wasNull();
    BytecodeNode nullValue = new BytecodeBlock().append(wasNull.set(constantTrue())).pushJavaDefault(returnType.getJavaType());
    // reverse list because current if statement builder doesn't support if/else so we need to build the if statements bottom up
    for (BytecodeNode operand : Lists.reverse(operands)) {
        IfStatement ifStatement = new IfStatement();
        ifStatement.condition().append(operand).append(wasNull);
        // if value was null, pop the null value, clear the null flag, and process the next operand
        ifStatement.ifTrue().pop(returnType.getJavaType()).append(wasNull.set(constantFalse())).append(nullValue);
        nullValue = ifStatement;
    }
    return nullValue;
}
Also used : IfStatement(io.airlift.bytecode.control.IfStatement) Variable(io.airlift.bytecode.Variable) ArrayList(java.util.ArrayList) BytecodeBlock(io.airlift.bytecode.BytecodeBlock) RowExpression(io.trino.sql.relational.RowExpression) BytecodeNode(io.airlift.bytecode.BytecodeNode)

Aggregations

BytecodeNode (io.airlift.bytecode.BytecodeNode)42 Variable (io.airlift.bytecode.Variable)37 BytecodeBlock (io.airlift.bytecode.BytecodeBlock)29 IfStatement (io.airlift.bytecode.control.IfStatement)26 MethodDefinition (io.airlift.bytecode.MethodDefinition)22 Parameter (io.airlift.bytecode.Parameter)20 Scope (io.airlift.bytecode.Scope)19 LabelNode (io.airlift.bytecode.instruction.LabelNode)15 ForLoop (io.airlift.bytecode.control.ForLoop)10 BytecodeExpression (io.airlift.bytecode.expression.BytecodeExpression)9 ClassDefinition (io.airlift.bytecode.ClassDefinition)8 VariableInstruction.incrementVariable (io.airlift.bytecode.instruction.VariableInstruction.incrementVariable)8 RowExpression (io.prestosql.spi.relation.RowExpression)6 ArrayList (java.util.ArrayList)6 ImmutableList (com.google.common.collect.ImmutableList)5 Block (io.prestosql.spi.block.Block)5 BuiltInScalarFunctionImplementation (io.prestosql.spi.function.BuiltInScalarFunctionImplementation)5 Block (io.trino.spi.block.Block)5 FunctionHandle (io.prestosql.spi.function.FunctionHandle)4 Signature.typeVariable (io.prestosql.spi.function.Signature.typeVariable)4