asolimando commented on code in PR #3522:
URL: https://github.com/apache/calcite/pull/3522#discussion_r1457093609
##########
testkit/src/main/java/org/apache/calcite/test/SqlOperatorTest.java:
##########
@@ -13695,6 +13698,43 @@ private static void
checkLogicalOrFunc(SqlOperatorFixture f) {
}
}
+ /**
+ * Test cases for
+ * <a
href="https://issues.apache.org/jira/browse/CALCITE-6111">[CALCITE-6111]
+ * Explicit cast from expression to numeric type doesn't check overflow</a>.
*/
+ @Test public void testOverflow() {
+ final SqlOperatorFixture f = fixture();
+ f.checkFails(String.format(Locale.US, "SELECT cast(%d+30 as tinyint)",
Byte.MAX_VALUE),
+ ".* out of range", true);
+ f.checkFails(String.format(Locale.US, "SELECT cast(%d+30 as smallint)",
Short.MAX_VALUE),
+ ".* out of range", true);
+ // We use a long value because otherwise calcite interprets the literal as
an integer.
+ f.checkFails(String.format(Locale.US, "SELECT cast(%d as int)",
Long.MAX_VALUE),
+ ".* out of range", true);
+
+ // Casting a floating point value larger than the maximum allowed value.
+ // 1e60 is larger than the largest BIGINT value allowed.
+ f.checkFails("SELECT cast(1e60+30 as tinyint)",
+ ".* out of range", true);
Review Comment:
Yes, Sonar has false positives sometimes, it's fine to address only what's
reasonable (I consider fixing the complexity of an existing test method as as
nice-to-have and totally optional), but most of the time it provides good hints
for keeping the code quality high.
--
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]