private VectorExpression getDecimal64VectorExpressionForUdf(GenericUDF genericUdf,
      Class<?> udfClass, List<ExprNodeDesc> childExprs, int numChildren,
      VectorExpressionDescriptor.Mode mode, TypeInfo returnTypeInfo) throws HiveException {

    VectorExpressionDescriptor.Builder builder = new VectorExpressionDescriptor.Builder();
    builder.setNumArguments(numChildren);
    builder.setMode(mode);

    // DECIMAL_64 decimals must have same scale.
    boolean anyDecimal64Expr = false;
    boolean isDecimal64ScaleEstablished = false;
    int decimal64ColumnScale = 0;
    boolean hasConstants = false;
    boolean scaleMismatch = false;

    for (int i = 0; i < numChildren; i++) {
      ExprNodeDesc childExpr = childExprs.get(i);

      /*
       * For columns, we check decimal columns for DECIMAL_64 DataTypePhysicalVariation.
       * For UDFs, we check for @VectorizedExpressionsSupportDecimal64 annotation, etc.
       */
      final boolean isExprDecimal64 = checkExprNodeDescForDecimal64(childExpr);
      if (isExprDecimal64) {
        anyDecimal64Expr = true;
      }

      TypeInfo typeInfo = childExpr.getTypeInfo();
      if (childExpr instanceof ExprNodeGenericFuncDesc ||
          childExpr instanceof ExprNodeColumnDesc) {
        if (isExprDecimal64) {
          DecimalTypeInfo decimalTypeInfo = (DecimalTypeInfo) typeInfo;
          if (decimalTypeInfo.getScale() != decimal64ColumnScale && i > 0) {
            scaleMismatch = true;
          }
          if (decimalTypeInfo.getScale() >= decimal64ColumnScale) {
            decimal64ColumnScale = decimalTypeInfo.getScale();
            isDecimal64ScaleEstablished = true;
          }
        }
        builder.setInputExpressionType(i, InputExpressionType.COLUMN);
      } else if (childExpr instanceof ExprNodeConstantDesc) {
        hasConstants = true;
        if (isNullConst(childExpr)) {
          // Cannot handle NULL scalar parameter.
          return null;
        }
        builder.setInputExpressionType(i, InputExpressionType.SCALAR);
      } else {
        return null;
      }

      if (isExprDecimal64) {
        builder.setArgumentType(i, ArgumentType.DECIMAL_64);
      } else {
        String undecoratedTypeName = getUndecoratedName(childExpr.getTypeString());
        if (undecoratedTypeName == null) {
          return null;
        }
        builder.setArgumentType(i, undecoratedTypeName);
      }
    }

    if (!anyDecimal64Expr) {
      return null;
    }

    final boolean isReturnDecimal64 = checkTypeInfoForDecimal64(returnTypeInfo);
    final DataTypePhysicalVariation returnDataTypePhysicalVariation;
    final boolean dontRescaleArguments = (genericUdf instanceof GenericUDFOPMultiply);
    if (isReturnDecimal64) {
      DecimalTypeInfo returnDecimalTypeInfo = (DecimalTypeInfo) returnTypeInfo;
      if (!isDecimal64ScaleEstablished) {
        decimal64ColumnScale = returnDecimalTypeInfo.getScale();
        isDecimal64ScaleEstablished = true;
      } else if (genericUdf instanceof GenericUDFOPDivide) {
        // Check possible overflow during decimal64 division for intermediate result
        // if yes then skip the optimization
        DecimalTypeInfo leftType = (DecimalTypeInfo)childExprs.get(0).getTypeInfo();
        if((leftType.precision() + returnDecimalTypeInfo.getScale()) > 18) {
          return null;
        }
      } else if (returnDecimalTypeInfo.getScale() != decimal64ColumnScale && !dontRescaleArguments) {
        return null;
      }
      returnDataTypePhysicalVariation = DataTypePhysicalVariation.DECIMAL_64;
    } else if (returnTypeInfo instanceof DecimalTypeInfo){

      // Currently, we don't have any vectorized expressions that take DECIMAL_64 inputs
      // and produce a regular decimal.  Or, currently, a way to express that in the
      // descriptor.
      return null;
    } else {
      returnDataTypePhysicalVariation = DataTypePhysicalVariation.NONE;
    }

    if (dontRescaleArguments && hasConstants) {
      builder.setUnscaled(true);
    }
    VectorExpressionDescriptor.Descriptor descriptor = builder.build();
    Class<?> vectorClass =
        this.vMap.getVectorExpressionClass(udfClass, descriptor, useCheckedVectorExpressions);
    if (vectorClass == null) {
      return null;
    }

    VectorExpressionDescriptor.Mode childrenMode = getChildrenMode(mode, udfClass);

    // Rewrite the operand with smaller scale, so we can process Decimal64 operations
    // on all the arithmetic and comparison operations.
    if (scaleMismatch && !hasConstants &&
        (genericUdf instanceof GenericUDFBaseArithmetic
        || genericUdf instanceof GenericUDFBaseCompare)) {
      ExprNodeDesc left = childExprs.get(0);
      ExprNodeDesc right = childExprs.get(1);
      DecimalTypeInfo leftTypeInfo = (DecimalTypeInfo)left.getTypeInfo();
      DecimalTypeInfo rightTypeInfo = (DecimalTypeInfo)right.getTypeInfo();
      int leftScale = leftTypeInfo.getScale();
      int rightScale = rightTypeInfo.getScale();
      int leftPrecision = leftTypeInfo.precision();
      int rightPrecision = rightTypeInfo.precision();
      ExprNodeDesc newConstant;
      List<ExprNodeDesc> children = new ArrayList<>();
      DecimalTypeInfo resultTypeInfo;
      int childIndexToRewrite = -1;
      int scaleDiff = 0;
      int resultPrecision = 0;
      int resultScale = 0;
      if (leftScale < rightScale) {
        scaleDiff = rightScale - leftScale;
        childIndexToRewrite = 0;
        resultPrecision = leftPrecision + rightScale - leftScale;
        resultScale = rightScale;
      } else {
        scaleDiff = leftScale - rightScale;
        childIndexToRewrite = 1;
        resultPrecision = rightPrecision + leftScale - rightScale;
        resultScale = leftScale;
      }
      newConstant = new ExprNodeConstantDesc(new DecimalTypeInfo(scaleDiff, 0),
          HiveDecimal.create(POWEROFTENTABLE[scaleDiff]));
      resultTypeInfo = new DecimalTypeInfo(resultPrecision, resultScale);
      children.add(childExprs.get(childIndexToRewrite));
      children.add(newConstant);
      ExprNodeGenericFuncDesc newScaledExpr = new ExprNodeGenericFuncDesc(resultTypeInfo,
          new GenericUDFOPScaleUpDecimal64(), " ScaleUp ", children);
      childExprs.remove(childIndexToRewrite);
      childExprs.add(childIndexToRewrite, newScaledExpr);
    }

    return createDecimal64VectorExpression(
        vectorClass, childExprs, childrenMode,
        isDecimal64ScaleEstablished, decimal64ColumnScale,
        returnTypeInfo, returnDataTypePhysicalVariation, dontRescaleArguments, genericUdf);
  }
Used as a fast path for operations that don't modify their input, like unary +
and casting boolean to long. IdentityExpression and its children are always
projections.
ql/src/java/org/apache/hadoop/hive/ql/exec/vector/VectorizationContext.java