use of org.apache.drill.exec.expr.holders.UnionHolder in project drill by apache.
the class DrillFuncHolder method convertReaderToHolder.
/**
* Convert an input value holder (in the generated code) into a value
* holder as declared on the input parameter.
*/
private void convertReaderToHolder(JCodeModel model, JBlock jBlock, HoldingContainer inputVariable, int currentIndex, ValueReference parameter) {
JVar inputHolder = inputVariable.getHolder();
MajorType inputSqlType = inputVariable.getMajorType();
if (Types.isComplex(parameter.getType())) {
// For complex data-types (repeated maps/lists/dicts) the input to the
// aggregate will be a FieldReader. However, aggregate
// functions like ANY_VALUE, will assume the input to be a
// RepeatedMapHolder etc. Generate boilerplate code, to map
// from FieldReader to respective Holder.
// FooHolder param = new FooHolder();
// param.reader = inputVar;
JType holderClass = getParamClass(model, parameter, inputHolder.type());
JAssignmentTarget holderVar = declare(jBlock, parameter, holderClass, JExpr._new(holderClass), currentIndex);
jBlock.assign(holderVar.ref("reader"), inputHolder);
} else if (Types.isUnion(inputSqlType)) {
// Normally unions are generated as a UnionHolder. However, if a parameter
// is a FieldReader, then we must generate the union as a UnionReader.
// Then, if there is another function that use a holder, we can convert
// from the UnionReader to a UnionHolder.
//
// UnionHolder param = new UnionHolder();
// inputVar.read(param);
JType holderClass = model._ref(UnionHolder.class);
JAssignmentTarget paramVar = jBlock.decl(holderClass, parameter.getName(), JExpr._new(holderClass));
JInvocation readCall = inputHolder.invoke("read");
readCall.arg(paramVar);
jBlock.add(readCall);
} else {
throw new UnsupportedOperationException(String.format("Cannot convert values of type %s from a reader to a holder", inputSqlType.getMinorType().name()));
}
}
Aggregations