diff --git a/be/src/exprs/math_functions.cpp b/be/src/exprs/math_functions.cpp index 66a23cee0b42ec..7f02e508129f35 100644 --- a/be/src/exprs/math_functions.cpp +++ b/be/src/exprs/math_functions.cpp @@ -69,7 +69,7 @@ const double log_10[] = { #define ARRAY_ELEMENTS(A) ((uint64_t) (sizeof(A)/sizeof(A[0]))) -static double my_double_round(double value, int64_t dec, bool dec_unsigned, bool truncate) { +double MathFunctions::my_double_round(double value, int64_t dec, bool dec_unsigned, bool truncate) { bool dec_negative = (dec < 0) && !dec_unsigned; uint64_t abs_dec = dec_negative ? -dec : dec; /* diff --git a/be/src/exprs/math_functions.h b/be/src/exprs/math_functions.h index 7ee8466e8b5b60..6ed9fb6fc3674c 100644 --- a/be/src/exprs/math_functions.h +++ b/be/src/exprs/math_functions.h @@ -172,6 +172,9 @@ class MathFunctions { doris_udf::FunctionContext* ctx, int num_args, const doris_udf::DecimalV2Val* val); static doris_udf::DecimalV2Val greatest( doris_udf::FunctionContext* ctx, int num_args, const doris_udf::DecimalV2Val* val); + + static double my_double_round(double value, int64_t dec, bool dec_unsigned, bool truncate); + private: static const int32_t MIN_BASE = 2; static const int32_t MAX_BASE = 36; diff --git a/be/src/exprs/string_functions.cpp b/be/src/exprs/string_functions.cpp index b0961d11f22690..7214b0bd819d8d 100644 --- a/be/src/exprs/string_functions.cpp +++ b/be/src/exprs/string_functions.cpp @@ -24,6 +24,7 @@ #include "runtime/string_value.hpp" #include "runtime/tuple_row.h" #include "util/url_parser.h" +#include "math_functions.h" // NOTE: be careful not to use string::append. It is not performant. namespace doris { @@ -707,4 +708,57 @@ StringVal StringFunctions::parse_url_key( return result_sv; } +StringVal StringFunctions::money_format(FunctionContext* context, const DoubleVal& v) { + if (v.is_null) { + 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)); +} + +StringVal StringFunctions::money_format(FunctionContext *context, const DecimalVal &v) { + if (v.is_null) { + return StringVal::null(); + } + + DecimalValue rounded; + DecimalValue::from_decimal_val(v).round(&rounded, 2, HALF_UP); + DecimalValue tmp(std::string("100")); + DecimalValue result = rounded * tmp; + return do_money_format(context, result.to_string()); +} + +StringVal StringFunctions::money_format(FunctionContext *context, const DecimalV2Val &v) { + if (v.is_null) { + return StringVal::null(); + } + + DecimalV2Value rounded; + DecimalV2Value::from_decimal_val(v).round(&rounded, 2, HALF_UP); + DecimalV2Value tmp(std::string("100")); + DecimalV2Value result = rounded * tmp; + return do_money_format(context, result.to_string()); +} + + +StringVal StringFunctions::money_format(FunctionContext *context, const BigIntVal &v) { + if (v.is_null) { + return StringVal::null(); + } + + std::string cent_money = std::to_string(v.val) + std::string("00"); + return do_money_format(context, cent_money); +} + +StringVal StringFunctions::money_format(FunctionContext *context, const LargeIntVal &v) { + if (v.is_null) { + return StringVal::null(); + } + + std::stringstream ss; + ss << v.val << "00"; + return do_money_format(context, ss.str()); +} + } diff --git a/be/src/exprs/string_functions.h b/be/src/exprs/string_functions.h index 22bdcf7b4557b0..a4ca3a769d951e 100644 --- a/be/src/exprs/string_functions.h +++ b/be/src/exprs/string_functions.h @@ -22,6 +22,10 @@ #include "runtime/string_value.h" #include "runtime/string_search.hpp" +#include "anyval_util.h" +#include +#include +#include namespace doris { @@ -137,8 +141,40 @@ class StringFunctions { static void parse_url_close( doris_udf::FunctionContext*, doris_udf::FunctionContext::FunctionStateScope); -}; + + static doris_udf::StringVal money_format(doris_udf::FunctionContext* context, + const doris_udf::DoubleVal& v); + + static doris_udf::StringVal money_format(doris_udf::FunctionContext* context, + const doris_udf::DecimalVal& v); + + static doris_udf::StringVal money_format(doris_udf::FunctionContext* context, + const doris_udf::DecimalV2Val& v); + + static doris_udf::StringVal money_format(doris_udf::FunctionContext* context, + const doris_udf::BigIntVal& v); + + static doris_udf::StringVal money_format(doris_udf::FunctionContext* context, + const doris_udf::LargeIntVal& v); + + struct CommaMoneypunct : std::moneypunct { + pattern do_pos_format() const override { return {{none, sign, none, value}}; } + pattern do_neg_format() const override { return {{none, sign, none, value}}; } + int do_frac_digits() const override { return 2; } + char_type do_thousands_sep() const override { return ','; } + string_type do_grouping() const override { return "\003"; } + string_type do_negative_sign() const override { return "-"; } + }; + + 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); + ss << std::put_money(v); + return AnyValUtil::from_string_temp(context, ss.str()); + }; +}; } #endif diff --git a/be/test/exprs/CMakeLists.txt b/be/test/exprs/CMakeLists.txt index fabf066b1c3c69..0aaa2804eb748a 100644 --- a/be/test/exprs/CMakeLists.txt +++ b/be/test/exprs/CMakeLists.txt @@ -26,4 +26,5 @@ ADD_BE_TEST(json_function_test) #ADD_BE_TEST(in_predicate_test) #ADD_BE_TEST(expr-test) ADD_BE_TEST(hybird_set_test) +ADD_BE_TEST(string_functions_test) #ADD_BE_TEST(in-predicate-test) diff --git a/be/test/exprs/string_functions_test.cpp b/be/test/exprs/string_functions_test.cpp new file mode 100644 index 00000000000000..e0e355505df657 --- /dev/null +++ b/be/test/exprs/string_functions_test.cpp @@ -0,0 +1,132 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#include "exprs/string_functions.h" +#include "util/logging.h" +#include "exprs/anyval_util.h" +#include +#include + +#include + +namespace doris { + +class StringFunctionsTest : public testing::Test { +public: + StringFunctionsTest() { + } +}; + +TEST_F(StringFunctionsTest, money_format_bigint) { + doris_udf::FunctionContext* context = new doris_udf::FunctionContext(); + + StringVal result = StringFunctions::money_format(context, doris_udf::BigIntVal(123456)); + StringVal expected = AnyValUtil::from_string_temp(context, std::string("123,456.00")); + ASSERT_EQ(expected, result); + + result = StringFunctions::money_format(context, doris_udf::BigIntVal(-123456)); + expected = AnyValUtil::from_string_temp(context, std::string("-123,456.00")); + ASSERT_EQ(expected, result); + + result = StringFunctions::money_format(context, doris_udf::BigIntVal(9223372036854775807)); + expected = AnyValUtil::from_string_temp(context, std::string("9,223,372,036,854,775,807.00")); + ASSERT_EQ(expected, result); +} + +TEST_F(StringFunctionsTest, money_format_large_int) { + doris_udf::FunctionContext* context = new doris_udf::FunctionContext(); + + std::string str("170141183460469231731687303715884105727"); + std::stringstream ss; + ss << str; + __int128 value; + ss >> value; + + std::cout << "value: " << value << std::endl; + + StringVal result = StringFunctions::money_format(context, doris_udf::LargeIntVal(value)); + StringVal expected = AnyValUtil::from_string_temp(context, std::string("170,141,183,460,469,231,731,687,303,715,884,105,727.00")); + ASSERT_EQ(expected, result); +} + +TEST_F(StringFunctionsTest, money_format_double) { + doris_udf::FunctionContext* context = new doris_udf::FunctionContext(); + + StringVal result = StringFunctions::money_format(context, doris_udf::DoubleVal(1234.456)); + StringVal expected = AnyValUtil::from_string_temp(context, std::string("1,234.46")); + ASSERT_EQ(expected, result); + + result = StringFunctions::money_format(context, doris_udf::DoubleVal(1234.45)); + expected = AnyValUtil::from_string_temp(context, std::string("1,234.45")); + ASSERT_EQ(expected, result); + + result = StringFunctions::money_format(context, doris_udf::DoubleVal(1234.4)); + expected = AnyValUtil::from_string_temp(context, std::string("1,234.40")); + ASSERT_EQ(expected, result); + + result = StringFunctions::money_format(context, doris_udf::DoubleVal(1234.454)); + expected = AnyValUtil::from_string_temp(context, std::string("1,234.45")); + ASSERT_EQ(expected, result); +} + +TEST_F(StringFunctionsTest, money_format_decimal) { + doris_udf::FunctionContext* context = new doris_udf::FunctionContext(); + + DecimalValue dv1(std::string("3333333333.2222222222")); + DecimalVal value1; + dv1.to_decimal_val(&value1); + + StringVal result = StringFunctions::money_format(context, value1); + StringVal expected = AnyValUtil::from_string_temp(context, std::string("3,333,333,333.22")); + ASSERT_EQ(expected, result); + + DecimalValue dv2(std::string("-7407407406790123456.71604938271975308642")); + DecimalVal value2; + dv2.to_decimal_val(&value2); + + result = StringFunctions::money_format(context, value2); + expected = AnyValUtil::from_string_temp(context, std::string("-7,407,407,406,790,123,456.72")); + ASSERT_EQ(expected, result); +} + +TEST_F(StringFunctionsTest, money_format_decimal_v2) { + doris_udf::FunctionContext* context = new doris_udf::FunctionContext(); + + DecimalV2Value dv1(std::string("3333333333.2222222222")); + DecimalV2Val value1; + dv1.to_decimal_val(&value1); + + StringVal result = StringFunctions::money_format(context, value1); + StringVal expected = AnyValUtil::from_string_temp(context, std::string("3,333,333,333.22")); + ASSERT_EQ(expected, result); + + DecimalV2Value dv2(std::string("-740740740.71604938271975308642")); + DecimalV2Val value2; + dv2.to_decimal_val(&value2); + + result = StringFunctions::money_format(context, value2); + expected = AnyValUtil::from_string_temp(context, std::string("-740,740,740.72")); + ASSERT_EQ(expected, result); +} + +} + +int main(int argc, char** argv) { + doris::init_glog("be-test"); + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} diff --git a/docs/documentation/cn/sql-reference/sql-functions/string-functions/money_format.md b/docs/documentation/cn/sql-reference/sql-functions/string-functions/money_format.md new file mode 100644 index 00000000000000..98da921327d4dd --- /dev/null +++ b/docs/documentation/cn/sql-reference/sql-functions/string-functions/money_format.md @@ -0,0 +1,34 @@ +# money_format + +## Syntax + +VARCHAR money_format(Number) + +## Description + +将数字按照货币格式输出,整数部分每隔3位用逗号分隔,小数部分保留2位 + +## Examples + +``` +mysql> select money_format(17014116); ++------------------------+ +| money_format(17014116) | ++------------------------+ +| 17,014,116.00 | ++------------------------+ + +mysql> select money_format(1123.456); ++------------------------+ +| money_format(1123.456) | ++------------------------+ +| 1,123.46 | ++------------------------+ + +mysql> select money_format(1123.4); ++----------------------+ +| money_format(1123.4) | ++----------------------+ +| 1,123.40 | ++----------------------+ +``` diff --git a/gensrc/script/doris_builtins_functions.py b/gensrc/script/doris_builtins_functions.py index ad298f5eddc08c..1754ed498e1114 100755 --- a/gensrc/script/doris_builtins_functions.py +++ b/gensrc/script/doris_builtins_functions.py @@ -32,13 +32,13 @@ visible_functions = [ # Bit and Byte functions # For functions corresponding to builtin operators, we can reuse the implementations - [['bitand'], 'TINYINT', ['TINYINT', 'TINYINT'], + [['bitand'], 'TINYINT', ['TINYINT', 'TINYINT'], '_ZN5doris9Operators32bitand_tiny_int_val_tiny_int_valEPN9doris_udf' '15FunctionContextERKNS1_10TinyIntValES6_'], - [['bitand'], 'SMALLINT', ['SMALLINT', 'SMALLINT'], + [['bitand'], 'SMALLINT', ['SMALLINT', 'SMALLINT'], '_ZN5doris9Operators34bitand_small_int_val_small_int_valEPN9doris_udf' '15FunctionContextERKNS1_11SmallIntValES6_'], - [['bitand'], 'INT', ['INT', 'INT'], + [['bitand'], 'INT', ['INT', 'INT'], '_ZN5doris9Operators22bitand_int_val_int_valEPN9doris_udf' '15FunctionContextERKNS1_6IntValES6_'], [['bitand'], 'BIGINT', ['BIGINT', 'BIGINT'], @@ -48,35 +48,35 @@ '_ZN5doris9Operators34bitand_large_int_val_large_int_valEPN9doris_udf' '15FunctionContextERKNS1_11LargeIntValES6_'], - [['bitor'], 'TINYINT', ['TINYINT', 'TINYINT'], + [['bitor'], 'TINYINT', ['TINYINT', 'TINYINT'], '_ZN5doris9Operators31bitor_tiny_int_val_tiny_int_valEPN9doris_udf' '15FunctionContextERKNS1_10TinyIntValES6_'], - [['bitor'], 'SMALLINT', ['SMALLINT', 'SMALLINT'], + [['bitor'], 'SMALLINT', ['SMALLINT', 'SMALLINT'], '_ZN5doris9Operators33bitor_small_int_val_small_int_valEPN9doris_udf' '15FunctionContextERKNS1_11SmallIntValES6_'], - [['bitor'], 'INT', ['INT', 'INT'], + [['bitor'], 'INT', ['INT', 'INT'], '_ZN5doris9Operators21bitor_int_val_int_valEPN9doris_udf' '15FunctionContextERKNS1_6IntValES6_'], - [['bitor'], 'BIGINT', ['BIGINT', 'BIGINT'], + [['bitor'], 'BIGINT', ['BIGINT', 'BIGINT'], '_ZN5doris9Operators29bitor_big_int_val_big_int_valEPN9doris_udf' '15FunctionContextERKNS1_9BigIntValES6_'], - [['bitor'], 'LARGEINT', ['LARGEINT', 'LARGEINT'], + [['bitor'], 'LARGEINT', ['LARGEINT', 'LARGEINT'], '_ZN5doris9Operators33bitor_large_int_val_large_int_valEPN9doris_udf' '15FunctionContextERKNS1_11LargeIntValES6_'], - [['bitxor'], 'TINYINT', ['TINYINT', 'TINYINT'], + [['bitxor'], 'TINYINT', ['TINYINT', 'TINYINT'], '_ZN5doris9Operators32bitxor_tiny_int_val_tiny_int_valEPN9doris_udf' '15FunctionContextERKNS1_10TinyIntValES6_'], - [['bitxor'], 'SMALLINT', ['SMALLINT', 'SMALLINT'], + [['bitxor'], 'SMALLINT', ['SMALLINT', 'SMALLINT'], '_ZN5doris9Operators34bitxor_small_int_val_small_int_valEPN9doris_udf' '15FunctionContextERKNS1_11SmallIntValES6_'], - [['bitxor'], 'INT', ['INT', 'INT'], + [['bitxor'], 'INT', ['INT', 'INT'], '_ZN5doris9Operators22bitxor_int_val_int_valEPN9doris_udf' '15FunctionContextERKNS1_6IntValES6_'], - [['bitxor'], 'BIGINT', ['BIGINT', 'BIGINT'], + [['bitxor'], 'BIGINT', ['BIGINT', 'BIGINT'], '_ZN5doris9Operators30bitxor_big_int_val_big_int_valEPN9doris_udf' '15FunctionContextERKNS1_9BigIntValES6_'], - [['bitxor'], 'LARGEINT', ['LARGEINT', 'LARGEINT'], + [['bitxor'], 'LARGEINT', ['LARGEINT', 'LARGEINT'], '_ZN5doris9Operators34bitxor_large_int_val_large_int_valEPN9doris_udf' '15FunctionContextERKNS1_11LargeIntValES6_'], @@ -86,60 +86,60 @@ [['bitnot'], 'SMALLINT', ['SMALLINT'], '_ZN5doris9Operators20bitnot_small_int_valEPN9doris_udf' '15FunctionContextERKNS1_11SmallIntValE'], - [['bitnot'], 'INT', ['INT'], + [['bitnot'], 'INT', ['INT'], '_ZN5doris9Operators14bitnot_int_valEPN9doris_udf' '15FunctionContextERKNS1_6IntValE'], - [['bitnot'], 'BIGINT', ['BIGINT'], + [['bitnot'], 'BIGINT', ['BIGINT'], '_ZN5doris9Operators18bitnot_big_int_valEPN9doris_udf' '15FunctionContextERKNS1_9BigIntValE'], - [['bitnot'], 'LARGEINT', ['LARGEINT'], + [['bitnot'], 'LARGEINT', ['LARGEINT'], '_ZN5doris9Operators20bitnot_large_int_valEPN9doris_udf' '15FunctionContextERKNS1_11LargeIntValE'], # Timestamp functions - [['unix_timestamp'], 'INT', [], + [['unix_timestamp'], 'INT', [], '_ZN5doris18TimestampFunctions7to_unixEPN9doris_udf15FunctionContextE'], - [['unix_timestamp'], 'INT', ['DATETIME'], + [['unix_timestamp'], 'INT', ['DATETIME'], '_ZN5doris18TimestampFunctions7to_unixEPN9doris_udf15FunctionContextERKNS1_11DateTimeValE'], - [['unix_timestamp'], 'INT', ['VARCHAR', 'VARCHAR'], + [['unix_timestamp'], 'INT', ['VARCHAR', 'VARCHAR'], '_ZN5doris18TimestampFunctions7to_unixEPN9doris_udf15FunctionContextERKNS1_9StringValES6_'], [['from_unixtime'], 'VARCHAR', ['INT'], '_ZN5doris18TimestampFunctions9from_unixEPN9doris_udf15FunctionContextERKNS1_6IntValE'], [['from_unixtime'], 'VARCHAR', ['INT', 'VARCHAR'], '_ZN5doris18TimestampFunctions9from_unixEPN9doris_udf' '15FunctionContextERKNS1_6IntValERKNS1_9StringValE'], - [['now', 'current_timestamp'], 'DATETIME', [], + [['now', 'current_timestamp'], 'DATETIME', [], '_ZN5doris18TimestampFunctions3nowEPN9doris_udf15FunctionContextE'], - [['curtime', 'current_time'], 'DATETIME', [], + [['curtime', 'current_time'], 'DATETIME', [], '_ZN5doris18TimestampFunctions7curtimeEPN9doris_udf15FunctionContextE'], - [['timestamp'], 'DATETIME', ['DATETIME'], + [['timestamp'], 'DATETIME', ['DATETIME'], '_ZN5doris18TimestampFunctions9timestampEPN9doris_udf15FunctionContextERKNS1_11DateTimeValE'], - [['from_days'], 'DATE', ['INT'], + [['from_days'], 'DATE', ['INT'], '_ZN5doris18TimestampFunctions9from_daysEPN9doris_udf15FunctionContextERKNS1_6IntValE'], - [['to_days'], 'INT', ['DATE'], + [['to_days'], 'INT', ['DATE'], '_ZN5doris18TimestampFunctions7to_daysEPN9doris_udf15FunctionContextERKNS1_11DateTimeValE'], - [['year'], 'INT', ['DATETIME'], + [['year'], 'INT', ['DATETIME'], '_ZN5doris18TimestampFunctions4yearEPN9doris_udf15FunctionContextERKNS1_11DateTimeValE'], - [['month'], 'INT', ['DATETIME'], + [['month'], 'INT', ['DATETIME'], '_ZN5doris18TimestampFunctions5monthEPN9doris_udf15FunctionContextERKNS1_11DateTimeValE'], - [['quarter'], 'INT', ['DATETIME'], + [['quarter'], 'INT', ['DATETIME'], '_ZN5doris18TimestampFunctions7quarterEPN9doris_udf15FunctionContextERKNS1_11DateTimeValE'], - [['day', 'dayofmonth'], 'INT', ['DATETIME'], + [['day', 'dayofmonth'], 'INT', ['DATETIME'], '_ZN5doris18TimestampFunctions12day_of_monthEPN9doris_udf' '15FunctionContextERKNS1_11DateTimeValE'], - [['dayofyear'], 'INT', ['DATETIME'], + [['dayofyear'], 'INT', ['DATETIME'], '_ZN5doris18TimestampFunctions11day_of_yearEPN9doris_udf' '15FunctionContextERKNS1_11DateTimeValE'], - [['weekofyear'], 'INT', ['DATETIME'], + [['weekofyear'], 'INT', ['DATETIME'], '_ZN5doris18TimestampFunctions12week_of_yearEPN9doris_udf' '15FunctionContextERKNS1_11DateTimeValE'], - [['hour'], 'INT', ['DATETIME'], + [['hour'], 'INT', ['DATETIME'], '_ZN5doris18TimestampFunctions4hourEPN9doris_udf15FunctionContextERKNS1_11DateTimeValE'], - [['minute'], 'INT', ['DATETIME'], + [['minute'], 'INT', ['DATETIME'], '_ZN5doris18TimestampFunctions6minuteEPN9doris_udf15FunctionContextERKNS1_11DateTimeValE'], - [['second'], 'INT', ['DATETIME'], + [['second'], 'INT', ['DATETIME'], '_ZN5doris18TimestampFunctions6secondEPN9doris_udf15FunctionContextERKNS1_11DateTimeValE'], [['years_add'], 'DATETIME', ['DATETIME', 'INT'], @@ -191,10 +191,10 @@ '_ZN5doris18TimestampFunctions10micros_subEPN9doris_udf' '15FunctionContextERKNS1_11DateTimeValERKNS1_6IntValE'], - [['datediff'], 'INT', ['DATETIME', 'DATETIME'], + [['datediff'], 'INT', ['DATETIME', 'DATETIME'], '_ZN5doris18TimestampFunctions9date_diffEPN9doris_udf' '15FunctionContextERKNS1_11DateTimeValES6_'], - [['timediff'], 'DATETIME', ['DATETIME', 'DATETIME'], + [['timediff'], 'DATETIME', ['DATETIME', 'DATETIME'], '_ZN5doris18TimestampFunctions9time_diffEPN9doris_udf' '15FunctionContextERKNS1_11DateTimeValES6_'], @@ -204,90 +204,90 @@ [['date_format'], 'VARCHAR', ['DATETIME', 'VARCHAR'], '_ZN5doris18TimestampFunctions11date_formatEPN9doris_udf' '15FunctionContextERKNS1_11DateTimeValERKNS1_9StringValE'], - [['date', 'to_date'], 'DATE', ['DATETIME'], + [['date', 'to_date'], 'DATE', ['DATETIME'], '_ZN5doris18TimestampFunctions7to_dateEPN9doris_udf15FunctionContextERKNS1_11DateTimeValE'], - [['dayname'], 'VARCHAR', ['DATETIME'], + [['dayname'], 'VARCHAR', ['DATETIME'], '_ZN5doris18TimestampFunctions8day_nameEPN9doris_udf' '15FunctionContextERKNS1_11DateTimeValE'], - [['monthname'], 'VARCHAR', ['DATETIME'], + [['monthname'], 'VARCHAR', ['DATETIME'], '_ZN5doris18TimestampFunctions10month_nameEPN9doris_udf' '15FunctionContextERKNS1_11DateTimeValE'], # Math builtin functions - [['pi'], 'DOUBLE', [], + [['pi'], 'DOUBLE', [], '_ZN5doris13MathFunctions2piEPN9doris_udf15FunctionContextE'], - [['e'], 'DOUBLE', [], + [['e'], 'DOUBLE', [], '_ZN5doris13MathFunctions1eEPN9doris_udf15FunctionContextE'], - [['abs'], 'DOUBLE', ['DOUBLE'], + [['abs'], 'DOUBLE', ['DOUBLE'], '_ZN5doris13MathFunctions3absEPN9doris_udf15FunctionContextERKNS1_9DoubleValE'], - [['sign'], 'FLOAT', ['DOUBLE'], + [['sign'], 'FLOAT', ['DOUBLE'], '_ZN5doris13MathFunctions4signEPN9doris_udf15FunctionContextERKNS1_9DoubleValE'], - [['sin'], 'DOUBLE', ['DOUBLE'], + [['sin'], 'DOUBLE', ['DOUBLE'], '_ZN5doris13MathFunctions3sinEPN9doris_udf15FunctionContextERKNS1_9DoubleValE'], - [['asin'], 'DOUBLE', ['DOUBLE'], + [['asin'], 'DOUBLE', ['DOUBLE'], '_ZN5doris13MathFunctions4asinEPN9doris_udf15FunctionContextERKNS1_9DoubleValE'], - [['cos'], 'DOUBLE', ['DOUBLE'], + [['cos'], 'DOUBLE', ['DOUBLE'], '_ZN5doris13MathFunctions3cosEPN9doris_udf15FunctionContextERKNS1_9DoubleValE'], - [['acos'], 'DOUBLE', ['DOUBLE'], + [['acos'], 'DOUBLE', ['DOUBLE'], '_ZN5doris13MathFunctions4acosEPN9doris_udf15FunctionContextERKNS1_9DoubleValE'], - [['tan'], 'DOUBLE', ['DOUBLE'], + [['tan'], 'DOUBLE', ['DOUBLE'], '_ZN5doris13MathFunctions3tanEPN9doris_udf15FunctionContextERKNS1_9DoubleValE'], - [['atan'], 'DOUBLE', ['DOUBLE'], + [['atan'], 'DOUBLE', ['DOUBLE'], '_ZN5doris13MathFunctions4atanEPN9doris_udf15FunctionContextERKNS1_9DoubleValE'], - [['ceil', 'ceiling', 'dceil'], 'BIGINT', ['DOUBLE'], + [['ceil', 'ceiling', 'dceil'], 'BIGINT', ['DOUBLE'], '_ZN5doris13MathFunctions4ceilEPN9doris_udf15FunctionContextERKNS1_9DoubleValE'], [['floor', 'dfloor'], 'BIGINT', ['DOUBLE'], '_ZN5doris13MathFunctions5floorEPN9doris_udf15FunctionContextERKNS1_9DoubleValE'], [['round', 'dround'], 'BIGINT', ['DOUBLE'], '_ZN5doris13MathFunctions5roundEPN9doris_udf15FunctionContextERKNS1_9DoubleValE'], - [['round', 'dround'], 'DOUBLE', ['DOUBLE', 'INT'], + [['round', 'dround'], 'DOUBLE', ['DOUBLE', 'INT'], '_ZN5doris13MathFunctions11round_up_toEPN9doris_udf' '15FunctionContextERKNS1_9DoubleValERKNS1_6IntValE'], - [['truncate'], 'DOUBLE', ['DOUBLE', 'INT'], + [['truncate'], 'DOUBLE', ['DOUBLE', 'INT'], '_ZN5doris13MathFunctions8truncateEPN9doris_udf' '15FunctionContextERKNS1_9DoubleValERKNS1_6IntValE'], - [['ln', 'dlog1'], 'DOUBLE', ['DOUBLE'], + [['ln', 'dlog1'], 'DOUBLE', ['DOUBLE'], '_ZN5doris13MathFunctions2lnEPN9doris_udf15FunctionContextERKNS1_9DoubleValE'], - [['log'], 'DOUBLE', ['DOUBLE', 'DOUBLE'], + [['log'], 'DOUBLE', ['DOUBLE', 'DOUBLE'], '_ZN5doris13MathFunctions3logEPN9doris_udf15FunctionContextERKNS1_9DoubleValES6_'], - [['log2'], 'DOUBLE', ['DOUBLE'], + [['log2'], 'DOUBLE', ['DOUBLE'], '_ZN5doris13MathFunctions4log2EPN9doris_udf15FunctionContextERKNS1_9DoubleValE'], [['log10', 'dlog10'], 'DOUBLE', ['DOUBLE'], '_ZN5doris13MathFunctions5log10EPN9doris_udf15FunctionContextERKNS1_9DoubleValE'], - [['exp', 'dexp'], 'DOUBLE', ['DOUBLE'], + [['exp', 'dexp'], 'DOUBLE', ['DOUBLE'], '_ZN5doris13MathFunctions3expEPN9doris_udf15FunctionContextERKNS1_9DoubleValE'], - [['radians'], 'DOUBLE', ['DOUBLE'], + [['radians'], 'DOUBLE', ['DOUBLE'], '_ZN5doris13MathFunctions7radiansEPN9doris_udf15FunctionContextERKNS1_9DoubleValE'], - [['degrees'], 'DOUBLE', ['DOUBLE'], + [['degrees'], 'DOUBLE', ['DOUBLE'], '_ZN5doris13MathFunctions7degreesEPN9doris_udf15FunctionContextERKNS1_9DoubleValE'], [['sqrt', 'dsqrt'], 'DOUBLE', ['DOUBLE'], '_ZN5doris13MathFunctions4sqrtEPN9doris_udf15FunctionContextERKNS1_9DoubleValE'], - [['pow', 'power', 'dpow', 'fpow'], 'DOUBLE', ['DOUBLE', 'DOUBLE'], + [['pow', 'power', 'dpow', 'fpow'], 'DOUBLE', ['DOUBLE', 'DOUBLE'], '_ZN5doris13MathFunctions3powEPN9doris_udf15FunctionContextERKNS1_9DoubleValES6_'], - [['rand', 'random'], 'DOUBLE', [], + [['rand', 'random'], 'DOUBLE', [], '_ZN5doris13MathFunctions4randEPN9doris_udf15FunctionContextE', '_ZN5doris13MathFunctions12rand_prepareEPN9doris_udf' '15FunctionContextENS2_18FunctionStateScopeE'], - [['rand', 'random'], 'DOUBLE', ['BIGINT'], + [['rand', 'random'], 'DOUBLE', ['BIGINT'], '_ZN5doris13MathFunctions9rand_seedEPN9doris_udf15FunctionContextERKNS1_9BigIntValE', '_ZN5doris13MathFunctions12rand_prepareEPN9doris_udf' '15FunctionContextENS2_18FunctionStateScopeE'], - [['bin'], 'VARCHAR', ['BIGINT'], + [['bin'], 'VARCHAR', ['BIGINT'], '_ZN5doris13MathFunctions3binEPN9doris_udf15FunctionContextERKNS1_9BigIntValE'], - [['hex'], 'VARCHAR', ['BIGINT'], + [['hex'], 'VARCHAR', ['BIGINT'], '_ZN5doris13MathFunctions7hex_intEPN9doris_udf15FunctionContextERKNS1_9BigIntValE'], - [['hex'], 'VARCHAR', ['VARCHAR'], + [['hex'], 'VARCHAR', ['VARCHAR'], '_ZN5doris13MathFunctions10hex_stringEPN9doris_udf15FunctionContextERKNS1_9StringValE'], - [['unhex'], 'VARCHAR', ['VARCHAR'], + [['unhex'], 'VARCHAR', ['VARCHAR'], '_ZN5doris13MathFunctions5unhexEPN9doris_udf15FunctionContextERKNS1_9StringValE'], [['conv'], 'VARCHAR', ['BIGINT', 'TINYINT', 'TINYINT'], @@ -297,36 +297,36 @@ '_ZN5doris13MathFunctions11conv_stringEPN9doris_udf' '15FunctionContextERKNS1_9StringValERKNS1_10TinyIntValES9_'], - [['pmod'], 'BIGINT', ['BIGINT', 'BIGINT'], + [['pmod'], 'BIGINT', ['BIGINT', 'BIGINT'], '_ZN5doris13MathFunctions11pmod_bigintEPN9doris_udf' '15FunctionContextERKNS1_9BigIntValES6_'], - [['pmod'], 'DOUBLE', ['DOUBLE', 'DOUBLE'], + [['pmod'], 'DOUBLE', ['DOUBLE', 'DOUBLE'], '_ZN5doris13MathFunctions11pmod_doubleEPN9doris_udf' '15FunctionContextERKNS1_9DoubleValES6_'], - [['mod'], 'TINYINT', ['TINYINT', 'TINYINT'], + [['mod'], 'TINYINT', ['TINYINT', 'TINYINT'], '_ZN5doris9Operators29mod_tiny_int_val_tiny_int_valEPN9doris_udf' '15FunctionContextERKNS1_10TinyIntValES6_'], - [['mod'], 'SMALLINT', ['SMALLINT', 'SMALLINT'], + [['mod'], 'SMALLINT', ['SMALLINT', 'SMALLINT'], '_ZN5doris9Operators31mod_small_int_val_small_int_valEPN9doris_udf' '15FunctionContextERKNS1_11SmallIntValES6_'], - [['mod'], 'INT', ['INT', 'INT'], + [['mod'], 'INT', ['INT', 'INT'], '_ZN5doris9Operators19mod_int_val_int_valEPN9doris_udf' '15FunctionContextERKNS1_6IntValES6_'], - [['mod'], 'BIGINT', ['BIGINT', 'BIGINT'], + [['mod'], 'BIGINT', ['BIGINT', 'BIGINT'], '_ZN5doris9Operators27mod_big_int_val_big_int_valEPN9doris_udf' '15FunctionContextERKNS1_9BigIntValES6_'], - [['mod'], 'LARGEINT', ['LARGEINT', 'LARGEINT'], + [['mod'], 'LARGEINT', ['LARGEINT', 'LARGEINT'], '_ZN5doris9Operators31mod_large_int_val_large_int_valEPN9doris_udf' '15FunctionContextERKNS1_11LargeIntValES6_'], - [['mod'], 'DECIMAL', ['DECIMAL', 'DECIMAL'], + [['mod'], 'DECIMAL', ['DECIMAL', 'DECIMAL'], '_ZN5doris16DecimalOperators27mod_decimal_val_decimal_valEPN9doris_udf' '15FunctionContextERKNS1_10DecimalValES6_'], - [['mod'], 'DECIMALV2', ['DECIMALV2', 'DECIMALV2'], + [['mod'], 'DECIMALV2', ['DECIMALV2', 'DECIMALV2'], '_ZN5doris18DecimalV2Operators31mod_decimalv2_val_decimalv2_valEPN9doris_udf' '15FunctionContextERKNS1_12DecimalV2ValES6_'], - [['mod', 'fmod'], 'FLOAT', ['FLOAT', 'FLOAT'], + [['mod', 'fmod'], 'FLOAT', ['FLOAT', 'FLOAT'], '_ZN5doris13MathFunctions10fmod_floatEPN9doris_udf15FunctionContextERKNS1_8FloatValES6_'], - [['mod', 'fmod'], 'DOUBLE', ['DOUBLE', 'DOUBLE'], + [['mod', 'fmod'], 'DOUBLE', ['DOUBLE', 'DOUBLE'], '_ZN5doris13MathFunctions11fmod_doubleEPN9doris_udf15FunctionContextERKNS1_9DoubleValES6_'], [['positive'], 'BIGINT', ['BIGINT'], @@ -455,7 +455,7 @@ [['coalesce'], 'DECIMAL', ['DECIMAL', '...'], ''], [['coalesce'], 'DECIMALV2', ['DECIMALV2', '...'], ''], - [['esquery'], 'BOOLEAN', ['VARCHAR', 'VARCHAR'], + [['esquery'], 'BOOLEAN', ['VARCHAR', 'VARCHAR'], '_ZN5doris11ESFunctions5matchEPN' '9doris_udf15FunctionContextERKNS1_9StringValES6_'], @@ -466,46 +466,46 @@ [['substr', 'substring'], 'VARCHAR', ['VARCHAR', 'INT', 'INT'], '_ZN5doris15StringFunctions9substringEPN' '9doris_udf15FunctionContextERKNS1_9StringValERKNS1_6IntValES9_'], - [['strleft'], 'VARCHAR', ['VARCHAR', 'INT'], + [['strleft'], 'VARCHAR', ['VARCHAR', 'INT'], '_ZN5doris15StringFunctions4leftEPN9doris_udf' '15FunctionContextERKNS1_9StringValERKNS1_6IntValE'], [['left'], 'VARCHAR', ['VARCHAR', 'INT'], '_ZN5doris15StringFunctions4leftEPN9doris_udf' '15FunctionContextERKNS1_9StringValERKNS1_6IntValE'], - [['strright'], 'VARCHAR', ['VARCHAR', 'INT'], + [['strright'], 'VARCHAR', ['VARCHAR', 'INT'], '_ZN5doris15StringFunctions5rightEPN9doris_udf' '15FunctionContextERKNS1_9StringValERKNS1_6IntValE'], [['right'], 'VARCHAR', ['VARCHAR', 'INT'], '_ZN5doris15StringFunctions5rightEPN9doris_udf' '15FunctionContextERKNS1_9StringValERKNS1_6IntValE'], - [['space'], 'VARCHAR', ['INT'], + [['space'], 'VARCHAR', ['INT'], '_ZN5doris15StringFunctions5spaceEPN9doris_udf15FunctionContextERKNS1_6IntValE'], - [['repeat'], 'VARCHAR', ['VARCHAR', 'INT'], + [['repeat'], 'VARCHAR', ['VARCHAR', 'INT'], '_ZN5doris15StringFunctions6repeatEPN9doris_udf' '15FunctionContextERKNS1_9StringValERKNS1_6IntValE'], - [['lpad'], 'VARCHAR', ['VARCHAR', 'INT', 'VARCHAR'], + [['lpad'], 'VARCHAR', ['VARCHAR', 'INT', 'VARCHAR'], '_ZN5doris15StringFunctions4lpadEPN9doris_udf' '15FunctionContextERKNS1_9StringValERKNS1_6IntValES6_'], - [['rpad'], 'VARCHAR', ['VARCHAR', 'INT', 'VARCHAR'], + [['rpad'], 'VARCHAR', ['VARCHAR', 'INT', 'VARCHAR'], '_ZN5doris15StringFunctions4rpadEPN9doris_udf' '15FunctionContextERKNS1_9StringValERKNS1_6IntValES6_'], - [['length'], 'INT', ['VARCHAR'], + [['length'], 'INT', ['VARCHAR'], '_ZN5doris15StringFunctions6lengthEPN9doris_udf15FunctionContextERKNS1_9StringValE'], - [['lower', 'lcase'], 'VARCHAR', ['VARCHAR'], + [['lower', 'lcase'], 'VARCHAR', ['VARCHAR'], '_ZN5doris15StringFunctions5lowerEPN9doris_udf15FunctionContextERKNS1_9StringValE'], [['upper', 'ucase'], 'VARCHAR', ['VARCHAR'], '_ZN5doris15StringFunctions5upperEPN9doris_udf15FunctionContextERKNS1_9StringValE'], - [['reverse'], 'VARCHAR', ['VARCHAR'], + [['reverse'], 'VARCHAR', ['VARCHAR'], '_ZN5doris15StringFunctions7reverseEPN9doris_udf15FunctionContextERKNS1_9StringValE'], - [['trim'], 'VARCHAR', ['VARCHAR'], + [['trim'], 'VARCHAR', ['VARCHAR'], '_ZN5doris15StringFunctions4trimEPN9doris_udf15FunctionContextERKNS1_9StringValE'], - [['ltrim'], 'VARCHAR', ['VARCHAR'], + [['ltrim'], 'VARCHAR', ['VARCHAR'], '_ZN5doris15StringFunctions5ltrimEPN9doris_udf15FunctionContextERKNS1_9StringValE'], [['rtrim'], 'VARCHAR', ['VARCHAR'], '_ZN5doris15StringFunctions5rtrimEPN9doris_udf15FunctionContextERKNS1_9StringValE'], - [['ascii'], 'INT', ['VARCHAR'], + [['ascii'], 'INT', ['VARCHAR'], '_ZN5doris15StringFunctions5asciiEPN9doris_udf15FunctionContextERKNS1_9StringValE'], - [['instr'], 'INT', ['VARCHAR', 'VARCHAR'], + [['instr'], 'INT', ['VARCHAR', 'VARCHAR'], '_ZN5doris15StringFunctions5instrEPN9doris_udf15FunctionContextERKNS1_9StringValES6_'], [['locate'], 'INT', ['VARCHAR', 'VARCHAR'], '_ZN5doris15StringFunctions6locateEPN9doris_udf15FunctionContextERKNS1_9StringValES6_'], @@ -526,7 +526,7 @@ '15FunctionContextENS2_18FunctionStateScopeE', '_ZN5doris15StringFunctions12regexp_closeEPN9doris_udf' '15FunctionContextENS2_18FunctionStateScopeE'], - [['concat'], 'VARCHAR', ['VARCHAR', '...'], + [['concat'], 'VARCHAR', ['VARCHAR', '...'], '_ZN5doris15StringFunctions6concatEPN9doris_udf15FunctionContextEiPKNS1_9StringValE'], [['concat_ws'], 'VARCHAR', ['VARCHAR', 'VARCHAR', '...'], '_ZN5doris15StringFunctions9concat_wsEPN9doris_udf' @@ -534,7 +534,7 @@ [['find_in_set'], 'INT', ['VARCHAR', 'VARCHAR'], '_ZN5doris15StringFunctions11find_in_setEPN9doris_udf' '15FunctionContextERKNS1_9StringValES6_'], - [['parse_url'], 'VARCHAR', ['VARCHAR', 'VARCHAR'], + [['parse_url'], 'VARCHAR', ['VARCHAR', 'VARCHAR'], '_ZN5doris15StringFunctions9parse_urlEPN9doris_udf' '15FunctionContextERKNS1_9StringValES6_', '_ZN5doris15StringFunctions17parse_url_prepareEPN9doris_udf' @@ -548,20 +548,30 @@ '15FunctionContextENS2_18FunctionStateScopeE', '_ZN5doris15StringFunctions15parse_url_closeEPN9doris_udf' '15FunctionContextENS2_18FunctionStateScopeE'], + [['money_format'], 'VARCHAR', ['BIGINT'], + '_ZN5doris15StringFunctions12money_formatEPN9doris_udf15FunctionContextERKNS1_9BigIntValE'], + [['money_format'], 'VARCHAR', ['LARGEINT'], + '_ZN5doris15StringFunctions12money_formatEPN9doris_udf15FunctionContextERKNS1_11LargeIntValE'], + [['money_format'], 'VARCHAR', ['DOUBLE'], + '_ZN5doris15StringFunctions12money_formatEPN9doris_udf15FunctionContextERKNS1_9DoubleValE'], + [['money_format'], 'VARCHAR', ['DECIMAL'], + '_ZN5doris15StringFunctions12money_formatEPN9doris_udf15FunctionContextERKNS1_10DecimalValE'], + [['money_format'], 'VARCHAR', ['DECIMALV2'], + '_ZN5doris15StringFunctions12money_formatEPN9doris_udf15FunctionContextERKNS1_12DecimalV2ValE'], # Utility functions - [['sleep'], 'BOOLEAN', ['INT'], + [['sleep'], 'BOOLEAN', ['INT'], '_ZN5doris16UtilityFunctions5sleepEPN9doris_udf15FunctionContextERKNS1_6IntValE'], - [['version'], 'VARCHAR', [], + [['version'], 'VARCHAR', [], '_ZN5doris16UtilityFunctions7versionEPN9doris_udf15FunctionContextE'], # Json functions - [['get_json_int'], 'INT', ['VARCHAR', 'VARCHAR'], + [['get_json_int'], 'INT', ['VARCHAR', 'VARCHAR'], '_ZN5doris13JsonFunctions12get_json_intEPN9doris_udf15FunctionContextERKNS1_9StringValES6_'], - [['get_json_double'], 'DOUBLE', ['VARCHAR', 'VARCHAR'], + [['get_json_double'], 'DOUBLE', ['VARCHAR', 'VARCHAR'], '_ZN5doris13JsonFunctions15get_json_doubleEPN9doris_udf' '15FunctionContextERKNS1_9StringValES6_'], - [['get_json_string'], 'VARCHAR', ['VARCHAR', 'VARCHAR'], + [['get_json_string'], 'VARCHAR', ['VARCHAR', 'VARCHAR'], '_ZN5doris13JsonFunctions15get_json_stringEPN9doris_udf' '15FunctionContextERKNS1_9StringValES6_'], @@ -570,7 +580,7 @@ '_ZN5doris16HllHashFunctions15hll_cardinalityEPN9doris_udf15FunctionContextERKNS1_6HllValE'], [['hll_hash'], 'VARCHAR', ['VARCHAR'], '_ZN5doris16HllHashFunctions8hll_hashEPN9doris_udf15FunctionContextERKNS1_9StringValE'], - + # aes and base64 function [['aes_encrypt'], 'VARCHAR', ['VARCHAR', 'VARCHAR'], '_ZN5doris19EncryptionFunctions11aes_encryptEPN9doris_udf' diff --git a/run-ut.sh b/run-ut.sh index 2963013b595029..22b9e7e4628853 100755 --- a/run-ut.sh +++ b/run-ut.sh @@ -154,6 +154,9 @@ ${DORIS_TEST_BINARY_DIR}/util/string_util_test ## Running common Unittest ${DORIS_TEST_BINARY_DIR}/common/resource_tls_test +## Running exprs unit test +${DORIS_TEST_BINARY_DIR}/exprs/string_functions_test + ## Running exec unit test ${DORIS_TEST_BINARY_DIR}/exec/plain_text_line_reader_uncompressed_test ${DORIS_TEST_BINARY_DIR}/exec/plain_text_line_reader_gzip_test