From 0b6cf8e5eeb5f15677298d9e5cde7d49dadc7087 Mon Sep 17 00:00:00 2001 From: zhanglistar Date: Wed, 20 Nov 2024 18:14:23 +0800 Subject: [PATCH] change name of tuple vector functions --- docs/en/sql-reference/functions/tuple-functions.md | 14 +++++++------- src/Functions/FunctionHelpers.cpp | 2 +- src/Functions/divideOrNull.cpp | 4 ++-- src/Functions/vectorFunctions.cpp | 12 +++++++++++- tests/queries/0_stateless/03224_modulo_or_null.sql | 4 ++-- tests/queries/0_stateless/03225_divide_or_null.sql | 4 ++-- utils/check-style/aspell-ignore/en/aspell-dict.txt | 2 +- 7 files changed, 26 insertions(+), 16 deletions(-) diff --git a/docs/en/sql-reference/functions/tuple-functions.md b/docs/en/sql-reference/functions/tuple-functions.md index 2206f2d1343..e271b03e7ea 100644 --- a/docs/en/sql-reference/functions/tuple-functions.md +++ b/docs/en/sql-reference/functions/tuple-functions.md @@ -596,14 +596,14 @@ Result: └──────────────────────────────────┘ ``` -## tupleDivideOrNullByNumber +## tupleDivideByNumberOrNull Like [tupleDivideByNumber](#tupleDivideByNumber), but division by zero will return `NULL`. **Syntax** ```sql -tupleDivideOrNullByNumber(tuple, number) +tupleDivideByNumberOrNull(tuple, number) ``` **Arguments** @@ -620,13 +620,13 @@ tupleDivideOrNullByNumber(tuple, number) Query: ```sql -SELECT tupleDivideOrNullByNumber((1, 2), 0.0); +SELECT tupleDivideByNumberOrNull((1, 2), 0.0); ``` Result: ```text -┌─tupleDivideOrNullByNumber((1, 2), 0.)─┐ +┌─tupleDivideByNumberOrNull((1, 2), 0.)─┐ │ (NULL,NULL) │ └───────────────────────────────────────┘ ``` @@ -970,7 +970,7 @@ Like [tupleModuloByNumber](#tuplemodulobynumber) it returns a tuple of the modul **Syntax** ```sql -tupleModuloOrNullByNumber(tuple_num, div) +tupleModuloByNumberOrNull(tuple_num, div) ``` **Parameters** @@ -988,13 +988,13 @@ tupleModuloOrNullByNumber(tuple_num, div) Query: ``` sql -SELECT tupleModuloOrNullByNumber((15, 10, 5), 0); +SELECT tupleModuloByNumberOrNull((15, 10, 5), 0); ``` Result: ``` text -┌─tupleModuloOrNullByNumber((15, 10, 5), 0)─┐ +┌─tupleModuloByNumberOrNull((15, 10, 5), 0)─┐ │ (NULL,NULL,NULL) │ └───────────────────────────────────────────┘ ``` diff --git a/src/Functions/FunctionHelpers.cpp b/src/Functions/FunctionHelpers.cpp index 8f446729065..9ec73226e73 100644 --- a/src/Functions/FunctionHelpers.cpp +++ b/src/Functions/FunctionHelpers.cpp @@ -218,7 +218,7 @@ checkAndGetNestedArrayOffset(const IColumn ** columns, size_t num_arguments) return {nested_columns, offsets->data()}; } -ColumnPtr +ColumnPtr wrapInNullable(const ColumnPtr & src, const ColumnsWithTypeAndName & args, const DataTypePtr & result_type, size_t input_rows_count, const NullMap * res_null_map) { ColumnPtr result_null_map_column; diff --git a/src/Functions/divideOrNull.cpp b/src/Functions/divideOrNull.cpp index b4aaacbbbcc..58e6a090239 100644 --- a/src/Functions/divideOrNull.cpp +++ b/src/Functions/divideOrNull.cpp @@ -48,7 +48,7 @@ struct DivideOrNullImpl c[i] = ResultType(); } else - c[i] = -a[i]; + c[i] = static_cast(-a[i]); } return; } @@ -86,7 +86,7 @@ struct DivideOrNullImpl *m = 1; return res; } - return -a; + return static_cast(-a); } } return static_cast(a) / b; diff --git a/src/Functions/vectorFunctions.cpp b/src/Functions/vectorFunctions.cpp index bd5d443cfd4..9f5fe3950c3 100644 --- a/src/Functions/vectorFunctions.cpp +++ b/src/Functions/vectorFunctions.cpp @@ -73,6 +73,16 @@ constexpr std::string makeFirstLetterUppercase(const std::string & str) return res; } +constexpr bool endWith(const std::string & str, const std::string & needle) +{ + return str.size() >= needle.size() && str.compare(str.size() - needle.size(), needle.size(), needle) == 0; +} + +constexpr std::string dropNeedle(const std::string & str, const std::string & needle) +{ + return endWith(str, needle) ? str.substr(0, str.size() - needle.size()) : str; +} + template class FunctionTupleOperator : public ITupleFunction { @@ -240,7 +250,7 @@ class FunctionTupleOperatorByNumber : public ITupleFunction { public: /// constexpr cannot be used due to std::string has not constexpr constructor in this compiler version - static inline auto name = "tuple" + makeFirstLetterUppercase(FuncName::name) + "ByNumber"; + static inline auto name = "tuple" + makeFirstLetterUppercase(dropNeedle(FuncName::name, "OrNull")) + "ByNumber" + (endWith(FuncName::name, "OrNull") ? "OrNull" : ""); explicit FunctionTupleOperatorByNumber(ContextPtr context_) : ITupleFunction(context_) {} static FunctionPtr create(ContextPtr context_) { return std::make_shared(context_); } diff --git a/tests/queries/0_stateless/03224_modulo_or_null.sql b/tests/queries/0_stateless/03224_modulo_or_null.sql index 971ea5fccd0..5a006f1f165 100644 --- a/tests/queries/0_stateless/03224_modulo_or_null.sql +++ b/tests/queries/0_stateless/03224_modulo_or_null.sql @@ -35,5 +35,5 @@ SELECT moduloOrNull(materialize(16.2), materialize(0.0)); SELECT tupleModuloOrNull((15, 10, 5), (0, 3, 2)); SELECT tupleModuloOrNull((15, 10, 5), (5, 3, 2)); -SELECT tupleModuloOrNullByNumber((15, 10, 5), 0); -SELECT tupleModuloOrNullByNumber((15, 10, 5), 2); +SELECT tupleModuloByNumberOrNull((15, 10, 5), 0); +SELECT tupleModuloByNumberOrNull((15, 10, 5), 2); diff --git a/tests/queries/0_stateless/03225_divide_or_null.sql b/tests/queries/0_stateless/03225_divide_or_null.sql index dce50079dd9..c0b5851cb09 100644 --- a/tests/queries/0_stateless/03225_divide_or_null.sql +++ b/tests/queries/0_stateless/03225_divide_or_null.sql @@ -34,5 +34,5 @@ SELECT divideOrNull(materialize(toDecimal32(16.2, 2)), materialize(0.0)); SELECT tupleDivideOrNull((15, 10, 5), (0, 0, 0)); SELECT tupleDivideOrNull((15, 10, 5), (5, 0, 0)); -SELECT tupleDivideOrNullByNumber((15, 10, 5), 5); -SELECT tupleDivideOrNullByNumber((15, 10, 5), 0); +SELECT tupleDivideByNumberOrNull((15, 10, 5), 5); +SELECT tupleDivideByNumberOrNull((15, 10, 5), 0); diff --git a/utils/check-style/aspell-ignore/en/aspell-dict.txt b/utils/check-style/aspell-ignore/en/aspell-dict.txt index 10a20fab1fa..666755bea4e 100644 --- a/utils/check-style/aspell-ignore/en/aspell-dict.txt +++ b/utils/check-style/aspell-ignore/en/aspell-dict.txt @@ -3160,7 +3160,7 @@ zstd divideOrNull moduloOrNull tupleDivideOrNull -tupleDivideOrNullByNumber +tupleDivideByNumberOrNull tupleModuloByNumberOrNull tupleModuloOrNull BFloat