wasabii commented on code in PR #5276:
URL: https://github.com/apache/calcite/pull/5276#discussion_r4067735813


##########
core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java:
##########
@@ -5636,6 +5637,194 @@ public static BigDecimal toBigDecimal(Object o) {
         : toBigDecimal(o.toString());
   }
 
+  /** Converts a value to the SQL type {@code typeName}, as {@code CAST}
+   * does, when the type of the value is not known until run time.
+   *
+   * <p>Throws if the value cannot be converted, and for a target type that
+   * this method does not handle, so that a caller such as
+   * {@code JSON_VALUE} can apply its {@code ON ERROR} clause.
+   *
+   * @param value        Value to convert
+   * @param typeName     Type to convert it to; {@link SqlTypeName#ANY}
+   *                     returns the value unchanged
+   * @param precision    Precision of the target type, or negative
+   * @param scale        Scale of the target type, or negative
+   * @param roundingMode Rounding mode of the type system
+   */
+  static @Nullable Object cast(@Nullable Object value,
+      SqlTypeName typeName, int precision, int scale,
+      RoundingMode roundingMode) {

Review Comment:
   When I was looking at the existing cast generation code, I found it being 
sent. I opted to include it here, even though it isn't passed with 
JSON_VALUE/JSON_QUERY, because I if I was going to make runtime versions of 
"cast" and "castArray", I wanted them to mirror what happened in the code 
generation portion. So we don't have to alter the signature in the future to 
include it if something else that needs runtime CAST comes up.



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

Reply via email to