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: LCM panicked due to overflow #11131

Merged
merged 4 commits into from
Jun 27, 2024
Merged

fix: LCM panicked due to overflow #11131

merged 4 commits into from
Jun 27, 2024

Conversation

jonahgao
Copy link
Member

Which issue does this PR close?

Closes #11104.

Rationale for this change

  • Use checked_mul to detect multiplication overflow.
  • This PR also fixed the issue of LCM potentially returning a negative result.
DataFusion CLI v39.0.0

> select lcm(1, -9223372036854775808);
+-------------------------------------------+
| lcm(Int64(1),Int64(-9223372036854775808)) |
+-------------------------------------------+
| -9223372036854775808                      |
+-------------------------------------------+
1 row(s) fetched.

What changes are included in this PR?

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
@@ -493,41 +493,6 @@ select gcd(a, b), gcd(c, d), gcd(e, f) from signed_integers;
2 1 1
NULL NULL NULL

## lcm
Copy link
Member Author

Choose a reason for hiding this comment

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

The tests for lcm existed in two slts and have now been moved to math.slt.

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.

Thank you @jonahgao -- the code looks good to me as do the tests. Nice work

let a = x.unsigned_abs();
let b = y.unsigned_abs();
let gcd = unsigned_gcd(a, b);
// gcd is not zero since both a and b are not zero, so the division is safe.
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

@jonahgao
Copy link
Member Author

Thanks @alamb for the review. Merged it since future PRs might conflict on math.slt.

@jonahgao jonahgao merged commit 2d1e850 into apache:main Jun 27, 2024
23 checks passed
@jonahgao jonahgao deleted the fix_lcm branch June 27, 2024 03:15
findepi pushed a commit to findepi/datafusion that referenced this pull request Jul 16, 2024
* fix: LCM panicked due to overflow

* add test

* fix comment
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.

LCM panicked due to overflow
2 participants