@Nullable Variable sampleWeightsBlock,
CallSiteBinder callSiteBinder,
boolean grouped)
{
// For-loop over rows
Variable positionVariable = context.declareVariable(int.class, "position");
Variable sampleWeightVariable = null;
if (sampleWeightsBlock != null) {
sampleWeightVariable = context.declareVariable(long.class, "sampleWeight");
}
Variable rowsVariable = context.declareVariable(int.class, "rows");
Block block = new Block(context)
.getVariable("page")
.invokeVirtual(Page.class, "getPositionCount", int.class)
.putVariable(rowsVariable)
.initializeVariable(positionVariable);
if (sampleWeightVariable != null) {
block.initializeVariable(sampleWeightVariable);
}
Block loopBody = generateInvokeInputFunction(context, stateField, positionVariable, sampleWeightVariable, parameterVariables, parameterMetadatas, inputFunction, callSiteBinder, grouped);
// Wrap with null checks
List<Boolean> nullable = new ArrayList<>();
for (ParameterMetadata metadata : parameterMetadatas) {
if (metadata.getParameterType() == INPUT_CHANNEL) {
nullable.add(false);
}
else if (metadata.getParameterType() == NULLABLE_INPUT_CHANNEL) {
nullable.add(true);
}
}
checkState(nullable.size() == parameterVariables.size(), "Number of parameters does not match");
for (int i = 0; i < parameterVariables.size(); i++) {
if (!nullable.get(i)) {
IfStatementBuilder builder = ifStatementBuilder(context);
Variable variableDefinition = parameterVariables.get(i);
builder.comment("if(!%s.isNull(position))", variableDefinition.getName())
.condition(new Block(context)
.getVariable(variableDefinition)
.getVariable(positionVariable)
.invokeInterface(com.facebook.presto.spi.block.Block.class, "isNull", boolean.class, int.class))
.ifTrue(NOP)