Skip to content

Add error handling for saturated floor cast#17014

Merged
sopel39 merged 1 commit intotrinodb:masterfrom
assaf2:error-handling-for-saturated-floor-cast
May 24, 2023
Merged

Add error handling for saturated floor cast#17014
sopel39 merged 1 commit intotrinodb:masterfrom
assaf2:error-handling-for-saturated-floor-cast

Conversation

@assaf2
Copy link
Copy Markdown
Member

@assaf2 assaf2 commented Apr 13, 2023

Description

An exception wasn't thrown until today because of rule ordering. For example, double NaN can't be cast to smallint. Given the query SELECT * FROM (VALUES SMALLINT '1') t(a) WHERE a IS DISTINCT FROM nan(), the filter's predicate is replaced with TRUE by
UnwrapCastInComparison.FilterExpressionRewrite before hitting DomainTranslator. When manually disabling this rule, a TrinoException with the message Unable to cast double NaN to smallint is thrown by DoubleOperators#saturatedFloorCastToLong.

Additional context and related issues

Blocking #16206

Release notes

( X ) This is not user-visible or docs only and no release notes are required.
( ) Release notes are required, please propose a release note for me.
( ) Release notes are required, with the following suggested text:

@cla-bot cla-bot bot added the cla-signed label Apr 13, 2023
@assaf2 assaf2 requested a review from findepi April 13, 2023 09:43
@assaf2 assaf2 self-assigned this Apr 13, 2023
@assaf2 assaf2 marked this pull request as ready for review April 13, 2023 09:43
@assaf2 assaf2 force-pushed the error-handling-for-saturated-floor-cast branch from a28b43d to 3073c7a Compare April 30, 2023 13:39
@assaf2 assaf2 requested review from findepi and martint April 30, 2023 13:41
An exception wasn't thrown until today because of rule ordering.
For example, double NaN can't be cast to smallint. Given the query
"SELECT * FROM (VALUES SMALLINT '1') t(a) WHERE a IS DISTINCT FROM nan()",
the filter's predicate is replaced with TRUE by
UnwrapCastInComparison.FilterExpressionRewrite before hitting
DomainTranslator. When manually disabling this rule, a TrinoException
with the message "Unable to cast double NaN to smallint"
is thrown by DoubleOperators#saturatedFloorCastToLong.
@assaf2 assaf2 force-pushed the error-handling-for-saturated-floor-cast branch from dab8061 to 250dcb5 Compare May 9, 2023 14:08
@assaf2 assaf2 requested a review from findepi May 9, 2023 14:10
@findepi findepi requested a review from sopel39 May 10, 2023 10:35
@findepi
Copy link
Copy Markdown
Member

findepi commented May 10, 2023

@martint @sopel39 ptal

@assaf2
Copy link
Copy Markdown
Member Author

assaf2 commented May 22, 2023

@martint @sopel39 ptal

@martint @sopel39 ptal

.map(floorValue -> rewriteComparisonExpression(symbolExpressionType, symbolExpression, valueType, value, floorValue, comparisonOperator));
Optional<Object> floorValueOptional;
try {
floorValueOptional = floorValue(valueType, symbolExpressionType, value);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is this the only usage of SaturatedFloorCast that needs to be fixed?

@sopel39 sopel39 merged commit e19b69a into trinodb:master May 24, 2023
@github-actions github-actions bot added this to the 419 milestone May 24, 2023
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.

4 participants