github-actions[bot] commented on code in PR #63322:
URL: https://github.com/apache/doris/pull/63322#discussion_r3254468041
##########
be/src/util/json/json_parser.h:
##########
@@ -39,8 +39,47 @@
namespace doris {
+inline bool should_preserve_json_number_as_string(std::string_view raw_number)
{
+ size_t significant_digits = 0;
+ size_t fractional_digits = 0;
+ bool seen_nonzero_digit = false;
+ bool seen_dot = false;
+ bool seen_exponent = false;
+
+ for (size_t i = 0; i < raw_number.size(); ++i) {
+ const char ch = raw_number[i];
+ if (ch == 'e' || ch == 'E') {
+ seen_exponent = true;
+ if (i + 1 < raw_number.size() &&
+ (raw_number[i + 1] == '-' || raw_number[i + 1] == '+')) {
+ ++i;
+ }
+ continue;
+ }
+ if (seen_exponent) {
+ continue;
+ }
+ if (ch == '.') {
+ seen_dot = true;
+ continue;
+ }
+ if (ch < '0' || ch > '9') {
+ continue;
+ }
+ if (seen_dot) {
+ ++fractional_digits;
+ }
+ if (ch != '0' || seen_nonzero_digit) {
+ seen_nonzero_digit = true;
+ ++significant_digits;
+ }
+ }
+
+ return significant_digits > 15 || fractional_digits >= 10;
+}
Review Comment:
This heuristic still lets typed decimal paths lose precision for
scientific-notation tokens because it stops counting once it sees `e`/`E` and
never accounts for the exponent magnitude. For example, with a
`decimalv3(38,10)` typed path, `9.999999999e27` has only 10 mantissa
significant digits and 9 fractional digits before the exponent, so this returns
false; `getValueAsField()` then stores a `TYPE_DOUBLE`, and the later decimal
cast uses the rounded double instead of the original JSON token. Please
preserve the raw token for exponent-form decimal typed-path numbers as well, or
preserve raw numeric text for all double typed-path values before casting to
decimal.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]