wasabii commented on code in PR #5276:
URL: https://github.com/apache/calcite/pull/5276#discussion_r4067788163
##########
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:
So my understanding is it should behave exactly like CAST does. And that
grabs the rounding mode from the TypeSystem. So this should also grab the same.
But, also, because the cast() method itself isn't really specifically for
JSON_VALUE. It's a dynamic verion of the existing cast code generation. So, it
should at least look the same. In case it gets used by more than JSON_VALUE in
the future.
--
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]