mihaibudiu commented on code in PR #3945:
URL: https://github.com/apache/calcite/pull/3945#discussion_r1741286587
##########
core/src/main/java/org/apache/calcite/sql/type/SqlTypeFactoryImpl.java:
##########
@@ -88,6 +90,15 @@ public SqlTypeFactoryImpl(RelDataTypeSystem typeSystem) {
if (maxPrecision >= 0 && precision > maxPrecision) {
precision = maxPrecision;
}
+ if (typeName == SqlTypeName.DECIMAL) {
+ if (precision != RelDataType.PRECISION_NOT_SPECIFIED && precision <= 0) {
+ throw RESOURCE.invalidPrecisionForDecimalType(precision,
maxPrecision).ex();
+ }
+ if (scale != RelDataType.SCALE_NOT_SPECIFIED && scale < 0
Review Comment:
This is now a problem, since SCALE_NOT_SPECIFIED is -1, which may be a legal
scale value. Maybe this constant should be changed to Integer.MIN_VALUE.
##########
core/src/test/resources/sql/misc.iq:
##########
@@ -3182,4 +3182,41 @@ from (values 0) as t(x);
EnumerableValues(tuples=[[{ true, false, true, false, true, false, true, false
}]])
!plan
+# [CALCITE-6560] Add supportsNegativeScale in RelDataTypeSystem
+
+!set outputformat csv
+
+# throw an exception when CAST target decimal type has illegal precision and
scale parameter
+
+# precision is negative number
+values cast(15.3 as decimal(-1,4));
+Error while executing SQL "values cast(15.3 as decimal(-1,4))": parse failed:
Encountered "-" at line 1, column 29.
+!error
+
+# precision is 0
+values cast(15.3 as decimal(0,4));
+DECIMAL precision 0 must be between 1 and max precision 19
+!error
+
+# scale is negative number
+values cast(15.3 as decimal(1,-1));
+Error while executing SQL "values cast(15.3 as decimal(1,-1))": parse failed:
Encountered "-" at line 1, column 31.
Review Comment:
this suggests that the parser has to be changed to allow negative values for
scale
--
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]