Search in sources :

Example 56 with MethodDefinition

use of com.facebook.presto.bytecode.MethodDefinition in project presto by prestodb.

the class JoinProbeCompiler method generateGetCurrentJoinPosition.

private static void generateGetCurrentJoinPosition(ClassDefinition classDefinition, CallSiteBinder callSiteBinder, FieldDefinition lookupSourceField, FieldDefinition probePageField, FieldDefinition pageField, Optional<Integer> probeHashChannel, FieldDefinition probeHashBlockField, FieldDefinition positionField) {
    MethodDefinition method = classDefinition.declareMethod(a(PUBLIC), "getCurrentJoinPosition", type(long.class));
    Variable thisVariable = method.getThis();
    BytecodeBlock body = method.getBody().append(new IfStatement().condition(thisVariable.invoke("currentRowContainsNull", boolean.class)).ifTrue(constantLong(-1).ret()));
    BytecodeExpression position = thisVariable.getField(positionField);
    BytecodeExpression hashChannelsPage = thisVariable.getField(probePageField);
    BytecodeExpression allChannelsPage = thisVariable.getField(pageField);
    BytecodeExpression probeHashBlock = thisVariable.getField(probeHashBlockField);
    if (probeHashChannel.isPresent()) {
        body.append(thisVariable.getField(lookupSourceField).invoke("getJoinPosition", long.class, position, hashChannelsPage, allChannelsPage, constantType(callSiteBinder, BigintType.BIGINT).invoke("getLong", long.class, probeHashBlock, position))).retLong();
    } else {
        body.append(thisVariable.getField(lookupSourceField).invoke("getJoinPosition", long.class, position, hashChannelsPage, allChannelsPage)).retLong();
    }
}
Also used : IfStatement(com.facebook.presto.bytecode.control.IfStatement) Variable(com.facebook.presto.bytecode.Variable) MethodDefinition(com.facebook.presto.bytecode.MethodDefinition) BytecodeBlock(com.facebook.presto.bytecode.BytecodeBlock) BytecodeExpression(com.facebook.presto.bytecode.expression.BytecodeExpression)

Example 57 with MethodDefinition

use of com.facebook.presto.bytecode.MethodDefinition in project presto by prestodb.

the class JoinProbeCompiler method internalCompileJoinOperatorFactory.

@VisibleForTesting
public HashJoinOperatorFactoryFactory internalCompileJoinOperatorFactory(List<Type> types, List<Integer> probeOutputChannels, List<Integer> probeJoinChannel, Optional<Integer> probeHashChannel) {
    Class<? extends JoinProbe> joinProbeClass = compileJoinProbe(types, probeOutputChannels, probeJoinChannel, probeHashChannel);
    ClassDefinition classDefinition = new ClassDefinition(a(PUBLIC, FINAL), makeClassName("JoinProbeFactory"), type(Object.class), type(JoinProbeFactory.class));
    classDefinition.declareDefaultConstructor(a(PUBLIC));
    Parameter lookupSource = arg("lookupSource", LookupSource.class);
    Parameter page = arg("page", Page.class);
    MethodDefinition method = classDefinition.declareMethod(a(PUBLIC), "createJoinProbe", type(JoinProbe.class), lookupSource, page);
    method.getBody().newObject(joinProbeClass).dup().append(lookupSource).append(page).invokeConstructor(joinProbeClass, LookupSource.class, Page.class).retObject();
    DynamicClassLoader classLoader = new DynamicClassLoader(joinProbeClass.getClassLoader());
    JoinProbeFactory joinProbeFactory;
    if (probeJoinChannel.isEmpty()) {
        // see comment in PagesIndex#createLookupSource
        joinProbeFactory = new SimpleJoinProbe.SimpleJoinProbeFactory(types, probeOutputChannels, probeJoinChannel, probeHashChannel);
    } else {
        Class<? extends JoinProbeFactory> joinProbeFactoryClass = defineClass(classDefinition, JoinProbeFactory.class, classLoader);
        try {
            joinProbeFactory = joinProbeFactoryClass.newInstance();
        } catch (Exception e) {
            throw Throwables.propagate(e);
        }
    }
    Class<? extends OperatorFactory> operatorFactoryClass = IsolatedClass.isolateClass(classLoader, OperatorFactory.class, LookupJoinOperatorFactory.class, LookupJoinOperator.class);
    return new HashJoinOperatorFactoryFactory(joinProbeFactory, operatorFactoryClass);
}
Also used : DynamicClassLoader(com.facebook.presto.bytecode.DynamicClassLoader) LookupSource(com.facebook.presto.operator.LookupSource) SimpleJoinProbe(com.facebook.presto.operator.SimpleJoinProbe) Page(com.facebook.presto.spi.Page) ClassDefinition(com.facebook.presto.bytecode.ClassDefinition) JoinProbe(com.facebook.presto.operator.JoinProbe) SimpleJoinProbe(com.facebook.presto.operator.SimpleJoinProbe) UncheckedExecutionException(com.google.common.util.concurrent.UncheckedExecutionException) ExecutionException(java.util.concurrent.ExecutionException) JoinProbeFactory(com.facebook.presto.operator.JoinProbeFactory) MethodDefinition(com.facebook.presto.bytecode.MethodDefinition) Parameter(com.facebook.presto.bytecode.Parameter) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 58 with MethodDefinition

use of com.facebook.presto.bytecode.MethodDefinition in project presto by prestodb.

the class JoinProbeCompiler method generateGetPage.

private static void generateGetPage(ClassDefinition classDefinition, FieldDefinition pageField) {
    // dummy implementation for now
    // compiled class is used only in usecase case when result of this method is ignored.
    MethodDefinition method = classDefinition.declareMethod(a(PUBLIC), "getPage", type(Page.class));
    Variable thisVariable = method.getThis();
    method.getBody().append(thisVariable.getField(pageField)).ret(Page.class);
}
Also used : Variable(com.facebook.presto.bytecode.Variable) MethodDefinition(com.facebook.presto.bytecode.MethodDefinition) Page(com.facebook.presto.spi.Page)

Example 59 with MethodDefinition

use of com.facebook.presto.bytecode.MethodDefinition in project presto by prestodb.

the class JoinCompiler method generateRowEqualsRowMethod.

private static void generateRowEqualsRowMethod(ClassDefinition classDefinition, CallSiteBinder callSiteBinder, List<Type> joinChannelTypes) {
    Parameter leftPosition = arg("leftPosition", int.class);
    Parameter leftPage = arg("leftPage", Page.class);
    Parameter rightPosition = arg("rightPosition", int.class);
    Parameter rightPage = arg("rightPage", Page.class);
    MethodDefinition rowEqualsRowMethod = classDefinition.declareMethod(a(PUBLIC), "rowEqualsRow", type(boolean.class), leftPosition, leftPage, rightPosition, rightPage);
    for (int index = 0; index < joinChannelTypes.size(); index++) {
        BytecodeExpression type = constantType(callSiteBinder, joinChannelTypes.get(index));
        BytecodeExpression leftBlock = leftPage.invoke("getBlock", Block.class, constantInt(index));
        BytecodeExpression rightBlock = rightPage.invoke("getBlock", Block.class, constantInt(index));
        LabelNode checkNextField = new LabelNode("checkNextField");
        rowEqualsRowMethod.getBody().append(typeEquals(type, leftBlock, leftPosition, rightBlock, rightPosition)).ifTrueGoto(checkNextField).push(false).retBoolean().visitLabel(checkNextField);
    }
    rowEqualsRowMethod.getBody().push(true).retInt();
}
Also used : LabelNode(com.facebook.presto.bytecode.instruction.LabelNode) MethodDefinition(com.facebook.presto.bytecode.MethodDefinition) Parameter(com.facebook.presto.bytecode.Parameter) BytecodeExpression(com.facebook.presto.bytecode.expression.BytecodeExpression)

Example 60 with MethodDefinition

use of com.facebook.presto.bytecode.MethodDefinition in project presto by prestodb.

the class JoinCompiler method generatePositionEqualsRowMethod.

private static void generatePositionEqualsRowMethod(ClassDefinition classDefinition, CallSiteBinder callSiteBinder, List<Type> joinChannelTypes, List<FieldDefinition> joinChannelFields, boolean ignoreNulls) {
    Parameter leftBlockIndex = arg("leftBlockIndex", int.class);
    Parameter leftBlockPosition = arg("leftBlockPosition", int.class);
    Parameter rightPosition = arg("rightPosition", int.class);
    Parameter rightPage = arg("rightPage", Page.class);
    MethodDefinition positionEqualsRowMethod = classDefinition.declareMethod(a(PUBLIC), ignoreNulls ? "positionEqualsRowIgnoreNulls" : "positionEqualsRow", type(boolean.class), leftBlockIndex, leftBlockPosition, rightPosition, rightPage);
    Variable thisVariable = positionEqualsRowMethod.getThis();
    for (int index = 0; index < joinChannelTypes.size(); index++) {
        BytecodeExpression type = constantType(callSiteBinder, joinChannelTypes.get(index));
        BytecodeExpression leftBlock = thisVariable.getField(joinChannelFields.get(index)).invoke("get", Object.class, leftBlockIndex).cast(Block.class);
        BytecodeExpression rightBlock = rightPage.invoke("getBlock", Block.class, constantInt(index));
        BytecodeNode equalityCondition;
        if (ignoreNulls) {
            equalityCondition = typeEqualsIgnoreNulls(type, leftBlock, leftBlockPosition, rightBlock, rightPosition);
        } else {
            equalityCondition = typeEquals(type, leftBlock, leftBlockPosition, rightBlock, rightPosition);
        }
        LabelNode checkNextField = new LabelNode("checkNextField");
        positionEqualsRowMethod.getBody().append(equalityCondition).ifTrueGoto(checkNextField).push(false).retBoolean().visitLabel(checkNextField);
    }
    positionEqualsRowMethod.getBody().push(true).retInt();
}
Also used : LabelNode(com.facebook.presto.bytecode.instruction.LabelNode) Variable(com.facebook.presto.bytecode.Variable) MethodDefinition(com.facebook.presto.bytecode.MethodDefinition) Parameter(com.facebook.presto.bytecode.Parameter) BytecodeNode(com.facebook.presto.bytecode.BytecodeNode) BytecodeExpression(com.facebook.presto.bytecode.expression.BytecodeExpression)

Aggregations

MethodDefinition (com.facebook.presto.bytecode.MethodDefinition)74 Parameter (com.facebook.presto.bytecode.Parameter)56 Variable (com.facebook.presto.bytecode.Variable)54 BytecodeBlock (com.facebook.presto.bytecode.BytecodeBlock)45 Scope (com.facebook.presto.bytecode.Scope)30 IfStatement (com.facebook.presto.bytecode.control.IfStatement)27 BytecodeExpression (com.facebook.presto.bytecode.expression.BytecodeExpression)24 Block (com.facebook.presto.spi.block.Block)20 ImmutableList (com.google.common.collect.ImmutableList)16 ClassDefinition (com.facebook.presto.bytecode.ClassDefinition)14 FieldDefinition (com.facebook.presto.bytecode.FieldDefinition)11 BytecodeNode (com.facebook.presto.bytecode.BytecodeNode)10 Type (com.facebook.presto.spi.type.Type)10 ForLoop (com.facebook.presto.bytecode.control.ForLoop)9 LabelNode (com.facebook.presto.bytecode.instruction.LabelNode)9 BlockBuilder (com.facebook.presto.spi.block.BlockBuilder)9 DictionaryBlock (com.facebook.presto.spi.block.DictionaryBlock)9 LazyBlock (com.facebook.presto.spi.block.LazyBlock)9 RunLengthEncodedBlock (com.facebook.presto.spi.block.RunLengthEncodedBlock)9 List (java.util.List)9