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

[SQL] Use standard SQL semantics for division #1201

Merged
merged 1 commit into from
Dec 28, 2023
Merged

[SQL] Use standard SQL semantics for division #1201

merged 1 commit into from
Dec 28, 2023

Conversation

mihaibudiu
Copy link
Collaborator

Is this a user-visible change (yes/no): yes

Fixes #1200

Initially I thought that division is a problematic operation in SQL because it throws on division by 0, so I redefined it to return NULL. Turns out that most SQL operations can throw, so there is no point in only changing the semantics of division. This PR reverts the typing and semantics of division to its standard SQL definition.

@mihaibudiu
Copy link
Collaborator Author

If we really want safe arithmetic we should define functions for that purpose. Note that the Calcite SAFE_ADD and co. functions are unsuitable for our purposes since they cast everything to either BIGINT, DECIMAL or DOUBLE.

Comment on lines 425 to 432
if (iRightType.isOne(rightLit)) {
result = left;
} else if (iRightType.isZero(rightLit)) {
this.errorReporter.reportWarning(expression.getSourcePosition(), "Division by zero",
" Division by constant zero value.");
} else if (iRightType.isOne(rightLit)) {
result = left;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

We check the same condition twice here?

Signed-off-by: Mihai Budiu <mbudiu@feldera.com>
@mihaibudiu mihaibudiu merged commit 5e61f58 into main Dec 28, 2023
5 checks passed
@mihaibudiu mihaibudiu deleted the issue1200 branch December 28, 2023 22:16
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.

[SQL] Use standard SQL semantics for division by zero
2 participants