[
https://issues.apache.org/jira/browse/CALCITE-6706?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17901358#comment-17901358
]
Mihai Budiu commented on CALCITE-6706:
--------------------------------------
The test as written by [~zstan] gives the correct result.
This is because the default conformance does not use checked arithmetic, and
without checked arithmetic -(-32768) returns -32768, ignoring the overflow.
For the test to produce a runtime failure one should use a conformance which
requires checked arithmetic, e.g., rewrite the test as follows:
{code:java}
@Test void testCastOverflow() {
final SqlOperatorFixture f =
fixture().withConformance(SqlConformanceEnum.BIG_QUERY);
f.checkFails("SELECT -CAST(-32768 AS SMALLINT)",
".*Value -32768 does not fit in a SMALLINT", true);
}
{code}
BIG_QUERY is one of the conformances which I could check always requires
checked arithmetic.
And indeed, this test fails, because there *is* a bug. I will submit a fix for
this bug right away.
> Explicit cast to numeric type doesn't check overflow
> ----------------------------------------------------
>
> Key: CALCITE-6706
> URL: https://issues.apache.org/jira/browse/CALCITE-6706
> Project: Calcite
> Issue Type: Bug
> Components: core
> Affects Versions: 1.38.0
> Reporter: Evgeny Stanilovsky
> Assignee: Mihai Budiu
> Priority: Major
>
> Seems this issue need to be continuation of [1] issue
> This test (placed into SqlOperatorTest) need to be failed but it passed:
> {noformat}
> @Test void testCast0() {
> final SqlOperatorFixture f = fixture();
> f.checkFails("SELECT -CAST(-32768 AS SMALLINT)",
> ".*Value 32768 out of range", true);
> }
> {noformat}
> [1] https://issues.apache.org/jira/browse/CALCITE-5990
--
This message was sent by Atlassian Jira
(v8.20.10#820010)