-
Notifications
You must be signed in to change notification settings - Fork 409
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
fix: format throw data truncated error #5272
Changes from 7 commits
c99bc07
d21ac2f
be0699b
ba3b1c1
2e49d56
726e12f
40f1a4d
8d6c677
339014a
e931521
3f5e6df
58e7a98
01dd580
107e110
ca01708
dba518e
50f4598
d6e8f15
ee26f15
aeab46a
ceac0fd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4565,6 +4565,9 @@ class FormatImpl : public IFunction | |
const auto & number_base_type = block.getByPosition(arguments[0]).type; | ||
const auto & precision_base_type = block.getByPosition(arguments[1]).type; | ||
|
||
auto precision_base_col = block.getByPosition(arguments[1]).column; | ||
auto precision_base_col_size = precision_base_col->size(); | ||
|
||
auto col_res = ColumnString::create(); | ||
auto val_num = block.getByPosition(arguments[0]).column->size(); | ||
|
||
|
@@ -4573,7 +4576,14 @@ class FormatImpl : public IFunction | |
using NumberFieldType = typename NumberType::FieldType; | ||
using NumberColVec = std::conditional_t<IsDecimal<NumberFieldType>, ColumnDecimal<NumberFieldType>, ColumnVector<NumberFieldType>>; | ||
const auto * number_raw = block.getByPosition(arguments[0]).column.get(); | ||
TiDBDecimalRoundInfo info{number_type, number_type}; | ||
|
||
auto prec = getDecimalPrecision(number_type, 0); | ||
auto scale = getDecimalScale(number_type, 0); | ||
|
||
/// output_scale is the second parameter of the 'format' function | ||
auto output_scale = precision_base_col_size > 0 ? (*precision_base_col)[0].get<Int64>() : scale; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What happens if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Then you need to update |
||
output_scale = output_scale < 0 ? 0 : output_scale; /// Ensure output_scale >= 0 | ||
TiDBDecimalRoundInfo info{prec, scale, prec, output_scale}; | ||
|
||
return getPrecisionType(precision_base_type, [&](const auto & precision_type, bool) { | ||
using PrecisionType = std::decay_t<decltype(precision_type)>; | ||
|
@@ -4612,6 +4622,7 @@ class FormatImpl : public IFunction | |
for (size_t i = 0; i != val_num; ++i) | ||
{ | ||
size_t max_num_decimals = getMaxNumDecimals(precision_array[i]); | ||
info.setOutputScale(max_num_decimals); | ||
format(number_array[i], max_num_decimals, info, col_res->getChars(), col_res->getOffsets()); | ||
} | ||
} | ||
|
@@ -4700,7 +4711,7 @@ class FormatImpl : public IFunction | |
static std::string number2Str(T number, const TiDBDecimalRoundInfo & info [[maybe_unused]]) | ||
{ | ||
if constexpr (IsDecimal<T>) | ||
return number.toString(info.output_scale); | ||
return number.toString(std::min(info.input_scale, info.output_scale)); | ||
else | ||
{ | ||
static_assert(std::is_floating_point_v<T> || std::is_integral_v<T>); | ||
|
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.
why remove this?