Skip to content

fix(cast): correct scientific notation string to decimal parsing (#63085)#63135

Open
leonard9893 wants to merge 2 commits into
apache:masterfrom
leonard9893:fix/63085-sci-notation-decimal
Open

fix(cast): correct scientific notation string to decimal parsing (#63085)#63135
leonard9893 wants to merge 2 commits into
apache:masterfrom
leonard9893:fix/63085-sci-notation-decimal

Conversation

@leonard9893
Copy link
Copy Markdown

Problem

CAST('1.4E+4' AS DECIMAL(38, 15)) returns 14.000... instead of 14000.000... in Doris 4.0.5 (regression from 2.1).

Root Cause

be/src/util/string_parser.cppstring_to_decimal function at line 191 uses a loop variable i that was contaminated by the exponent parsing loop, instead of the preserved end_digit_index.

Introduced by commit c108263.

Fix

Replace i with end_digit_index on line 191.

Fixes #63085

…x instead of reused loop variable i

Signed-off-by: leonard9893 <leonard9893@gmail.com>
…ction

Signed-off-by: leonard9893 <leonard9893@gmail.com>
@hello-stephen
Copy link
Copy Markdown
Contributor

Thank you for your contribution to Apache Doris.
Don't know what should be done next? See How to process your PR.

Please clearly describe your PR:

  1. What problem was fixed (it's best to include specific error reporting information). How it was fixed.
  2. Which behaviors were modified. What was the previous behavior, what is it now, why was it modified, and what possible impacts might there be.
  3. What features were added. Why was this function added?
  4. Which code was refactored and why was this part of the code refactored?
  5. Which functions were optimized and what is the difference before and after the optimization?

@leonard9893
Copy link
Copy Markdown
Author

Hi @apache/doris-committers, this PR fixes a regression in DECIMAL parsing of scientific notation introduced by #60004.

CAST('1.4E+4' AS DECIMAL(38,15)) currently returns 14.000... instead of 14000.000... because the loop variable i was contaminated by the exponent parsing loop.

The fix is a one-line change replacing reused i with the preserved end_digit_index in be/src/util/string_parser.cpp. Could someone please take a look? Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Doris 4.0.5 CAST string scientific notation to DECIMAL returns incorrect result

2 participants