private static RowExpressionVisitor<BytecodeNode, Scope> fieldReferenceCompiler( final CallSiteBinder callSiteBinder, final Variable leftPosition, final Variable leftPage, final Variable rightPosition, final Variable rightPage, final int leftBlocksSize) { return new InputReferenceCompiler( (scope, field) -> { if (field < leftBlocksSize) { return leftPage.invoke("getBlock", Block.class, constantInt(field)); } return rightPage.invoke("getBlock", Block.class, constantInt(field - leftBlocksSize)); }, (scope, field) -> field < leftBlocksSize ? leftPosition : rightPosition, callSiteBinder); }
private static void declareBlockVariables(RowExpression expression, Parameter page, Scope scope, BytecodeBlock body) { for (int channel : getInputChannels(expression)) { scope.declareVariable("block_" + channel, body, page.invoke("getBlock", Block.class, constantInt(channel))); } }
ParameterMetadata parameterMetadata = parameterMetadatas.get(i); Class<?> parameterType = parameterTypes[i]; BytecodeExpression getChannel = channels.invoke("get", Object.class, constantInt(inputChannel)).cast(int.class); switch (parameterMetadata.getParameterType()) { case STATE: case BLOCK_INDEX: expressions.add(constantInt(0)); break; case BLOCK_INPUT_CHANNEL:
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; }
"map", methodDefinition.getBody(), invokeStatic(Maps.class, "newHashMapWithExpectedSize", HashMap.class, constantInt(javaTypes.size()))); for (int i = 0; i < javaTypes.size(); i++) { body.append(map.invoke("put", Object.class, constantString(names.get(i)).cast(Object.class), parameterList.get(i).cast(Object.class)));
constantType(binder, elementType).invoke("createBlockBuilder", BlockBuilder.class, constantNull(BlockBuilderStatus.class), constantInt(stackTypes.size()))); body.append(createBlockBuilder);
body.append(length.set(constantInt(0))); body.append(position.set(constantInt(0)));
.invoke("getBlock", Block.class, constantInt(sortChannel)); .invoke("getBlock", Block.class, constantInt(sortChannel));
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));
if (!field.isPrimitiveType()) { deserializerBody.append(new IfStatement() .condition(row.invoke("isNull", boolean.class, constantInt(position))) .ifTrue(state.cast(setter.getDeclaringClass()).invoke(setter, constantNull(field.getType()))) .ifFalse(state.cast(setter.getDeclaringClass()).invoke(setter, constantType(binder, field.getSqlType()).getValue(row, constantInt(position))))); state.cast(setter.getDeclaringClass()).invoke( setter, constantType(binder, field.getSqlType()).getValue(row, constantInt(position)).cast(field.getType())));
body.append(thisVariable.setField( stateFieldAndDescriptors.get(i).getStateSerializerField(), stateDescriptors.invoke("get", Object.class, constantInt(i)) .cast(AccumulatorStateDescriptor.class) .invoke("getSerializer", AccumulatorStateSerializer.class))); body.append(thisVariable.setField( stateFieldAndDescriptors.get(i).getStateFactoryField(), stateDescriptors.invoke("get", Object.class, constantInt(i)) .cast(AccumulatorStateDescriptor.class) .invoke("getFactory", AccumulatorStateFactory.class))); body.append(thisVariable.setField( lambdaProviderFields.get(i), lambdaProviders.invoke("get", Object.class, constantInt(i)) .cast(LambdaProvider.class)));
private static void generateHashRowMethod(ClassDefinition classDefinition, CallSiteBinder callSiteBinder, List<Type> joinChannelTypes) { Parameter position = arg("position", int.class); Parameter page = arg("blocks", Page.class); MethodDefinition hashRowMethod = classDefinition.declareMethod(a(PUBLIC), "hashRow", type(long.class), position, page); Variable resultVariable = hashRowMethod.getScope().declareVariable(long.class, "result"); hashRowMethod.getBody().push(0L).putVariable(resultVariable); for (int index = 0; index < joinChannelTypes.size(); index++) { BytecodeExpression type = constantType(callSiteBinder, joinChannelTypes.get(index)); BytecodeExpression block = page.invoke("getBlock", Block.class, constantInt(index)); hashRowMethod .getBody() .getVariable(resultVariable) .push(31L) .append(OpCode.LMUL) .append(typeHashCode(type, block, position)) .append(OpCode.LADD) .putVariable(resultVariable); } hashRowMethod .getBody() .getVariable(resultVariable) .retLong(); }
BlockBuilder.class, constantNull(BlockBuilderStatus.class), constantInt(1)))); block.append(singleRowBlockWriter.set(blockBuilder.invoke("beginBlockEntry", BlockBuilder.class))); block.append(constantType(binder, rowType).invoke("getObject", Object.class, blockBuilder.cast(Block.class), constantInt(0)) .cast(Block.class)); block.append(context.wasNull().set(constantFalse()));
.cast(Block.class); BytecodeExpression rightBlock = rightPage.invoke("getBlock", Block.class, constantInt(index)); BytecodeNode equalityCondition; if (ignoreNulls) {
.pushJavaDefault(javaType); BytecodeExpression value = constantType(callSiteBinder, returnType).getValue(rowBlock, constantInt(index));
Variable position = scope.declareVariable(int.class, "position"); body.append(new ForLoop() .initialize(position.set(constantInt(0))) .condition(lessThan(position, positionCount)) .update(position.increment())
.initialize(position.set(constantInt(0))) .condition(lessThan(position, array.invoke("getPositionCount", int.class))) .update(incrementVariable(position, (byte) 1))
for (int i = 0; i < fieldTypes.size(); i++) { IfStatement ifNullField = new IfStatement("if the field is null..."); ifNullField.condition(value.invoke("isNull", boolean.class, constantInt(i))) .ifTrue(new BytecodeBlock() .push(true) ImmutableList.of(fieldTypes.get(i).getTypeSignature())); ScalarFunctionImplementation function = functionRegistry.getScalarFunctionImplementation(signature); BytecodeExpression element = constantType(binder, fieldTypes.get(i)).getValue(value, constantInt(i));
BytecodeExpression channel = channels.invoke("get", Object.class, constantInt(index)) .cast(type(List.class, Block.class)); .initialize(blockIndex.set(constantInt(0))) .condition(new BytecodeBlock() .append(blockIndex) BytecodeExpression joinChannel = channels.invoke("get", Object.class, constantInt(joinChannels.get(index))) .cast(type(List.class, Block.class));
private static BytecodeBlock generateBlockNonNullPositionForLoop(Scope scope, Variable positionVariable, BytecodeBlock loopBody) { Variable rowsVariable = scope.declareVariable(int.class, "rows"); Variable blockVariable = scope.getVariable("block"); BytecodeBlock block = new BytecodeBlock() .append(blockVariable) .invokeInterface(Block.class, "getPositionCount", int.class) .putVariable(rowsVariable); IfStatement ifStatement = new IfStatement("if(!block.isNull(position))") .condition(new BytecodeBlock() .append(blockVariable) .append(positionVariable) .invokeInterface(Block.class, "isNull", boolean.class, int.class)) .ifFalse(loopBody); block.append(new ForLoop() .initialize(positionVariable.set(constantInt(0))) .condition(new BytecodeBlock() .append(positionVariable) .append(rowsVariable) .invokeStatic(CompilerOperations.class, "lessThan", boolean.class, int.class, int.class)) .update(new BytecodeBlock().incrementVariable(positionVariable, (byte) 1)) .body(ifStatement)); return block; }