[Bug][Optimize] Fix race condition problem and optimize do_money_format function (#6350)
* [Bug][Optimize] Fix race condition problem and optimize do_money_format function Co-authored-by: caiconghui <caiconghui@xiaomi.com>
This commit is contained in:
@ -880,8 +880,10 @@ StringVal StringFunctions::money_format(FunctionContext* context, const DoubleVa
|
||||
return StringVal::null();
|
||||
}
|
||||
|
||||
double v_cent = MathFunctions::my_double_round(v.val, 2, false, false) * 100;
|
||||
return do_money_format(context, std::to_string(v_cent));
|
||||
double v_cent = MathFunctions::my_double_round(v.val, 2, false, false);
|
||||
bool negative = v_cent < 0;
|
||||
int32_t frac_value = negative ? ((int64_t) (-v_cent * 100)) % 100 : ((int64_t)(v_cent * 100)) % 100;
|
||||
return do_money_format<int64_t, 26>(context, (int64_t) v_cent , frac_value);
|
||||
}
|
||||
|
||||
StringVal StringFunctions::money_format(FunctionContext* context, const DecimalV2Val& v) {
|
||||
@ -891,25 +893,21 @@ StringVal StringFunctions::money_format(FunctionContext* context, const DecimalV
|
||||
|
||||
DecimalV2Value rounded(0);
|
||||
DecimalV2Value::from_decimal_val(v).round(&rounded, 2, HALF_UP);
|
||||
DecimalV2Value tmp(std::string_view("100"));
|
||||
DecimalV2Value result = rounded * tmp;
|
||||
return do_money_format(context, result.to_string());
|
||||
return do_money_format<int64_t, 26>(context, rounded.int_value(), abs(rounded.frac_value()));
|
||||
}
|
||||
|
||||
StringVal StringFunctions::money_format(FunctionContext* context, const BigIntVal& v) {
|
||||
if (v.is_null) {
|
||||
return StringVal::null();
|
||||
}
|
||||
|
||||
return do_money_format(context, fmt::format("{}00", v.val, "00"));
|
||||
return do_money_format<int64_t, 26>(context, v.val);
|
||||
}
|
||||
|
||||
StringVal StringFunctions::money_format(FunctionContext* context, const LargeIntVal& v) {
|
||||
if (v.is_null) {
|
||||
return StringVal::null();
|
||||
}
|
||||
|
||||
return do_money_format(context, fmt::format("{}00", v.val, "00"));
|
||||
return do_money_format<__int128_t, 52>(context, v.val);
|
||||
}
|
||||
|
||||
static int index_of(const uint8_t* source, int source_offset, int source_count,
|
||||
|
||||
Reference in New Issue
Block a user