private VectorExpression getCastToDecimal(List<ExprNodeDesc> childExpr, VectorExpressionDescriptor.Mode mode,
      TypeInfo returnType) throws HiveException {
    ExprNodeDesc child = childExpr.get(0);
    String inputType = childExpr.get(0).getTypeString();
    if (child instanceof ExprNodeConstantDesc) {

      // Return a constant vector expression
      try {
        Object constantValue = ((ExprNodeConstantDesc) child).getValue();
        if (tryDecimal64Cast) {
          if (((DecimalTypeInfo)returnType).precision() <= 18) {
            Long longValue = castConstantToLong(constantValue, child.getTypeInfo(), PrimitiveCategory.LONG);
            return getConstantVectorExpression(longValue, TypeInfoFactory.longTypeInfo,
                VectorExpressionDescriptor.Mode.PROJECTION);
          }
          return null;
        }
        HiveDecimal decimalValue = castConstantToDecimal(constantValue, child.getTypeInfo());
        return getConstantVectorExpression(decimalValue, returnType, VectorExpressionDescriptor.Mode.PROJECTION);
      } catch (Exception e) {

        // Fall back to VectorUDFAdaptor.
        return null;
      }
    }
    if (isIntFamily(inputType)) {
      if (tryDecimal64Cast) {
        if (((DecimalTypeInfo)returnType).precision() <= 18) {
          return createVectorExpression(CastLongToDecimal64.class, childExpr,
              VectorExpressionDescriptor.Mode.PROJECTION, returnType, DataTypePhysicalVariation.DECIMAL_64);
        }
        return null;
      }
      return createVectorExpression(CastLongToDecimal.class, childExpr, VectorExpressionDescriptor.Mode.PROJECTION,
          returnType, DataTypePhysicalVariation.NONE);
    } else if (inputType.equals(serdeConstants.FLOAT_TYPE_NAME)) {
      return createVectorExpression(CastFloatToDecimal.class, childExpr, VectorExpressionDescriptor.Mode.PROJECTION,
          returnType, DataTypePhysicalVariation.NONE);
    } else if (inputType.equals(serdeConstants.DOUBLE_TYPE_NAME)) {
      return createVectorExpression(CastDoubleToDecimal.class, childExpr, VectorExpressionDescriptor.Mode.PROJECTION,
          returnType, DataTypePhysicalVariation.NONE);
    } else if (decimalTypePattern.matcher(inputType).matches()) {
      if (child instanceof ExprNodeColumnDesc) {
        int colIndex = getInputColumnIndex((ExprNodeColumnDesc) child);
        DataTypePhysicalVariation dataTypePhysicalVariation = getDataTypePhysicalVariation(colIndex);
        if (dataTypePhysicalVariation == DataTypePhysicalVariation.DECIMAL_64) {
          // try to scale up the expression so we can match the return type scale
          if (tryDecimal64Cast && ((DecimalTypeInfo)returnType).precision() <= 18) {
            List<ExprNodeDesc> children = new ArrayList<>();
            int scaleDiff = ((DecimalTypeInfo)returnType).scale() - ((DecimalTypeInfo)childExpr.get(0).getTypeInfo()).scale();
            ExprNodeDesc newConstant = new ExprNodeConstantDesc(new DecimalTypeInfo(scaleDiff, 0),
                HiveDecimal.create(POWEROFTENTABLE[scaleDiff]));
            children.add(child);
            children.add(newConstant);
            ExprNodeGenericFuncDesc newScaledExpr = new ExprNodeGenericFuncDesc(returnType,
                new GenericUDFOPScaleUpDecimal64(), " ScaleUp ", children);
            return getVectorExpression(newScaledExpr, mode);
          }
          // Do Decimal64 conversion instead.
          return createDecimal64ToDecimalConversion(colIndex, returnType);
        } else {
          return createVectorExpression(CastDecimalToDecimal.class, childExpr,
              VectorExpressionDescriptor.Mode.PROJECTION, returnType, DataTypePhysicalVariation.NONE);
        }
      } else {
        return createVectorExpression(CastDecimalToDecimal.class, childExpr, VectorExpressionDescriptor.Mode.PROJECTION,
            returnType, DataTypePhysicalVariation.NONE);
      }
    } else if (isStringFamily(inputType)) {
      DataTypePhysicalVariation dataTypePhysicalVariation =
          tryDecimal64Cast && ((DecimalTypeInfo) returnType).precision() <= 18 ?
              DataTypePhysicalVariation.DECIMAL_64 : 
              DataTypePhysicalVariation.NONE;
      return createVectorExpression(CastStringToDecimal.class, childExpr, VectorExpressionDescriptor.Mode.PROJECTION,
          returnType, dataTypePhysicalVariation);
    } else if (inputType.equals(serdeConstants.TIMESTAMP_TYPE_NAME)) {
      return createVectorExpression(CastTimestampToDecimal.class, childExpr, VectorExpressionDescriptor.Mode.PROJECTION,
          returnType, DataTypePhysicalVariation.NONE);
    }
    return null;
  }
Invoke special handling for expressions that can't be vectorized by regular
descriptor based lookup.
ql/src/java/org/apache/hadoop/hive/ql/exec/vector/VectorizationContext.java