You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by "tanclary (via GitHub)" <gi...@apache.org> on 2023/05/31 20:51:00 UTC

[GitHub] [calcite] tanclary commented on a diff in pull request #3234: [CALCITE-5735] Add SAFE_MULTIPLY function (enabled in BigQuery)

tanclary commented on code in PR #3234:
URL: https://github.com/apache/calcite/pull/3234#discussion_r1212296823


##########
core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java:
##########
@@ -1524,6 +1524,19 @@ public static int multiply(int b0, int b1) {
     throw notArithmetic("*", b0, b1);
   }
 
+  /** Helper method for safe arithmetic functions that checks if overflow has occurred. */
+  private static boolean isOverflow(BigDecimal b0) {
+    return b0.compareTo(BigDecimal.valueOf(Long.MIN_VALUE)) < 0
+        || b0.compareTo(BigDecimal.valueOf(Long.MAX_VALUE)) > 0;
+  }
+
+  /** SQL {@code SAFE_MULTIPLY(<value0>, <value1>)} function. */
+  public static @Nullable Double safeMultiply(@PolyNull BigDecimal b0,

Review Comment:
   Yes this is a great idea. 



##########
core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java:
##########
@@ -1524,6 +1524,19 @@ public static int multiply(int b0, int b1) {
     throw notArithmetic("*", b0, b1);
   }
 
+  /** Helper method for safe arithmetic functions that checks if overflow has occurred. */
+  private static boolean isOverflow(BigDecimal b0) {
+    return b0.compareTo(BigDecimal.valueOf(Long.MIN_VALUE)) < 0
+        || b0.compareTo(BigDecimal.valueOf(Long.MAX_VALUE)) > 0;
+  }
+
+  /** SQL {@code SAFE_MULTIPLY(<value0>, <value1>)} function. */
+  public static @Nullable Double safeMultiply(@PolyNull BigDecimal b0,

Review Comment:
   Will remove!



-- 
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@calcite.apache.org

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