Search in sources :

Example 1 with FunctionCallExpr

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);
}
Also used : LogicalExpression(org.apache.drill.common.expression.LogicalExpression) FixedLenExpr(org.apache.drill.exec.physical.impl.project.OutputWidthExpression.FixedLenExpr) DrillFuncHolder(org.apache.drill.exec.expr.fn.DrillFuncHolder) FunctionCallExpr(org.apache.drill.exec.physical.impl.project.OutputWidthExpression.FunctionCallExpr) OutputWidthCalculator(org.apache.drill.exec.expr.fn.output.OutputWidthCalculator) DrillFuncHolderExpr(org.apache.drill.exec.expr.DrillFuncHolderExpr)

Aggregations

LogicalExpression (org.apache.drill.common.expression.LogicalExpression)1 DrillFuncHolderExpr (org.apache.drill.exec.expr.DrillFuncHolderExpr)1 DrillFuncHolder (org.apache.drill.exec.expr.fn.DrillFuncHolder)1 OutputWidthCalculator (org.apache.drill.exec.expr.fn.output.OutputWidthCalculator)1 FixedLenExpr (org.apache.drill.exec.physical.impl.project.OutputWidthExpression.FixedLenExpr)1 FunctionCallExpr (org.apache.drill.exec.physical.impl.project.OutputWidthExpression.FunctionCallExpr)1