Skip to content

[CALCITE-7694] RexSimplify should simplify comparisons involving RAND() using its [0, 1) range - #5161

Open
xuzifu666 wants to merge 5 commits into
apache:mainfrom
xuzifu666:rand_opt
Open

[CALCITE-7694] RexSimplify should simplify comparisons involving RAND() using its [0, 1) range#5161
xuzifu666 wants to merge 5 commits into
apache:mainfrom
xuzifu666:rand_opt

Conversation

@xuzifu666

Copy link
Copy Markdown
Member

}

/** Flips a comparison operator. e.g., GREATER_THAN → LESS_THAN. */
private static SqlKind flipComparison(SqlKind kind) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This method should not be necessary, there is already SqlKind#reverse which seems to serve the same purpose

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.

Good catch!SqlKind#reverse() does serve the same purpose. It maps the four ordering comparisons identically, and for EQUALS/NOT_EQUALS it returns the kind unchanged, which is exactly what we want since a = b ⇔ b = a and a <> b ⇔ b <> a. I've removed flipComparison and replaced its three call sites with kind.reverse(). Thanks!

}

/** Checks if a RexNode is a numeric literal (possibly wrapped in CAST). */
private static boolean isNumericLiteral(RexNode node) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could this be simplified by (re)using SqlTypeUtil#isNumeric ?

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. Replaced the manual type-family check with SqlTypeUtil.isNumeric(stripped.getType()), which is equivalent (isExactNumeric || isApproximateNumeric) and reads more clearly. isNumericLiteral is now just a LITERAL check plus SqlTypeUtil.isNumeric.

@sonarqubecloud

sonarqubecloud Bot commented Aug 6, 2026

Copy link
Copy Markdown

@julianhyde

Copy link
Copy Markdown
Contributor

That's a lot of code. Does anyone need this?

@julianhyde

Copy link
Copy Markdown
Contributor

See jira. I don't think we should do this.

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