use of com.sun.codemodel.JForLoop in project drill by apache.
the class DrillAggFuncHolder method renderStart.
@Override
public JVar[] renderStart(ClassGenerator<?> g, HoldingContainer[] inputVariables) {
if (!g.getMappingSet().isHashAggMapping()) {
//Declare workspace vars for non-hash-aggregation.
JVar[] workspaceJVars = declareWorkspaceVariables(g);
generateBody(g, BlockType.SETUP, setup(), null, workspaceJVars, true);
return workspaceJVars;
} else {
//Declare workspace vars and workspace vectors for hash aggregation.
JVar[] workspaceJVars = declareWorkspaceVectors(g);
JBlock setupBlock = g.getSetupBlock();
//Loop through all workspace vectors, to get the minimum of size of all workspace vectors.
JVar sizeVar = setupBlock.decl(g.getModel().INT, "vectorSize", JExpr.lit(Integer.MAX_VALUE));
JClass mathClass = g.getModel().ref(Math.class);
for (int id = 0; id < getWorkspaceVars().length; id++) {
if (!getWorkspaceVars()[id].isInject()) {
setupBlock.assign(sizeVar, mathClass.staticInvoke("min").arg(sizeVar).arg(g.getWorkspaceVectors().get(getWorkspaceVars()[id]).invoke("getValueCapacity")));
}
}
for (int i = 0; i < getWorkspaceVars().length; i++) {
if (!getWorkspaceVars()[i].isInject()) {
setupBlock.assign(workspaceJVars[i], JExpr._new(g.getHolderType(getWorkspaceVars()[i].getMajorType())));
}
}
//Use for loop to initialize entries in the workspace vectors.
JForLoop forLoop = setupBlock._for();
JVar ivar = forLoop.init(g.getModel().INT, "drill_internal_i", JExpr.lit(0));
forLoop.test(ivar.lt(sizeVar));
forLoop.update(ivar.assignPlus(JExpr.lit(1)));
JBlock subBlock = generateInitWorkspaceBlockHA(g, BlockType.SETUP, setup(), workspaceJVars, ivar);
forLoop.body().add(subBlock);
return workspaceJVars;
}
}