-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Conversation
There was a problem hiding this 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
datafusion/sql/src/expr/value.rs
Outdated
))) | ||
})?; | ||
|
||
const MAX_DECIMAL_128_VALUE: i128 = 10_i128.pow(38) - 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps using https://docs.rs/arrow/latest/arrow/datatypes/constant.DECIMAL128_MAX_PRECISION.html would be clearer than 38
here
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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 | |||
|
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks again @jonahgao
…he#7627) * fix: check for precision overflow when parsing float as decimal * fix hard-coded precison and move tests to options.slt
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