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

Fix ClassCastException in DomainTranslator #14958

Merged
merged 1 commit into from
Nov 15, 2022
Merged

Conversation

martint
Copy link
Member

@martint martint commented Nov 8, 2022

When theres's an expression such as:

CAST('2022-01-01') AS date) BETWEEN CAST(start_date AS date) AND CAST(end_date AS date)

There's a call to visitComparisonExpression with the term:

DATE '2022-01-01' >= CAST(start_date AS date)

Inside that method, the expression is normalized to have the symbol on the left and the constant on the right. However, the createVarcharCastToDateComparisonExtractionResult pulls the elements from the unnormalized ComparisonExpression node and expects the left subexpression to be cast, which results in a failure due to ClassCastException

Fixes #14954

Release notes

(x) Release notes are required, with the following suggested text:

# General
* Fix failure for queries involving BETWEEN predicates over `varchar` columns that contain temporal data. ({issue}`14954`)

@cla-bot cla-bot bot added the cla-signed label Nov 8, 2022
@hashhar hashhar requested review from findepi and kasiafi November 10, 2022 19:08
@findepi
Copy link
Member

findepi commented Nov 14, 2022

When theres's an expression such as:

CAST('2022-01-01') AS date) BETWEEN CAST(start_date AS date) AND CAST(end_date AS date)

There's a call to visitComparisonExpression with the term:

DATE '2022-01-01' >= CAST(start_date AS varchar)

Did you mean varchar or date in the CAST on the rhs of the comparison?

@@ -1083,6 +1083,23 @@ public void testPredicateWithVarcharCastToDate()
and(
greaterThanOrEqual(cast(C_VARCHAR, DATE), new GenericLiteral("DATE", "2001-01-31")),
lessThanOrEqual(cast(C_VARCHAR, DATE), new GenericLiteral("DATE", "2005-09-10"))));

assertPredicateTranslates(
Copy link
Member

Choose a reason for hiding this comment

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

Add a comment what's special about this case.

When theres's an expression such as:

    CAST('2022-01-01') AS date) BETWEEN CAST(start_date AS date) AND CAST(end_date AS date)

There's a call to visitComparisonExpression with the term:

    DATE '2022-01-01' >= CAST(start_date AS date)

Inside that method, the expression is normalized to have the symbol on the
left and the constant on the right. However, the createVarcharCastToDateComparisonExtractionResult
pulls the elements from the unnormalized ComparisonExpression node and expects the left
subexpression to be cast, which results in a failure due to ClassCastException
@martint martint merged commit b467374 into trinodb:master Nov 15, 2022
@github-actions github-actions bot added this to the 403 milestone Nov 15, 2022
@martint martint deleted the fix-14954 branch July 2, 2024 16:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

Using BETWEEN with varchar cast to date fails
3 participants