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);
}
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());
}
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());
}
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());
}
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()));
}
Aggregations