This is an automated email from the ASF dual-hosted git repository.
lihaopeng pushed a commit to branch vectorized
in repository https://gitbox.apache.org/repos/asf/incubator-doris.git
The following commit(s) were added to refs/heads/vectorized by this push:
new 55a6a80 [Vectorized][Feature] support
money_format/ucase/character_length (#7649)
55a6a80 is described below
commit 55a6a8022b04f5e80d2d9a16a127db7df77ecf2d
Author: Pxl <[email protected]>
AuthorDate: Fri Jan 7 15:04:55 2022 +0800
[Vectorized][Feature] support money_format/ucase/character_length (#7649)
---
be/src/vec/functions/function_string.cpp | 12 +++-
be/src/vec/functions/function_string.h | 110 +++++++++++++++++++++++++++++-
gensrc/script/doris_builtins_functions.py | 8 +--
3 files changed, 120 insertions(+), 10 deletions(-)
diff --git a/be/src/vec/functions/function_string.cpp
b/be/src/vec/functions/function_string.cpp
index 34f1c6b..bdeb7e5 100644
--- a/be/src/vec/functions/function_string.cpp
+++ b/be/src/vec/functions/function_string.cpp
@@ -272,7 +272,7 @@ struct HexStringName {
struct HexStringImpl {
static DataTypes get_variadic_argument_types() {
- return {std::make_shared<vectorized::DataTypeString>()};
+ return {std::make_shared<DataTypeString>()};
}
static Status vector(const ColumnString::Chars& data, const
ColumnString::Offsets& offsets,
@@ -774,8 +774,8 @@ void register_function_string(SimpleFunctionFactory&
factory) {
factory.register_function<FunctionLTrim>();
factory.register_function<FunctionRTrim>();
factory.register_function<FunctionTrim>();
- factory.register_function<FunctionSubstring<Substr3Imp>>();
- factory.register_function<FunctionSubstring<Substr2Imp>>();
+ factory.register_function<FunctionSubstring<Substr3Impl>>();
+ factory.register_function<FunctionSubstring<Substr2Impl>>();
factory.register_function<FunctionLeft>();
factory.register_function<FunctionRight>();
factory.register_function<FunctionNullOrEmpty>();
@@ -792,12 +792,18 @@ void register_function_string(SimpleFunctionFactory&
factory) {
factory.register_function<FunctionSplitPart>();
factory.register_function<FunctionStringMd5sum>();
factory.register_function<FunctionStringParseUrl>();
+ factory.register_function<FunctionMoneyFormat<MoneyFormatDoubleImpl>>();
+ factory.register_function<FunctionMoneyFormat<MoneyFormatInt64Impl>>();
+ factory.register_function<FunctionMoneyFormat<MoneyFormatInt128Impl>>();
+ factory.register_function<FunctionMoneyFormat<MoneyFormatDecimalImpl>>();
factory.register_alias(FunctionLeft::name, "strleft");
factory.register_alias(FunctionRight::name, "strright");
factory.register_alias(SubstringUtil::name, "substr");
factory.register_alias(FunctionToLower::name, "lcase");
+ factory.register_alias(FunctionToUpper::name, "ucase");
factory.register_alias(FunctionStringMd5sum::name, "md5");
+ factory.register_alias(FunctionStringUTF8Length::name, "character_length");
}
} // namespace doris::vectorized
diff --git a/be/src/vec/functions/function_string.h
b/be/src/vec/functions/function_string.h
index 3f3e538..af58062 100644
--- a/be/src/vec/functions/function_string.h
+++ b/be/src/vec/functions/function_string.h
@@ -24,9 +24,12 @@
#include <string_view>
#include "exprs/anyval_util.h"
+#include "exprs/math_functions.h"
+#include "exprs/string_functions.h"
#include "runtime/string_value.hpp"
#include "util/md5.h"
#include "util/url_parser.h"
+#include "vec/columns/column_decimal.h"
#include "vec/columns/column_nullable.h"
#include "vec/columns/column_string.h"
#include "vec/columns/columns_number.h"
@@ -211,7 +214,7 @@ public:
}
};
-struct Substr3Imp {
+struct Substr3Impl {
static DataTypes get_variadic_argument_types() {
return {std::make_shared<DataTypeString>(),
std::make_shared<DataTypeInt32>(),
std::make_shared<DataTypeInt32>()};
@@ -225,7 +228,7 @@ struct Substr3Imp {
}
};
-struct Substr2Imp {
+struct Substr2Impl {
static DataTypes get_variadic_argument_types() {
return {std::make_shared<DataTypeString>(),
std::make_shared<DataTypeInt32>()};
}
@@ -558,7 +561,7 @@ public:
}
return Status::OK();
}
-}; // namespace doris::vectorized
+};
class FunctionStringRepeat : public IFunction {
public:
@@ -1038,4 +1041,105 @@ public:
}
};
+template <typename Impl>
+class FunctionMoneyFormat : public IFunction {
+public:
+ static constexpr auto name = "money_format";
+ static FunctionPtr create() { return
std::make_shared<FunctionMoneyFormat<Impl>>(); }
+ String get_name() const override { return name; }
+
+ DataTypePtr get_return_type_impl(const DataTypes& arguments) const
override {
+ return std::make_shared<DataTypeString>();
+ }
+ DataTypes get_variadic_argument_types_impl() const override {
+ return Impl::get_variadic_argument_types();
+ }
+ size_t get_number_of_arguments() const override { return 1; }
+
+ bool use_default_implementation_for_constants() const override { return
true; }
+
+ Status execute_impl(FunctionContext* context, Block& block, const
ColumnNumbers& arguments,
+ size_t result, size_t input_rows_count) override {
+ auto res_column = ColumnString::create();
+ ColumnPtr argument_column = block.get_by_position(arguments[0]).column;
+
+ auto result_column = assert_cast<ColumnString*>(res_column.get());
+ auto data_column = assert_cast<const typename
Impl::ColumnType*>(argument_column.get());
+
+ Impl::execute(context, result_column, data_column, input_rows_count);
+
+ block.replace_by_position(result, std::move(res_column));
+ return Status::OK();
+ }
+};
+
+struct MoneyFormatDoubleImpl {
+ using ColumnType = ColumnVector<Float64>;
+
+ static DataTypes get_variadic_argument_types() { return
{std::make_shared<DataTypeFloat64>()}; }
+
+ static void execute(FunctionContext* context, ColumnString* result_column,
+ const ColumnType* data_column, size_t
input_rows_count) {
+ for (size_t i = 0; i < input_rows_count; i++) {
+ double value =
+
MathFunctions::my_double_round(data_column->get_element(i), 2, false, false);
+ StringVal str = StringFunctions::do_money_format(context,
fmt::format("{:.2f}", value));
+ result_column->insert_data(reinterpret_cast<const char*>(str.ptr),
str.len);
+ }
+ }
+};
+
+struct MoneyFormatInt64Impl {
+ using ColumnType = ColumnVector<Int64>;
+
+ static DataTypes get_variadic_argument_types() { return
{std::make_shared<DataTypeInt64>()}; }
+
+ static void execute(FunctionContext* context, ColumnString* result_column,
+ const ColumnType* data_column, size_t
input_rows_count) {
+ for (size_t i = 0; i < input_rows_count; i++) {
+ Int64 value = data_column->get_element(i);
+ StringVal str = StringFunctions::do_money_format<Int64,
26>(context, value);
+ result_column->insert_data(reinterpret_cast<const char*>(str.ptr),
str.len);
+ }
+ }
+};
+
+struct MoneyFormatInt128Impl {
+ using ColumnType = ColumnVector<Int128>;
+
+ static DataTypes get_variadic_argument_types() { return
{std::make_shared<DataTypeInt128>()}; }
+
+ static void execute(FunctionContext* context, ColumnString* result_column,
+ const ColumnType* data_column, size_t
input_rows_count) {
+ for (size_t i = 0; i < input_rows_count; i++) {
+ Int128 value = data_column->get_element(i);
+ StringVal str = StringFunctions::do_money_format<Int128,
52>(context, value);
+ result_column->insert_data(reinterpret_cast<const char*>(str.ptr),
str.len);
+ }
+ }
+};
+
+struct MoneyFormatDecimalImpl {
+ using ColumnType = ColumnDecimal<Decimal128>;
+
+ static DataTypes get_variadic_argument_types() {
+ return {std::make_shared<DataTypeDecimal<Decimal128>>(27, 9)};
+ }
+
+ static void execute(FunctionContext* context, ColumnString* result_column,
+ const ColumnType* data_column, size_t
input_rows_count) {
+ for (size_t i = 0; i < input_rows_count; i++) {
+ DecimalV2Val value = DecimalV2Val(data_column->get_element(i));
+
+ DecimalV2Value rounded(0);
+ DecimalV2Value::from_decimal_val(value).round(&rounded, 2,
HALF_UP);
+
+ StringVal str = StringFunctions::do_money_format<int64_t, 26>(
+ context, rounded.int_value(), abs(rounded.frac_value() /
10000000));
+
+ result_column->insert_data(reinterpret_cast<const char*>(str.ptr),
str.len);
+ }
+ }
+};
+
} // namespace doris::vectorized
\ No newline at end of file
diff --git a/gensrc/script/doris_builtins_functions.py
b/gensrc/script/doris_builtins_functions.py
index 176dacc..211775a 100755
--- a/gensrc/script/doris_builtins_functions.py
+++ b/gensrc/script/doris_builtins_functions.py
@@ -930,16 +930,16 @@ visible_functions = [
'15FunctionContextENS2_18FunctionStateScopeE', 'vec',
'ALWAYS_NULLABLE'],
[['money_format'], 'VARCHAR', ['BIGINT'],
'_ZN5doris15StringFunctions12money_formatEPN9doris_udf15FunctionContextERKNS1_9BigIntValE',
- '', '', '', ''],
+ '', '', 'vec', ''],
[['money_format'], 'VARCHAR', ['LARGEINT'],
'_ZN5doris15StringFunctions12money_formatEPN9doris_udf15FunctionContextERKNS1_11LargeIntValE',
- '', '', '', ''],
+ '', '', 'vec', ''],
[['money_format'], 'VARCHAR', ['DOUBLE'],
'_ZN5doris15StringFunctions12money_formatEPN9doris_udf15FunctionContextERKNS1_9DoubleValE',
- '', '', '', ''],
+ '', '', 'vec', ''],
[['money_format'], 'VARCHAR', ['DECIMALV2'],
'_ZN5doris15StringFunctions12money_formatEPN9doris_udf15FunctionContextERKNS1_12DecimalV2ValE',
- '', '', '', ''],
+ '', '', 'vec', ''],
[['split_part'], 'VARCHAR', ['VARCHAR', 'VARCHAR', 'INT'],
'_ZN5doris15StringFunctions10split_partEPN9doris_udf15FunctionContextERKNS1_9StringValES6_RKNS1_6IntValE',
'', '', 'vec', 'ALWAYS_NULLABLE'],
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]