yujun777 commented on code in PR #44732:
URL: https://github.com/apache/doris/pull/44732#discussion_r1862389568
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/util/TypeCoercionUtils.java:
##########
@@ -1796,6 +1797,65 @@ private static Expression
processDecimalV3BinaryArithmetic(BinaryArithmetic bina
castIfNotSameType(right, dt2));
}
+ /**
+ * get min and max value of a data type
+ *
+ * @param dataType specific data type
+ * @return min and max values pair
+ */
+ public static Optional<Pair<BigDecimal, BigDecimal>>
getDataTypeMinMaxValue(DataType dataType) {
+ if (dataType.isTinyIntType()) {
+ return Optional.of(Pair.of(new BigDecimal(Byte.MIN_VALUE), new
BigDecimal(Byte.MAX_VALUE)));
+ } else if (dataType.isSmallIntType()) {
+ return Optional.of(Pair.of(new BigDecimal(Short.MIN_VALUE), new
BigDecimal(Short.MAX_VALUE)));
+ } else if (dataType.isIntegerType()) {
+ return Optional.of(Pair.of(new BigDecimal(Integer.MIN_VALUE), new
BigDecimal(Integer.MAX_VALUE)));
+ } else if (dataType.isBigIntType()) {
+ return Optional.of(Pair.of(new BigDecimal(Long.MIN_VALUE), new
BigDecimal(Long.MAX_VALUE)));
+ } else if (dataType.isLargeIntType()) {
+ return Optional.of(Pair.of(new BigDecimal(LargeIntType.MIN_VALUE),
new BigDecimal(LargeIntType.MAX_VALUE)));
+ } else if (dataType.isFloatType()) {
+ //minVal = BigDecimal.valueOf(-Float.MAX_VALUE);
+ return Optional.of(Pair.of(new
BigDecimal(String.valueOf(Float.MIN_VALUE)),
+ new BigDecimal(String.valueOf(Float.MAX_VALUE))));
+ } else if (dataType.isDoubleType()) {
+ //minVal = BigDecimal.valueOf(-Double.MAX_VALUE);
Review Comment:
> need `-Double.MAX_VALUE`
fix
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/util/TypeCoercionUtils.java:
##########
@@ -1796,6 +1797,65 @@ private static Expression
processDecimalV3BinaryArithmetic(BinaryArithmetic bina
castIfNotSameType(right, dt2));
}
+ /**
+ * get min and max value of a data type
+ *
+ * @param dataType specific data type
+ * @return min and max values pair
+ */
+ public static Optional<Pair<BigDecimal, BigDecimal>>
getDataTypeMinMaxValue(DataType dataType) {
+ if (dataType.isTinyIntType()) {
+ return Optional.of(Pair.of(new BigDecimal(Byte.MIN_VALUE), new
BigDecimal(Byte.MAX_VALUE)));
+ } else if (dataType.isSmallIntType()) {
+ return Optional.of(Pair.of(new BigDecimal(Short.MIN_VALUE), new
BigDecimal(Short.MAX_VALUE)));
+ } else if (dataType.isIntegerType()) {
+ return Optional.of(Pair.of(new BigDecimal(Integer.MIN_VALUE), new
BigDecimal(Integer.MAX_VALUE)));
+ } else if (dataType.isBigIntType()) {
+ return Optional.of(Pair.of(new BigDecimal(Long.MIN_VALUE), new
BigDecimal(Long.MAX_VALUE)));
+ } else if (dataType.isLargeIntType()) {
+ return Optional.of(Pair.of(new BigDecimal(LargeIntType.MIN_VALUE),
new BigDecimal(LargeIntType.MAX_VALUE)));
+ } else if (dataType.isFloatType()) {
+ //minVal = BigDecimal.valueOf(-Float.MAX_VALUE);
+ return Optional.of(Pair.of(new
BigDecimal(String.valueOf(Float.MIN_VALUE)),
+ new BigDecimal(String.valueOf(Float.MAX_VALUE))));
+ } else if (dataType.isDoubleType()) {
+ //minVal = BigDecimal.valueOf(-Double.MAX_VALUE);
+ return Optional.of(Pair.of(new
BigDecimal(String.valueOf(Double.MIN_VALUE)),
+ new BigDecimal(String.valueOf(Double.MAX_VALUE))));
+ } else if (dataType.isDecimalLikeType()) {
+ int precision = -1;
+ int scale = -1;
+ if (dataType instanceof DecimalV2Type) {
+ DecimalV2Type type = (DecimalV2Type) dataType;
+ precision = type.getPrecision();
+ scale = type.getScale();
+ }
+ if (dataType instanceof DecimalV3Type) {
+ DecimalV3Type type = (DecimalV3Type) dataType;
+ precision = type.getPrecision();
+ scale = type.getScale();
+ }
+ if (scale >= 0) {
+ StringBuilder sb = new StringBuilder();
+ for (int i = 0; i < precision - scale; i++) {
+ sb.append('9');
Review Comment:
> maybe u could use `org.apache.common.lang3.StringUtils.repeat`
fix
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]