You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flink.apache.org by tw...@apache.org on 2021/11/09 08:03:02 UTC

[flink] 02/03: [hotfix][table-common] Add java docs to LogicalTypeMerging

This is an automated email from the ASF dual-hosted git repository.

twalthr pushed a commit to branch release-1.14
in repository https://gitbox.apache.org/repos/asf/flink.git

commit 0c47ed79b4ea7e3804309426c61f3ecdc3b96273
Author: Marios Trivyzas <ma...@gmail.com>
AuthorDate: Thu Nov 4 10:06:25 2021 +0100

    [hotfix][table-common] Add java docs to LogicalTypeMerging
    
    Add more explanation in `LogicalTypeMerging#adjustPrecisionScale()` method
    regarding the decision to not follow 100% the Microsoft's SQL Server rules
    but instead the Hive/Spark behaviour, when calculating the resulting precision
    of a decimal operation.
---
 .../flink/table/types/logical/utils/LogicalTypeMerging.java    | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/logical/utils/LogicalTypeMerging.java b/flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/logical/utils/LogicalTypeMerging.java
index dfb1ec1..8cf5d96 100644
--- a/flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/logical/utils/LogicalTypeMerging.java
+++ b/flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/logical/utils/LogicalTypeMerging.java
@@ -303,6 +303,16 @@ public final class LogicalTypeMerging {
      * integral part of a result from being truncated.
      *
      * <p>https://docs.microsoft.com/en-us/sql/t-sql/data-types/precision-scale-and-length-transact-sql
+     *
+     * <p>The rules although inspired by SQL Server they are not followed 100%, instead the approach
+     * of Spark/Hive is followed for adjusting the precision.
+     *
+     * <p>http://www.openkb.info/2021/05/understand-decimal-precision-and-scale.html
+     *
+     * <p>For (38, 8) + (32, 8) -> (39, 8) (If precision is infinite) // integral part: 31
+     *
+     * <p>The rounding for SQL Server would be: (39, 8) -> (38, 8) // integral part: 30, but instead
+     * we follow the Hive/Spark approach which gives: (39, 8) -> (38, 7) // integral part: 31
      */
     private static DecimalType adjustPrecisionScale(int precision, int scale) {
         if (precision <= DecimalType.MAX_PRECISION) {