-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[CALCITE-6751] Reduction of CAST from string to interval is incorrect #4116
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4271,6 +4271,10 @@ public static int toInt(java.sql.Time v) { | |
return v == null ? castNonNull(null) : toInt(v); | ||
} | ||
|
||
// Method tagged as non-deterministic because it can throw. | ||
// The DeterministicCodeOptimizer may otherwise try to lift it out of try-catch blocks. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: the indent. |
||
// See https://issues.apache.org/jira/browse/CALCITE-6753 | ||
ILuffZhe marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. CALCITE-6753 can be resolved in an independent PR. |
||
@NonDeterministic | ||
public static int toInt(String s) { | ||
return parseInt(s.trim()); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,40 @@ | |
!use post | ||
!set outputformat mysql | ||
|
||
# [CALCITE-6751] Reduction of CAST from string to interval is incorrect | ||
SELECT TIME '10:00:00' + CAST('1' AS INTERVAL SECOND); | ||
+----------+ | ||
| EXPR$0 | | ||
+----------+ | ||
| 10:00:01 | | ||
+----------+ | ||
(1 row) | ||
|
||
!ok | ||
|
||
# Unfortunately, due to CALCITE-6752 the following test crashes | ||
# SELECT TIME '10:00:00' + CAST('1.1' AS INTERVAL SECOND); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can the annotations here add the correct results?Even if it can't run here. |
||
# | ||
SELECT TIME '10:00:00' + CAST('1' AS INTERVAL HOUR); | ||
+----------+ | ||
| EXPR$0 | | ||
+----------+ | ||
| 11:00:00 | | ||
+----------+ | ||
(1 row) | ||
|
||
!ok | ||
|
||
SELECT TIME '10:00:00' + CAST('1' AS INTERVAL MINUTE); | ||
+----------+ | ||
| EXPR$0 | | ||
+----------+ | ||
| 10:01:00 | | ||
+----------+ | ||
(1 row) | ||
|
||
!ok | ||
|
||
# Compared by casting varchar to number | ||
SELECT '1' > 0 AS C; | ||
+------+ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -569,6 +569,13 @@ static void assertQuery( | |
try { | ||
if (updateChecker == null) { | ||
resultSet = statement.executeQuery(sql); | ||
if (resultChecker == null && exceptionChecker != null) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a separate bug, which was uncovered by the |
||
// Pull data from result set, otherwise exceptions that happen during evaluation | ||
// won't be triggered | ||
while (resultSet.next()) { | ||
// no need to do anything with the data | ||
} | ||
} | ||
} else { | ||
updateCount = statement.executeUpdate(sql); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is the right order to do the conversion: first scaling, then checking for safety.
Otherwise the safe cast implementation returns null, which cannot be an input for the scaling computation.