Gabriel39 commented on code in PR #16427:
URL: https://github.com/apache/doris/pull/16427#discussion_r1097086147
##########
be/src/vec/core/types.h:
##########
@@ -325,6 +341,44 @@ struct Decimal {
return *this;
}
+ std::string to_string(UInt32 scale) const {
+ static constexpr auto precision =
+ std::is_same_v<T, Int32> ? 9 : (std::is_same_v<T, Int64> ? 18
: 38);
Review Comment:
Use `BeConsts::MAX_DECIMAL32_PRECISION / MAX_DECIMAL64_PRECISION /
MAX_DECIMAL128_PRECISION` to replace `9 / 18 / 38`
##########
be/src/vec/core/types.h:
##########
@@ -325,6 +341,44 @@ struct Decimal {
return *this;
}
+ std::string to_string(UInt32 scale) const {
+ static constexpr auto precision =
+ std::is_same_v<T, Int32> ? 9 : (std::is_same_v<T, Int64> ? 18
: 38);
+ bool is_nagetive = value < 0;
+ int max_result_length = precision + (scale > 0) // Add a space for
decimal place
+ + (scale == precision) // Add a space for
leading 0
+ + (is_nagetive); // Add a space for
negative sign
+ std::string str = std::string(max_result_length, '0');
+
+ T abs_value = value;
+ int pos = 0;
+
+ if (is_nagetive) {
+ abs_value = -value;
Review Comment:
The result is unexpected if `value` is a min value of a signed numeric type
--
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]