twalthr commented on a change in pull request #12464:
URL: https://github.com/apache/flink/pull/12464#discussion_r438156001



##########
File path: 
flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/logical/utils/LogicalTypeMerging.java
##########
@@ -193,6 +193,56 @@ private static void addDayTimeMapping(DayTimeResolution 
to, DayTimeResolution...
                return Optional.empty();
        }
 
+       /**
+        * Finds the result type of a decimal division operation.
+        */
+       public static DecimalType findDivisionDecimalType(int precision1, int 
scale1, int precision2, int scale2) {
+               // adopted from 
https://docs.microsoft.com/en-us/sql/t-sql/data-types/precision-scale-and-length-transact-sql

Review comment:
       Calcite uses a different logic for division. Due to the Blink merge 
there is no history about this change. That's why I simply adopted the logic 
from there.
   
   ```
   final int maxNumericPrecision = getMaxNumericPrecision();
           int dout =
                   Math.min(
                           p1 - s1 + s2,
                           maxNumericPrecision);
   
           int scale = Math.max(6, s1 + p2 + 1);
           scale =
                   Math.min(
                           scale,
                           maxNumericPrecision - dout);
           scale = Math.min(scale, getMaxNumericScale());
   
           int precision = dout + scale;
   ```




----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to