suibianwanwank commented on code in PR #3906:
URL: https://github.com/apache/calcite/pull/3906#discussion_r1706323018
##########
core/src/main/java/org/apache/calcite/rel/type/RelDataTypeSystem.java:
##########
@@ -294,21 +294,21 @@ default boolean
shouldUseDoubleMultiplication(RelDataTypeFactory typeFactory,
int s1 = type1.getScale();
int s2 = type2.getScale();
- final int maxNumericPrecision = getMaxNumericPrecision();
- int dout =
- Math.min(
- p1 - s1 + s2,
- maxNumericPrecision);
-
+ int d = p1 - s1 + s2;
int scale = Math.max(6, s1 + p2 + 1);
- scale =
- Math.min(
- scale,
- maxNumericPrecision - dout);
- scale = Math.min(scale, getMaxNumericScale());
+ int precision = d + scale;
+
+ // Rules from
+ //
https://learn.microsoft.com/en-us/sql/t-sql/data-types/precision-scale-and-length-transact-sql
+ int bound = getMaxNumericPrecision() - 6; // 32 in the MS
documentation
+ if (precision <= bound) {
+ scale = Math.min(scale, getMaxNumericScale() - (precision - scale));
+ } else {
+ // precision > bound
+ scale = Math.min(6, scale);
Review Comment:
If MaxNumericScale < 6, is it possible here to exceed
--
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]