zstan commented on code in PR #2220:
URL: https://github.com/apache/ignite-3/pull/2220#discussion_r1245235582
##########
modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/exec/exp/IgniteSqlFunctions.java:
##########
@@ -209,6 +216,39 @@ public static BigDecimal toBigDecimal(Object o, int
precision, int scale) {
: toBigDecimal(o.toString(), precision, scale);
}
+ /**
+ * Converts the given {@code BigDecimal} to a decimal with the given
{@code precision} and {@code scale}
+ * according to SQL spec for CAST specification: General Rules, 8.
+ */
+ public static BigDecimal convertDecimal(BigDecimal value, int precision,
int scale) {
+ assert precision > 0 : "Invalid precision: " + precision;
+
+ int defaultPrecision =
IgniteTypeSystem.INSTANCE.getDefaultPrecision(SqlTypeName.DECIMAL);
+ if (precision == defaultPrecision) {
+ // This branch covers at least one known case: access to dynamic
parameter from context.
+ // In this scenario precision = DefaultTypePrecision, because
types for dynamic params
+ // are created by toSql(createType(param.class)).
+ return value;
+ }
+
+ boolean nonZero = !value.unscaledValue().equals(BigInteger.ZERO);
+
+ if (nonZero) {
+ if (scale > precision) {
+ throw new SqlException(QUERY_INVALID_ERR, "Numeric overflow");
Review Comment:
probably "Numeric overflow" must be closer to PG ? i.e. "Numeric field
overflow" ?
additionally why this message is not a public constant for purpose of
further test usage ?
--
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]