use of com.facebook.presto.operator.project.CursorProcessorOutput in project presto by prestodb.
the class CursorProcessorCompiler method generateProcessMethod.
private static void generateProcessMethod(ClassDefinition classDefinition, int projections, Map<VariableReferenceExpression, CommonSubExpressionFields> cseFields) {
Parameter properties = arg("properties", SqlFunctionProperties.class);
Parameter yieldSignal = arg("yieldSignal", DriverYieldSignal.class);
Parameter cursor = arg("cursor", RecordCursor.class);
Parameter pageBuilder = arg("pageBuilder", PageBuilder.class);
MethodDefinition method = classDefinition.declareMethod(a(PUBLIC), "process", type(CursorProcessorOutput.class), properties, yieldSignal, cursor, pageBuilder);
Scope scope = method.getScope();
Variable completedPositionsVariable = scope.declareVariable(int.class, "completedPositions");
Variable finishedVariable = scope.declareVariable(boolean.class, "finished");
method.getBody().comment("int completedPositions = 0;").putVariable(completedPositionsVariable, 0).comment("boolean finished = false;").putVariable(finishedVariable, false);
// while loop loop body
LabelNode done = new LabelNode("done");
BytecodeBlock whileFunctionBlock = new BytecodeBlock().comment("if (pageBuilder.isFull() || yieldSignal.isSet()) return new CursorProcessorOutput(completedPositions, false);").append(new IfStatement().condition(or(pageBuilder.invoke("isFull", boolean.class), yieldSignal.invoke("isSet", boolean.class))).ifTrue(jump(done))).comment("if (!cursor.advanceNextPosition()) return new CursorProcessorOutput(completedPositions, true);").append(new IfStatement().condition(cursor.invoke("advanceNextPosition", boolean.class)).ifFalse(new BytecodeBlock().putVariable(finishedVariable, true).gotoLabel(done)));
// reset the CSE evaluatedField = false for every row
cseFields.values().forEach(field -> whileFunctionBlock.append(scope.getThis().setField(field.getEvaluatedField(), constantBoolean(false))));
whileFunctionBlock.comment("do the projection").append(createProjectIfStatement(classDefinition, method, properties, cursor, pageBuilder, projections)).comment("completedPositions++;").incrementVariable(completedPositionsVariable, (byte) 1);
WhileLoop whileLoop = new WhileLoop().condition(constantTrue()).body(whileFunctionBlock);
method.getBody().append(whileLoop).visitLabel(done).append(newInstance(CursorProcessorOutput.class, completedPositionsVariable, finishedVariable).ret());
}
use of com.facebook.presto.operator.project.CursorProcessorOutput in project presto by prestodb.
the class ScanFilterAndProjectOperator method processColumnSource.
private Page processColumnSource() {
DriverYieldSignal yieldSignal = operatorContext.getDriverContext().getYieldSignal();
if (!finishing && !yieldSignal.isSet()) {
CursorProcessorOutput output = cursorProcessor.process(sqlFunctionProperties, yieldSignal, cursor, pageBuilder);
pageSourceMemoryContext.setBytes(cursor.getSystemMemoryUsage());
recordCursorInputStats(output.getProcessedRows());
if (output.isNoMoreRows()) {
finishing = true;
mergingOutput.finish();
}
}
// only return a page if buffer is full or we are finishing
Page page = null;
if (!pageBuilder.isEmpty() && (finishing || pageBuilder.isFull())) {
page = pageBuilder.build();
pageBuilder.reset();
}
outputMemoryContext.setBytes(pageBuilder.getRetainedSizeInBytes());
return page;
}
Aggregations