Skip to content
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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

mihaibudiu
Copy link
Contributor

While fixing this bug I uncovered two more bugs, https://issues.apache.org/jira/browse/CALCITE-6752 and https://issues.apache.org/jira/browse/CALCITE-6753. Some of the code changes are workarounds for these other bugs.

Signed-off-by: Mihai Budiu <mbudiu@feldera.com>
@@ -304,8 +304,8 @@ Expression translateCast(
ConstantExpression format) {
Expression convert = getConvertExpression(sourceType, targetType, operand, format);
Expression convert2 = checkExpressionPadTruncate(convert, sourceType, targetType);
Expression convert3 = expressionHandlingSafe(convert2, safe, targetType);
return scaleValue(sourceType, targetType, convert3);
Expression convert3 = scaleValue(sourceType, targetType, convert2);
Copy link
Contributor Author

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.

@@ -569,6 +569,13 @@ static void assertQuery(
try {
if (updateChecker == null) {
resultSet = statement.executeQuery(sql);
if (resultChecker == null && exceptionChecker != null) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a separate bug, which was uncovered by the @NonDeterministic annotation on toInt. The exception was happening at compilation time, instead of runtime. This change is necessary to uncover exceptions that happen at runtime.

@@ -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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: the indent.

Copy link
Contributor

@NobiGo NobiGo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

!ok

# Unfortunately, due to CALCITE-6752 the following test crashes
# SELECT TIME '10:00:00' + CAST('1.1' AS INTERVAL SECOND);
Copy link
Contributor

Choose a reason for hiding this comment

The 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.

@@ -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.
// See https://issues.apache.org/jira/browse/CALCITE-6753
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CALCITE-6753 can be resolved in an independent PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants