private static boolean isDecimalTypeMatched()

in common/src/main/java/org/apache/comet/parquet/TypeUtil.java [272:304]


  private static boolean isDecimalTypeMatched(ColumnDescriptor descriptor, DataType dt) {
    DecimalType d = (DecimalType) dt;
    LogicalTypeAnnotation typeAnnotation = descriptor.getPrimitiveType().getLogicalTypeAnnotation();
    if (typeAnnotation instanceof DecimalLogicalTypeAnnotation) {
      DecimalLogicalTypeAnnotation decimalType = (DecimalLogicalTypeAnnotation) typeAnnotation;
      // It's OK if the required decimal precision is larger than or equal to the physical decimal
      // precision in the Parquet metadata, as long as the decimal scale is the same.
      return (decimalType.getPrecision() <= d.precision() && decimalType.getScale() == d.scale())
          || (isSpark40Plus()
              && (!SQLConf.get().parquetVectorizedReaderEnabled()
                  || (decimalType.getScale() <= d.scale()
                      && decimalType.getPrecision() - decimalType.getScale()
                          <= d.precision() - d.scale())));
    } else if (isSpark40Plus()) {
      boolean isNullTypeAnnotation = typeAnnotation == null;
      boolean isIntTypeAnnotation = typeAnnotation instanceof IntLogicalTypeAnnotation;
      if (!SQLConf.get().parquetVectorizedReaderEnabled()) {
        return isNullTypeAnnotation || isIntTypeAnnotation;
      } else if (isNullTypeAnnotation
          || (isIntTypeAnnotation && ((IntLogicalTypeAnnotation) typeAnnotation).isSigned())) {
        PrimitiveType.PrimitiveTypeName typeName =
            descriptor.getPrimitiveType().getPrimitiveTypeName();
        int integerPrecision = d.precision() - d.scale();
        switch (typeName) {
          case INT32:
            return integerPrecision >= DecimalType$.MODULE$.IntDecimal().precision();
          case INT64:
            return integerPrecision >= DecimalType$.MODULE$.LongDecimal().precision();
        }
      }
    }
    return false;
  }