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 overflow in factorial #11134

Merged
merged 4 commits into from
Jun 26, 2024
Merged

Fix overflow in factorial #11134

merged 4 commits into from
Jun 26, 2024

Conversation

LorrensP-2158466
Copy link
Contributor

Which issue does this PR close?

Closes #11074 .

Rationale for this change

What changes are included in this PR?

  • do checked multiplication
  • added SLT test for overflow

Are these changes tested?

yes

Are there any user-facing changes?

no

@github-actions github-actions bot added the sqllogictest SQL Logic Tests (.slt) label Jun 26, 2024
Copy link
Contributor

@alamb alamb left a comment

Choose a reason for hiding this comment

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

.iter()
.map(|a| match a {
Some(a) => (2..=a)
.try_fold(1i64, i64::checked_mul)
Copy link
Contributor

Choose a reason for hiding this comment

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

👌 Very nice

@alamb alamb merged commit f6f63b9 into apache:main Jun 26, 2024
23 checks passed
@LorrensP-2158466 LorrensP-2158466 deleted the fix-overflow-in-factorial branch June 26, 2024 17:45
findepi pushed a commit to findepi/datafusion that referenced this pull request Jul 16, 2024
* fix: Return overflow error instead of panicking

* refactor: change the way we do checked multiplication and the error returned

* cleaner order of operations on factorial results

* test: add test for factorial overflow
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sqllogictest SQL Logic Tests (.slt)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Overflow bug in FACTORIAL scalar function (found by SQLancer)
2 participants