use of com.sun.codemodel.JClass in project drill by apache.
the class ClassGenerator method declareVectorValueSetupAndMember.
/**
* Creates class variable for the value vector using metadata from {@code fieldId}
* and initializes it using setup blocks.
*
* @param batchName expression for invoking {@code getValueAccessorById} method
* @param fieldId metadata of the field that should be declared
* @return a newly generated class field
*/
public JVar declareVectorValueSetupAndMember(DirectExpression batchName, TypedFieldId fieldId) {
// declares field in the inner class if innerClassGenerator has been created
if (innerClassGenerator != null) {
return innerClassGenerator.declareVectorValueSetupAndMember(batchName, fieldId);
}
final ValueVectorSetup setup = new ValueVectorSetup(batchName, fieldId);
// JVar var = this.vvDeclaration.get(setup);
// if(var != null) return var;
Class<?> valueVectorClass = fieldId.getIntermediateClass();
JClass vvClass = model.ref(valueVectorClass);
JClass retClass = vvClass;
String vectorAccess = "getValueVector";
if (fieldId.isHyperReader()) {
retClass = retClass.array();
vectorAccess = "getValueVectors";
}
JVar vv = declareClassField("vv", retClass);
JClass t = model.ref(SchemaChangeException.class);
JType objClass = model.ref(Object.class);
JBlock b = getSetupBlock();
//JExpr.newArray(model.INT).
JVar fieldArr = b.decl(model.INT.array(), "fieldIds" + index++, JExpr.newArray(model.INT, fieldId.getFieldIds().length));
int[] fieldIndices = fieldId.getFieldIds();
for (int i = 0; i < fieldIndices.length; i++) {
b.assign(fieldArr.component(JExpr.lit(i)), JExpr.lit(fieldIndices[i]));
}
JInvocation invoke = batchName.invoke(//
"getValueAccessorById").arg(vvClass.dotclass()).arg(fieldArr);
JVar obj = b.decl(objClass, getNextVar("tmp"), invoke.invoke(vectorAccess));
b._if(obj.eq(JExpr._null()))._then()._throw(JExpr._new(t).arg(JExpr.lit(String.format("Failure while loading vector %s with id: %s.", vv.name(), fieldId.toString()))));
//b.assign(vv, JExpr.cast(retClass, ((JExpression) JExpr.cast(wrapperClass, obj)).invoke(vectorAccess)));
b.assign(vv, JExpr.cast(retClass, obj));
vvDeclaration.put(setup, vv);
return vv;
}
use of com.sun.codemodel.JClass 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;
}
}
Aggregations