You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hudi.apache.org by "danny0405 (via GitHub)" <gi...@apache.org> on 2023/04/18 08:05:10 UTC

[GitHub] [hudi] danny0405 commented on a diff in pull request #8380: [HUDI-6033] Fix rounding exception when to decimal casting

danny0405 commented on code in PR #8380:
URL: https://github.com/apache/hudi/pull/8380#discussion_r1169652200


##########
hudi-common/src/main/java/org/apache/hudi/avro/HoodieAvroUtils.java:
##########
@@ -1040,6 +1035,32 @@ private static Object rewritePrimaryTypeWithDiffSchemaType(Object oldValue, Sche
     throw new AvroRuntimeException(String.format("cannot support rewrite value for schema type: %s since the old schema type is: %s", newSchema, oldSchema));
   }
 
+  /**
+   * When there is a lost in scale, rounding is required to be performed when performing casts.
+   * For types that have a fix scale, the results of the cast will need to be the same for COW and MOR.
+   * <p>
+   * NOTE: COW uses Spark's default rounding of HALF_UP (if Spark entry points are used).
+   * <p>
+   * Floating point types are not considered here as they are susceptible to floating point rounding errors.
+   * <p>
+   * Summary:
+   * <ul>
+   *   <li>double/string -> decimal: HALF_UP</li>
+   *   <li>float -> decimal: HALF_EVEN</li>
+   * </ul>

Review Comment:
   I think we should unify all the rounding mode to `HALF_UP` to avoid ambiguity. And another confusion is #7769, all the numeric and string types use the `HALP_EVEN`, why this patch only fixes `DOUBLE` and `STRING` type, the strategy are out of sync.



-- 
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: commits-unsubscribe@hudi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org