Search in sources :

Example 11 with FieldDefinition

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

the class JoinFilterFunctionCompiler method generateMethods.

private void generateMethods(ClassDefinition classDefinition, CallSiteBinder callSiteBinder, RowExpression filter, int leftBlocksSize) {
    CachedInstanceBinder cachedInstanceBinder = new CachedInstanceBinder(classDefinition, callSiteBinder);
    FieldDefinition sessionField = classDefinition.declareField(a(PRIVATE, FINAL), "session", ConnectorSession.class);
    generateFilterMethod(classDefinition, callSiteBinder, cachedInstanceBinder, filter, leftBlocksSize, sessionField);
    generateConstructor(classDefinition, sessionField, cachedInstanceBinder);
}
Also used : FieldDefinition(com.facebook.presto.bytecode.FieldDefinition)

Example 12 with FieldDefinition

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

the class JoinProbeCompiler method compileJoinProbe.

private Class<? extends JoinProbe> compileJoinProbe(List<Type> types, List<Integer> probeOutputChannels, List<Integer> probeChannels, Optional<Integer> probeHashChannel) {
    CallSiteBinder callSiteBinder = new CallSiteBinder();
    ClassDefinition classDefinition = new ClassDefinition(a(PUBLIC, FINAL), makeClassName("JoinProbe"), type(Object.class), type(JoinProbe.class));
    // declare fields
    FieldDefinition lookupSourceField = classDefinition.declareField(a(PRIVATE, FINAL), "lookupSource", LookupSource.class);
    FieldDefinition positionCountField = classDefinition.declareField(a(PRIVATE, FINAL), "positionCount", int.class);
    List<FieldDefinition> blockFields = new ArrayList<>();
    for (int i = 0; i < types.size(); i++) {
        FieldDefinition channelField = classDefinition.declareField(a(PRIVATE, FINAL), "block_" + i, Block.class);
        blockFields.add(channelField);
    }
    List<FieldDefinition> probeBlockFields = new ArrayList<>();
    for (int i = 0; i < probeChannels.size(); i++) {
        FieldDefinition channelField = classDefinition.declareField(a(PRIVATE, FINAL), "probeBlock_" + i, Block.class);
        probeBlockFields.add(channelField);
    }
    FieldDefinition probeBlocksArrayField = classDefinition.declareField(a(PRIVATE, FINAL), "probeBlocks", Block[].class);
    FieldDefinition probePageField = classDefinition.declareField(a(PRIVATE, FINAL), "probePage", Page.class);
    FieldDefinition pageField = classDefinition.declareField(a(PRIVATE, FINAL), "page", Page.class);
    FieldDefinition positionField = classDefinition.declareField(a(PRIVATE), "position", int.class);
    FieldDefinition probeHashBlockField = classDefinition.declareField(a(PRIVATE, FINAL), "probeHashBlock", Block.class);
    generateConstructor(classDefinition, probeChannels, probeHashChannel, lookupSourceField, blockFields, probeBlockFields, probeBlocksArrayField, probePageField, pageField, probeHashBlockField, positionField, positionCountField);
    generateGetChannelCountMethod(classDefinition, probeOutputChannels.size());
    generateAppendToMethod(classDefinition, callSiteBinder, types, probeOutputChannels, blockFields, positionField);
    generateAdvanceNextPosition(classDefinition, positionField, positionCountField);
    generateGetCurrentJoinPosition(classDefinition, callSiteBinder, lookupSourceField, probePageField, pageField, probeHashChannel, probeHashBlockField, positionField);
    generateCurrentRowContainsNull(classDefinition, probeBlockFields, positionField);
    generateGetPosition(classDefinition, positionField);
    generateGetPage(classDefinition, pageField);
    return defineClass(classDefinition, JoinProbe.class, callSiteBinder.getBindings(), getClass().getClassLoader());
}
Also used : FieldDefinition(com.facebook.presto.bytecode.FieldDefinition) ArrayList(java.util.ArrayList) Block(com.facebook.presto.spi.block.Block) BytecodeBlock(com.facebook.presto.bytecode.BytecodeBlock) ClassDefinition(com.facebook.presto.bytecode.ClassDefinition) JoinProbe(com.facebook.presto.operator.JoinProbe) SimpleJoinProbe(com.facebook.presto.operator.SimpleJoinProbe)

Example 13 with FieldDefinition

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

the class JoinCompiler method internalCompileHashStrategy.

private Class<? extends PagesHashStrategy> internalCompileHashStrategy(List<Type> types, List<Integer> outputChannels, List<Integer> joinChannels) {
    CallSiteBinder callSiteBinder = new CallSiteBinder();
    ClassDefinition classDefinition = new ClassDefinition(a(PUBLIC, FINAL), makeClassName("PagesHashStrategy"), type(Object.class), type(PagesHashStrategy.class));
    FieldDefinition sizeField = classDefinition.declareField(a(PRIVATE, FINAL), "size", type(long.class));
    List<FieldDefinition> channelFields = new ArrayList<>();
    for (int i = 0; i < types.size(); i++) {
        FieldDefinition channelField = classDefinition.declareField(a(PRIVATE, FINAL), "channel_" + i, type(List.class, Block.class));
        channelFields.add(channelField);
    }
    List<Type> joinChannelTypes = new ArrayList<>();
    List<FieldDefinition> joinChannelFields = new ArrayList<>();
    for (int i = 0; i < joinChannels.size(); i++) {
        joinChannelTypes.add(types.get(joinChannels.get(i)));
        FieldDefinition channelField = classDefinition.declareField(a(PRIVATE, FINAL), "joinChannel_" + i, type(List.class, Block.class));
        joinChannelFields.add(channelField);
    }
    FieldDefinition hashChannelField = classDefinition.declareField(a(PRIVATE, FINAL), "hashChannel", type(List.class, Block.class));
    generateConstructor(classDefinition, joinChannels, sizeField, channelFields, joinChannelFields, hashChannelField);
    generateGetChannelCountMethod(classDefinition, outputChannels.size());
    generateGetSizeInBytesMethod(classDefinition, sizeField);
    generateAppendToMethod(classDefinition, callSiteBinder, types, outputChannels, channelFields);
    generateHashPositionMethod(classDefinition, callSiteBinder, joinChannelTypes, joinChannelFields, hashChannelField);
    generateHashRowMethod(classDefinition, callSiteBinder, joinChannelTypes);
    generateRowEqualsRowMethod(classDefinition, callSiteBinder, joinChannelTypes);
    generatePositionEqualsRowMethod(classDefinition, callSiteBinder, joinChannelTypes, joinChannelFields, true);
    generatePositionEqualsRowMethod(classDefinition, callSiteBinder, joinChannelTypes, joinChannelFields, false);
    generatePositionEqualsRowWithPageMethod(classDefinition, callSiteBinder, joinChannelTypes, joinChannelFields);
    generatePositionEqualsPositionMethod(classDefinition, callSiteBinder, joinChannelTypes, joinChannelFields, true);
    generatePositionEqualsPositionMethod(classDefinition, callSiteBinder, joinChannelTypes, joinChannelFields, false);
    generateIsPositionNull(classDefinition, joinChannelFields);
    return defineClass(classDefinition, PagesHashStrategy.class, callSiteBinder.getBindings(), getClass().getClassLoader());
}
Also used : Type(com.facebook.presto.spi.type.Type) SqlTypeBytecodeExpression.constantType(com.facebook.presto.sql.gen.SqlTypeBytecodeExpression.constantType) BigintType(com.facebook.presto.spi.type.BigintType) PagesHashStrategy(com.facebook.presto.operator.PagesHashStrategy) FieldDefinition(com.facebook.presto.bytecode.FieldDefinition) LongArrayList(it.unimi.dsi.fastutil.longs.LongArrayList) ArrayList(java.util.ArrayList) Block(com.facebook.presto.spi.block.Block) BytecodeBlock(com.facebook.presto.bytecode.BytecodeBlock) LongArrayList(it.unimi.dsi.fastutil.longs.LongArrayList) ImmutableCollectors.toImmutableList(com.facebook.presto.util.ImmutableCollectors.toImmutableList) List(java.util.List) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) ClassDefinition(com.facebook.presto.bytecode.ClassDefinition)

Example 14 with FieldDefinition

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

the class JoinCompiler method generateIsPositionNull.

private static void generateIsPositionNull(ClassDefinition classDefinition, List<FieldDefinition> joinChannelFields) {
    Parameter blockIndex = arg("blockIndex", int.class);
    Parameter blockPosition = arg("blockPosition", int.class);
    MethodDefinition isPositionNullMethod = classDefinition.declareMethod(a(PUBLIC), "isPositionNull", type(boolean.class), blockIndex, blockPosition);
    for (FieldDefinition joinChannelField : joinChannelFields) {
        BytecodeExpression block = isPositionNullMethod.getThis().getField(joinChannelField).invoke("get", Object.class, blockIndex).cast(Block.class);
        IfStatement ifStatement = new IfStatement();
        ifStatement.condition(block.invoke("isNull", boolean.class, blockPosition));
        ifStatement.ifTrue(constantTrue().ret());
        isPositionNullMethod.getBody().append(ifStatement);
    }
    isPositionNullMethod.getBody().append(constantFalse().ret());
}
Also used : IfStatement(com.facebook.presto.bytecode.control.IfStatement) MethodDefinition(com.facebook.presto.bytecode.MethodDefinition) FieldDefinition(com.facebook.presto.bytecode.FieldDefinition) Parameter(com.facebook.presto.bytecode.Parameter) BytecodeExpression(com.facebook.presto.bytecode.expression.BytecodeExpression)

Example 15 with FieldDefinition

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

the class StateCompiler method generateField.

private static void generateField(ClassDefinition definition, MethodDefinition constructor, StateField stateField) {
    FieldDefinition field = definition.declareField(a(PRIVATE), UPPER_CAMEL.to(LOWER_CAMEL, stateField.getName()) + "Value", stateField.getType());
    // Generate getter
    MethodDefinition getter = definition.declareMethod(a(PUBLIC), stateField.getGetterName(), type(stateField.getType()));
    getter.getBody().append(getter.getThis().getField(field).ret());
    // Generate setter
    Parameter value = arg("value", stateField.getType());
    MethodDefinition setter = definition.declareMethod(a(PUBLIC), stateField.getSetterName(), type(void.class), value);
    setter.getBody().append(setter.getThis().setField(field, value)).ret();
    constructor.getBody().append(constructor.getThis().setField(field, stateField.initialValueExpression()));
}
Also used : MethodDefinition(com.facebook.presto.bytecode.MethodDefinition) FieldDefinition(com.facebook.presto.bytecode.FieldDefinition) Parameter(com.facebook.presto.bytecode.Parameter)

Aggregations

FieldDefinition (com.facebook.presto.bytecode.FieldDefinition)18 MethodDefinition (com.facebook.presto.bytecode.MethodDefinition)11 Parameter (com.facebook.presto.bytecode.Parameter)7 BytecodeBlock (com.facebook.presto.bytecode.BytecodeBlock)5 ClassDefinition (com.facebook.presto.bytecode.ClassDefinition)5 Variable (com.facebook.presto.bytecode.Variable)4 Block (com.facebook.presto.spi.block.Block)4 ArrayList (java.util.ArrayList)4 BytecodeNode (com.facebook.presto.bytecode.BytecodeNode)3 CallExpression (com.facebook.presto.sql.relational.CallExpression)3 LambdaDefinitionExpression (com.facebook.presto.sql.relational.LambdaDefinitionExpression)3 RowExpression (com.facebook.presto.sql.relational.RowExpression)3 VerifyException (com.google.common.base.VerifyException)3 ImmutableMap (com.google.common.collect.ImmutableMap)3 Scope (com.facebook.presto.bytecode.Scope)2 BytecodeExpressions.constantClass (com.facebook.presto.bytecode.expression.BytecodeExpressions.constantClass)2 ImmutableList (com.google.common.collect.ImmutableList)2 List (java.util.List)2 CompilerUtils.defineClass (com.facebook.presto.bytecode.CompilerUtils.defineClass)1 IfStatement (com.facebook.presto.bytecode.control.IfStatement)1