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: check for precision overflow when parsing float as decimal #7627

Merged
merged 2 commits into from
Sep 25, 2023

Conversation

jonahgao
Copy link
Member

Which issue does this PR close?

Closes #7626.

Rationale for this change

A decimal data could exceed its maximum precision limit without exceeding the maximum value of i128.

What changes are included in this PR?

Check for precision overflow when parsing float as decimal

Are these changes tested?

Yes

Are there any user-facing changes?

No

@github-actions github-actions bot added sql SQL Planner sqllogictest SQL Logic Tests (.slt) labels Sep 22, 2023
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.

Looks good to me -- thank you @jonahgao

)))
})?;

const MAX_DECIMAL_128_VALUE: i128 = 10_i128.pow(38) - 1;
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed. Thank you @alamb .

let number = parse_decimal_128_without_scale(str)?;
Ok(Expr::Literal(ScalarValue::Decimal128(
Some(number),
str.len() as u8,
Copy link
Member Author

Choose a reason for hiding this comment

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

Try to use the minimum precision instead of the maximum precision.

@@ -82,3 +82,72 @@ set datafusion.execution.batch_size = 8192;

statement ok
drop table a

Copy link
Member Author

Choose a reason for hiding this comment

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

Move the tests to options.slt. I think those tests are not related to DDL.

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.

Thanks again @jonahgao

@alamb alamb merged commit 19174e7 into apache:main Sep 25, 2023
21 checks passed
@jonahgao jonahgao deleted the parse_float_as_decimal branch September 25, 2023 15:06
Ted-Jiang pushed a commit to Ted-Jiang/arrow-datafusion that referenced this pull request Oct 7, 2023
…he#7627)

* fix: check for precision overflow when parsing float as decimal

* fix hard-coded precison and move tests to options.slt
@andygrove andygrove added the enhancement New feature or request label Oct 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request sql SQL Planner sqllogictest SQL Logic Tests (.slt)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

panic when parsing float as decimal
3 participants