-
Notifications
You must be signed in to change notification settings - Fork 3.7k
[fix](core) Fix format round would core under boundary conditions. #53660
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
Conversation
|
Thank you for your contribution to Apache Doris. Please clearly describe your PR:
|
|
run buildall |
TPC-H: Total hot run time: 34069 ms |
TPC-DS: Total hot run time: 190539 ms |
ClickBench: Total hot run time: 32.68 s |
| // Find the position of the decimal point | ||
| size_t dot_pos = formatted_num.find('.'); | ||
| if (dot_pos == std::string::npos) { | ||
| dot_pos = formatted_num.size(); // 没有小数点 |
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.
Chinese comment
|
run buildall |
TPC-H: Total hot run time: 34217 ms |
TPC-DS: Total hot run time: 190515 ms |
ClickBench: Total hot run time: 32.81 s |
|
run buildall |
TPC-H: Total hot run time: 34710 ms |
TPC-DS: Total hot run time: 192108 ms |
|
run buildall |
TPC-H: Total hot run time: 33826 ms |
TPC-DS: Total hot run time: 187995 ms |
ClickBench: Total hot run time: 32.44 s |
HappenLee
left a comment
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.
LGTM
|
PR approved by at least one committer and no changes requested. |
|
PR approved by anyone and no changes requested. |
| } | ||
|
|
||
| // Handle the integer part | ||
| int start = (formatted_num[0] == '-') ? 1 : 0; |
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.
Will formatted_num be empty?
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.
这个formatted_num是fmt::format("{:.{}f}", value, decimal_places)的结果。
这个已经判断是一个正规的数了,变成字符串一定不为空,我加一个DCHECK吧。
…pache#53660) my_double_round did not handle NaN values correctly. For example, when dec is very large and value is 0, there will be a case of 0 * inf, resulting in a NaN value. do_format_round assumes the input is always a valid double value, which causes a core dump when a NaN is passed in. Additionally, (value.size() - (is_positive ? (decimal_places + 2) : (decimal_places + 3))) / 3; This code does not account for the situation where value.size() is 0. Currently, a custom add_thousands_separator function is implemented. If the fmt library is upgraded in the future, we should use fmt to add thousands separators.
…pache#53660) my_double_round did not handle NaN values correctly. For example, when dec is very large and value is 0, there will be a case of 0 * inf, resulting in a NaN value. do_format_round assumes the input is always a valid double value, which causes a core dump when a NaN is passed in. Additionally, (value.size() - (is_positive ? (decimal_places + 2) : (decimal_places + 3))) / 3; This code does not account for the situation where value.size() is 0. Currently, a custom add_thousands_separator function is implemented. If the fmt library is upgraded in the future, we should use fmt to add thousands separators.
…pache#53660) my_double_round did not handle NaN values correctly. For example, when dec is very large and value is 0, there will be a case of 0 * inf, resulting in a NaN value. do_format_round assumes the input is always a valid double value, which causes a core dump when a NaN is passed in. Additionally, (value.size() - (is_positive ? (decimal_places + 2) : (decimal_places + 3))) / 3; This code does not account for the situation where value.size() is 0. Currently, a custom add_thousands_separator function is implemented. If the fmt library is upgraded in the future, we should use fmt to add thousands separators.
…ons (#53855) …53660) #53660 my_double_round did not handle NaN values correctly. For example, when dec is very large and value is 0, there will be a case of 0 * inf, resulting in a NaN value. do_format_round assumes the input is always a valid double value, which causes a core dump when a NaN is passed in. Additionally, (value.size() - (is_positive ? (decimal_places + 2) : (decimal_places + 3))) / 3; This code does not account for the situation where value.size() is 0. Currently, a custom add_thousands_separator function is implemented. If the fmt library is upgraded in the future, we should use fmt to add thousands separators. ### What problem does this PR solve? Issue Number: close #xxx Related PR: #xxx Problem Summary: ### Release note None ### Check List (For Author) - Test <!-- At least one of them must be included. --> - [ ] Regression test - [ ] Unit Test - [ ] Manual test (add detailed scripts or steps below) - [ ] No need to test or manual test. Explain why: - [ ] This is a refactor/code format and no logic has been changed. - [ ] Previous test can cover this change. - [ ] No code files have been changed. - [ ] Other reason <!-- Add your reason? --> - Behavior changed: - [ ] No. - [ ] Yes. <!-- Explain the behavior change --> - Does this need documentation? - [ ] No. - [ ] Yes. <!-- Add document PR link here. eg: apache/doris-website#1214 --> ### Check List (For Reviewer who merge this PR) - [ ] Confirm the release note - [ ] Confirm test cases - [ ] Confirm document - [ ] Add branch pick label <!-- Add branch pick label that this PR should merge into -->
What problem does this PR solve?
my_double_round did not handle NaN values correctly. For example, when dec is very large and value is 0, there will be a case of 0 * inf, resulting in a NaN value.
do_format_round assumes the input is always a valid double value, which causes a core dump when a NaN is passed in.
Additionally,
(value.size() - (is_positive ? (decimal_places + 2) : (decimal_places + 3))) / 3;
This code does not account for the situation where value.size() is 0.
Currently, a custom add_thousands_separator function is implemented. If the fmt library is upgraded in the future, we should use fmt to add thousands separators.
Release note
None
Check List (For Author)
Test
Behavior changed:
Does this need documentation?
Check List (For Reviewer who merge this PR)