use of org.apache.drill.exec.physical.impl.project.OutputWidthExpression.FunctionCallExpr in project drill by apache.
the class OutputWidthVisitor method visitFunctionHolderExpression.
/**
* Handles a {@link FunctionHolderExpression}. Functions that produce
* fixed-width output are trivially converted to a {@link FixedLenExpr}. For
* functions that produce variable width output, the output width calculator
* annotation is looked-up and recorded in a {@link FunctionCallExpr}. This
* calculator will later be used to convert the FunctionCallExpr to a
* {@link FixedLenExpr} expression
*/
@Override
public OutputWidthExpression visitFunctionHolderExpression(FunctionHolderExpression holderExpr, OutputWidthVisitorState state) throws RuntimeException {
OutputWidthExpression fixedWidth = getFixedLenExpr(holderExpr.getMajorType());
if (fixedWidth != null) {
return fixedWidth;
}
// will default to a fixed value
if (!(holderExpr instanceof DrillFuncHolderExpr)) {
// Use a default if this is not a DrillFunc
return new FixedLenExpr(OutputSizeEstimateConstants.NON_DRILL_FUNCTION_OUTPUT_SIZE_ESTIMATE);
}
final DrillFuncHolder holder = ((DrillFuncHolderExpr) holderExpr).getHolder();
// If the user has provided a size estimate, use it
int estimate = holder.variableOutputSizeEstimate();
if (estimate != FunctionTemplate.OUTPUT_SIZE_ESTIMATE_DEFAULT) {
return new FixedLenExpr(estimate);
}
// Use the calculator provided by the user or use the default
OutputWidthCalculator widthCalculator = holder.getOutputWidthCalculator();
final int argSize = holderExpr.args.size();
ArrayList<OutputWidthExpression> arguments = null;
if (argSize != 0) {
arguments = new ArrayList<>(argSize);
for (LogicalExpression expr : holderExpr.args) {
arguments.add(expr.accept(this, state));
}
}
return new FunctionCallExpr(holderExpr, widthCalculator, arguments);
}
Aggregations