change name of tuple vector functions

This commit is contained in:
zhanglistar 2024-11-20 18:14:23 +08:00
parent 1d52b1f020
commit 0b6cf8e5ee
7 changed files with 26 additions and 16 deletions

View File

@ -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) │
└───────────────────────────────────────────┘
```

View File

@ -48,7 +48,7 @@ struct DivideOrNullImpl
c[i] = ResultType();
}
else
c[i] = -a[i];
c[i] = static_cast<ResultType>(-a[i]);
}
return;
}
@ -86,7 +86,7 @@ struct DivideOrNullImpl
*m = 1;
return res;
}
return -a;
return static_cast<ResultType>(-a);
}
}
return static_cast<ResultType>(a) / b;

View File

@ -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 FuncName>
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<FunctionTupleOperatorByNumber>(context_); }

View File

@ -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);

View File

@ -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);

View File

@ -3160,7 +3160,7 @@ zstd
divideOrNull
moduloOrNull
tupleDivideOrNull
tupleDivideOrNullByNumber
tupleDivideByNumberOrNull
tupleModuloByNumberOrNull
tupleModuloOrNull
BFloat