Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions be/src/exprs/string_functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,16 @@ class StringFunctions {
};

static StringVal do_money_format(FunctionContext *context, const std::string& v) {
std::locale comma_locale(std::locale(), new CommaMoneypunct ());
std::stringstream ss;
ss.imbue(comma_locale);
static std::locale comma_locale(std::locale(), new CommaMoneypunct());
static std::stringstream ss;
static bool ss_init = false;
if (UNLIKELY(!ss_init)) {
ss.imbue(comma_locale);
ss_init = true;
}
static std::string empty_string;
ss.str(empty_string);

ss << std::put_money(v);
return AnyValUtil::from_string_temp(context, ss.str());
};
Expand Down
10 changes: 10 additions & 0 deletions be/test/exprs/string_functions_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@ class StringFunctionsTest : public testing::Test {
FunctionContext* ctx;
};

TEST_F(StringFunctionsTest, do_money_format_bench) {
doris_udf::FunctionContext* context = new doris_udf::FunctionContext();
StringVal expected = AnyValUtil::from_string_temp(context, std::string("9,223,372,036,854,775,807.00"));
for (int i = 0; i < 10000000; i++) {
StringVal result = StringFunctions::do_money_format(context, "922337203685477580700"); // cent
ASSERT_EQ(expected, result);
}
delete context;
}

TEST_F(StringFunctionsTest, money_format_bigint) {
doris_udf::FunctionContext* context = new doris_udf::FunctionContext();

Expand Down