-
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
feat: support scientific notation in parse_float_as_decimal
#8494
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.
Thanks @Weijun-H
@@ -206,6 +206,18 @@ select 123456789.0123456789012345678901234567890 | |||
statement error SQL error: ParserError\("Cannot parse 1234567890123456789012345678901234567890 as i128 when building decimal: number too large to fit in target type"\) | |||
select -123456789.0123456789012345678901234567890 | |||
|
|||
# scientific notation | |||
query RRRR | |||
select 1.234e2, 1.234e-2, -1.234e2, -1.234e-2 |
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.
1.234e-2
is not -123.4
I don't think 🤔
DataFusion CLI v33.0.0
❯ select 1.234e-2;
+------------------+
| Float64(0.01234) |
+------------------+
| 0.01234 |
+------------------+
datafusion/sql/src/expr/value.rs
Outdated
))) | ||
})?; | ||
|
||
let replaced_str = big_decimal.to_string().replace('.', ""); |
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.
Once you have parsed the data into a BigDecimal, I think you could just convert to a i128
directly which would be more performant and I think potentially more correct
Perhaps you could use
https://docs.rs/bigdecimal/latest/bigdecimal/struct.BigDecimal.html#method.fractional_digit_count to get the scale
And then compute the precision and the i128
from
https://docs.rs/bigdecimal/latest/bigdecimal/struct.BigDecimal.html#method.into_bigint_and_exponent
I don't think this PR is waiting on feedback, so marking it as a draft. Please mark it as ready for review when it is ready for another look 🙏 |
Thank you for your contribution. Unfortunately, this pull request is stale because it has been open 60 days with no activity. Please remove the stale label or comment or this will be closed in 7 days. |
Which issue does this PR close?
Closes #8486
Rationale for this change
What changes are included in this PR?
Are these changes tested?
Are there any user-facing changes?