Search in sources :

Example 1 with BytecodeExpression

use of io.airlift.bytecode.expression.BytecodeExpression in project hetu-core by openlookeng.

the class AccumulatorCompiler method anyParametersAreNull.

private static BytecodeExpression anyParametersAreNull(List<ParameterMetadata> parameterMetadatas, Variable index, Variable channels, Variable position) {
    int inputChannel = 0;
    BytecodeExpression isNull = constantFalse();
    for (ParameterMetadata parameterMetadata : parameterMetadatas) {
        switch(parameterMetadata.getParameterType()) {
            case BLOCK_INPUT_CHANNEL:
            case INPUT_CHANNEL:
                BytecodeExpression getChannel = channels.invoke("get", Object.class, constantInt(inputChannel)).cast(int.class);
                isNull = BytecodeExpressions.or(isNull, index.invoke("isNull", boolean.class, getChannel, position));
                inputChannel++;
                break;
            case NULLABLE_BLOCK_INPUT_CHANNEL:
                inputChannel++;
                break;
        }
    }
    return isNull;
}
Also used : BytecodeExpression(io.airlift.bytecode.expression.BytecodeExpression) ParameterMetadata(io.prestosql.operator.aggregation.AggregationMetadata.ParameterMetadata)

Example 2 with BytecodeExpression

use of io.airlift.bytecode.expression.BytecodeExpression in project hetu-core by openlookeng.

the class AccumulatorCompiler method generateEnsureCapacity.

private static void generateEnsureCapacity(Scope scope, List<FieldDefinition> stateFields, BytecodeBlock block) {
    Variable groupIdsBlock = scope.getVariable("groupIdsBlock");
    for (FieldDefinition stateField : stateFields) {
        BytecodeExpression state = scope.getThis().getField(stateField);
        block.append(state.invoke("ensureCapacity", void.class, groupIdsBlock.invoke("getGroupCount", long.class)));
    }
}
Also used : Variable(io.airlift.bytecode.Variable) FieldDefinition(io.airlift.bytecode.FieldDefinition) BytecodeExpression(io.airlift.bytecode.expression.BytecodeExpression)

Example 3 with BytecodeExpression

use of io.airlift.bytecode.expression.BytecodeExpression in project hetu-core by openlookeng.

the class AccumulatorCompiler method generateGroupedEvaluateIntermediate.

private static void generateGroupedEvaluateIntermediate(ClassDefinition definition, List<StateFieldAndDescriptor> stateFieldAndDescriptors) {
    Parameter groupId = arg("groupId", int.class);
    Parameter out = arg("out", BlockBuilder.class);
    MethodDefinition method = definition.declareMethod(a(PUBLIC), "evaluateIntermediate", type(void.class), groupId, out);
    Variable thisVariable = method.getThis();
    BytecodeBlock body = method.getBody();
    if (stateFieldAndDescriptors.size() == 1) {
        BytecodeExpression stateSerializer = thisVariable.getField(getOnlyElement(stateFieldAndDescriptors).getStateSerializerField());
        BytecodeExpression state = thisVariable.getField(getOnlyElement(stateFieldAndDescriptors).getStateField());
        body.append(state.invoke("setGroupId", void.class, groupId.cast(long.class))).append(stateSerializer.invoke("serialize", void.class, state.cast(Object.class), out)).ret();
    } else {
        Variable rowBuilder = method.getScope().declareVariable(BlockBuilder.class, "rowBuilder");
        body.append(rowBuilder.set(out.invoke("beginBlockEntry", BlockBuilder.class)));
        for (int i = 0; i < stateFieldAndDescriptors.size(); i++) {
            BytecodeExpression stateSerializer = thisVariable.getField(stateFieldAndDescriptors.get(i).getStateSerializerField());
            BytecodeExpression state = thisVariable.getField(stateFieldAndDescriptors.get(i).getStateField());
            body.append(state.invoke("setGroupId", void.class, groupId.cast(long.class))).append(stateSerializer.invoke("serialize", void.class, state.cast(Object.class), rowBuilder));
        }
        body.append(out.invoke("closeEntry", BlockBuilder.class).pop()).ret();
    }
}
Also used : Variable(io.airlift.bytecode.Variable) MethodDefinition(io.airlift.bytecode.MethodDefinition) BytecodeBlock(io.airlift.bytecode.BytecodeBlock) Parameter(io.airlift.bytecode.Parameter) BytecodeExpression(io.airlift.bytecode.expression.BytecodeExpression) BlockBuilder(io.prestosql.spi.block.BlockBuilder)

Example 4 with BytecodeExpression

use of io.airlift.bytecode.expression.BytecodeExpression in project hetu-core by openlookeng.

the class OrderingCompiler method generateMergeSortCompareTo.

private void generateMergeSortCompareTo(ClassDefinition classDefinition, CallSiteBinder callSiteBinder, List<Type> types, List<Integer> sortChannels, List<SortOrder> sortOrders) {
    Parameter leftPage = arg("leftPage", Page.class);
    Parameter leftPosition = arg("leftPosition", int.class);
    Parameter rightPage = arg("rightPage", Page.class);
    Parameter rightPosition = arg("rightPosition", int.class);
    MethodDefinition compareToMethod = classDefinition.declareMethod(a(PUBLIC), "compareTo", type(int.class), leftPage, leftPosition, rightPage, rightPosition);
    for (int i = 0; i < sortChannels.size(); i++) {
        int sortChannel = sortChannels.get(i);
        SortOrder sortOrder = sortOrders.get(i);
        BytecodeBlock block = new BytecodeBlock().setDescription("compare channel " + sortChannel + " " + sortOrder);
        Type sortType = types.get(sortChannel);
        BytecodeExpression leftBlock = leftPage.invoke("getBlock", Block.class, constantInt(sortChannel));
        BytecodeExpression rightBlock = rightPage.invoke("getBlock", Block.class, constantInt(sortChannel));
        block.append(getStatic(SortOrder.class, sortOrder.name()).invoke("compareBlockValue", int.class, ImmutableList.of(Type.class, Block.class, int.class, Block.class, int.class), constantType(callSiteBinder, sortType), leftBlock, leftPosition, rightBlock, rightPosition));
        LabelNode equal = new LabelNode("equal");
        block.comment("if (compare != 0) return compare").dup().ifZeroGoto(equal).retInt().visitLabel(equal).pop(int.class);
        compareToMethod.getBody().append(block);
    }
    // values are equal
    compareToMethod.getBody().push(0).retInt();
}
Also used : LabelNode(io.airlift.bytecode.instruction.LabelNode) SqlTypeBytecodeExpression.constantType(io.prestosql.sql.gen.SqlTypeBytecodeExpression.constantType) Type(io.prestosql.spi.type.Type) MethodDefinition(io.airlift.bytecode.MethodDefinition) BytecodeBlock(io.airlift.bytecode.BytecodeBlock) Parameter(io.airlift.bytecode.Parameter) SortOrder(io.prestosql.spi.block.SortOrder) BytecodeExpression(io.airlift.bytecode.expression.BytecodeExpression)

Example 5 with BytecodeExpression

use of io.airlift.bytecode.expression.BytecodeExpression in project hetu-core by openlookeng.

the class OrderingCompiler method generatePageIndexCompareTo.

private static void generatePageIndexCompareTo(ClassDefinition classDefinition, CallSiteBinder callSiteBinder, List<Type> sortTypes, List<Integer> sortChannels, List<SortOrder> sortOrders) {
    Parameter pagesIndex = arg("pagesIndex", PagesIndex.class);
    Parameter leftPosition = arg("leftPosition", int.class);
    Parameter rightPosition = arg("rightPosition", int.class);
    MethodDefinition compareToMethod = classDefinition.declareMethod(a(PUBLIC), "compareTo", type(int.class), pagesIndex, leftPosition, rightPosition);
    Scope scope = compareToMethod.getScope();
    Variable valueAddresses = scope.declareVariable(LongArrayList.class, "valueAddresses");
    compareToMethod.getBody().comment("LongArrayList valueAddresses = pagesIndex.valueAddresses").append(valueAddresses.set(pagesIndex.invoke("getValueAddresses", LongArrayList.class)));
    Variable leftPageAddress = scope.declareVariable(long.class, "leftPageAddress");
    compareToMethod.getBody().comment("long leftPageAddress = valueAddresses.getLong(leftPosition)").append(leftPageAddress.set(valueAddresses.invoke("getLong", long.class, leftPosition)));
    Variable leftBlockIndex = scope.declareVariable(int.class, "leftBlockIndex");
    compareToMethod.getBody().comment("int leftBlockIndex = decodeSliceIndex(leftPageAddress)").append(leftBlockIndex.set(invokeStatic(SyntheticAddress.class, "decodeSliceIndex", int.class, leftPageAddress)));
    Variable leftBlockPosition = scope.declareVariable(int.class, "leftBlockPosition");
    compareToMethod.getBody().comment("int leftBlockPosition = decodePosition(leftPageAddress)").append(leftBlockPosition.set(invokeStatic(SyntheticAddress.class, "decodePosition", int.class, leftPageAddress)));
    Variable rightPageAddress = scope.declareVariable(long.class, "rightPageAddress");
    compareToMethod.getBody().comment("long rightPageAddress = valueAddresses.getLong(rightPosition);").append(rightPageAddress.set(valueAddresses.invoke("getLong", long.class, rightPosition)));
    Variable rightBlockIndex = scope.declareVariable(int.class, "rightBlockIndex");
    compareToMethod.getBody().comment("int rightBlockIndex = decodeSliceIndex(rightPageAddress)").append(rightBlockIndex.set(invokeStatic(SyntheticAddress.class, "decodeSliceIndex", int.class, rightPageAddress)));
    Variable rightBlockPosition = scope.declareVariable(int.class, "rightBlockPosition");
    compareToMethod.getBody().comment("int rightBlockPosition = decodePosition(rightPageAddress)").append(rightBlockPosition.set(invokeStatic(SyntheticAddress.class, "decodePosition", int.class, rightPageAddress)));
    for (int i = 0; i < sortChannels.size(); i++) {
        int sortChannel = sortChannels.get(i);
        SortOrder sortOrder = sortOrders.get(i);
        BytecodeBlock block = new BytecodeBlock().setDescription("compare channel " + sortChannel + " " + sortOrder);
        Type sortType = sortTypes.get(i);
        BytecodeExpression leftBlock = pagesIndex.invoke("getChannel", ObjectArrayList.class, constantInt(sortChannel)).invoke("get", Object.class, leftBlockIndex).cast(Block.class);
        BytecodeExpression rightBlock = pagesIndex.invoke("getChannel", ObjectArrayList.class, constantInt(sortChannel)).invoke("get", Object.class, rightBlockIndex).cast(Block.class);
        block.append(getStatic(SortOrder.class, sortOrder.name()).invoke("compareBlockValue", int.class, ImmutableList.of(Type.class, Block.class, int.class, Block.class, int.class), constantType(callSiteBinder, sortType), leftBlock, leftBlockPosition, rightBlock, rightBlockPosition));
        LabelNode equal = new LabelNode("equal");
        block.comment("if (compare != 0) return compare").dup().ifZeroGoto(equal).retInt().visitLabel(equal).pop(int.class);
        compareToMethod.getBody().append(block);
    }
    // values are equal
    compareToMethod.getBody().push(0).retInt();
}
Also used : LabelNode(io.airlift.bytecode.instruction.LabelNode) SqlTypeBytecodeExpression.constantType(io.prestosql.sql.gen.SqlTypeBytecodeExpression.constantType) Type(io.prestosql.spi.type.Type) Variable(io.airlift.bytecode.Variable) Scope(io.airlift.bytecode.Scope) MethodDefinition(io.airlift.bytecode.MethodDefinition) BytecodeBlock(io.airlift.bytecode.BytecodeBlock) Parameter(io.airlift.bytecode.Parameter) SortOrder(io.prestosql.spi.block.SortOrder) BytecodeExpression(io.airlift.bytecode.expression.BytecodeExpression)

Aggregations

BytecodeExpression (io.airlift.bytecode.expression.BytecodeExpression)66 MethodDefinition (io.airlift.bytecode.MethodDefinition)51 Parameter (io.airlift.bytecode.Parameter)49 Variable (io.airlift.bytecode.Variable)49 BytecodeBlock (io.airlift.bytecode.BytecodeBlock)38 IfStatement (io.airlift.bytecode.control.IfStatement)20 LabelNode (io.airlift.bytecode.instruction.LabelNode)17 FieldDefinition (io.airlift.bytecode.FieldDefinition)14 Type (io.trino.spi.type.Type)14 Scope (io.airlift.bytecode.Scope)13 ArrayList (java.util.ArrayList)13 ImmutableList (com.google.common.collect.ImmutableList)11 SqlTypeBytecodeExpression.constantType (io.trino.sql.gen.SqlTypeBytecodeExpression.constantType)11 BigintType (io.trino.spi.type.BigintType)10 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)9 BytecodeNode (io.airlift.bytecode.BytecodeNode)9 ClassDefinition (io.airlift.bytecode.ClassDefinition)8 MethodHandle (java.lang.invoke.MethodHandle)8 Type (io.prestosql.spi.type.Type)7 SqlTypeBytecodeExpression.constantType (io.prestosql.sql.gen.SqlTypeBytecodeExpression.constantType)7