Skip to content

Avoid casting REAL into DOUBLE on is_nan()#13831

Merged
findepi merged 1 commit intotrinodb:masterfrom
assaf2:dont-cast-real-to-double-on-is_nan
Aug 25, 2022
Merged

Avoid casting REAL into DOUBLE on is_nan()#13831
findepi merged 1 commit intotrinodb:masterfrom
assaf2:dont-cast-real-to-double-on-is_nan

Conversation

@assaf2
Copy link
Copy Markdown
Member

@assaf2 assaf2 commented Aug 24, 2022

Description

Is this change a fix, improvement, new feature, refactoring, or other?

Improvement

Is this a change to the core query engine, a connector, client library, or the SPI interfaces? (be specific)

Core query engine

How would you describe this change to a non-technical end user or system administrator?

Instead of translating is_nan(real_column) into is_nan(cast(real_column as DOUBLE)) use is_nan(real_column) directly, since REAL type can test for NaN values directly.

Related issues, pull requests, and links

Documentation

( ) No documentation is needed.
(X) Sufficient documentation is included in this PR.
( ) Documentation PR is available with #prnumber.
( ) Documentation issue #issuenumber is filed, and can be handled later.

Release notes

(X) No release notes entries required.
( ) Release notes entries required with the following suggested text:

@cla-bot cla-bot bot added the cla-signed label Aug 24, 2022
@assaf2 assaf2 self-assigned this Aug 24, 2022
@assaf2 assaf2 marked this pull request as ready for review August 25, 2022 07:07
@assaf2 assaf2 requested a review from findepi August 25, 2022 07:09
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.

i'd use toIntExact here.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I thought about it, but seems like this is how isNaN usually tested (at this class, at io.trino.type.RealOperators and at io.trino.spi.type.RealType). I can change it in all places (on a separated PR), WDYT?

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.

Yes, we're not consistent. Sometimes we do unchecked cast ((int)) and sometimes we do a checked one (toIntExact). In new code, please use toIntExact unless there is a compelling reason not to.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

done

@assaf2 assaf2 requested a review from findepi August 25, 2022 09:55
@assaf2 assaf2 force-pushed the dont-cast-real-to-double-on-is_nan branch from b08cd57 to 1047391 Compare August 25, 2022 12:09
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.

No need to produce TrinoException for what would be an internal bug (or a bug in a connector)
(just like some ArrayIndexOutOfBound, or NPE).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Removed

@assaf2 assaf2 force-pushed the dont-cast-real-to-double-on-is_nan branch from 1047391 to 4e3cda7 Compare August 25, 2022 12:59
@assaf2 assaf2 force-pushed the dont-cast-real-to-double-on-is_nan branch from 4e3cda7 to 3b53c2c Compare August 25, 2022 13:01
@assaf2 assaf2 requested a review from findepi August 25, 2022 13:02
@findepi findepi merged commit 46e226e into trinodb:master Aug 25, 2022
@findepi findepi added the no-release-notes This pull request does not require release notes entry label Aug 25, 2022
@github-actions github-actions bot added this to the 394 milestone Aug 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed no-release-notes This pull request does not require release notes entry

Development

Successfully merging this pull request may close these issues.

2 participants