Search in sources :

Example 1 with DecimalScalePrecisionAddFunction

use of org.apache.drill.common.util.DecimalScalePrecisionAddFunction in project drill by axbaretto.

the class DrillDecimalAddFuncHolder method getReturnType.

/*
   * This function scope is used by add and subtract functions for decimal data type.
   * DecimalScalePrecisionAddFunction is used to compute the output types'
   * scale and precision
   */
@Override
public MajorType getReturnType(List<LogicalExpression> args) {
    TypeProtos.DataMode mode = returnValue.type.getMode();
    if (nullHandling == NullHandling.NULL_IF_NULL) {
        // if any one of the input types is nullable, then return nullable return type
        for (LogicalExpression e : args) {
            if (e.getMajorType().getMode() == TypeProtos.DataMode.OPTIONAL) {
                mode = TypeProtos.DataMode.OPTIONAL;
                break;
            }
        }
    }
    /* Get the result's scale and precision. This is a function scope for add function, assert we have
     * only two inputs
     */
    assert args.size() == 2;
    DecimalScalePrecisionAddFunction outputScalePrec = new DecimalScalePrecisionAddFunction(args.get(0).getMajorType().getPrecision(), args.get(0).getMajorType().getScale(), args.get(1).getMajorType().getPrecision(), args.get(1).getMajorType().getScale());
    return (TypeProtos.MajorType.newBuilder().setMinorType(DecimalUtility.getDecimalDataType(outputScalePrec.getOutputPrecision())).setScale(outputScalePrec.getOutputScale()).setPrecision(outputScalePrec.getOutputPrecision()).setMode(mode).build());
}
Also used : LogicalExpression(org.apache.drill.common.expression.LogicalExpression) DecimalScalePrecisionAddFunction(org.apache.drill.common.util.DecimalScalePrecisionAddFunction) TypeProtos(org.apache.drill.common.types.TypeProtos)

Aggregations

LogicalExpression (org.apache.drill.common.expression.LogicalExpression)1 TypeProtos (org.apache.drill.common.types.TypeProtos)1 DecimalScalePrecisionAddFunction (org.apache.drill.common.util.DecimalScalePrecisionAddFunction)1