Rename decode/encodeSqid() to sqidDecode/Encode()

This commit is contained in:
Robert Schulze 2024-01-05 21:37:30 +00:00
parent f6ecf2b617
commit 44b9547fba
No known key found for this signature in database
GPG Key ID: 26703B55FB13728A
4 changed files with 46 additions and 44 deletions

View File

@ -1777,7 +1777,7 @@ Result:
└────────────────────────────────────────────────────────────────────────┘
```
## encodeSqid
## sqidEncode
Encodes numbers as a [Sqid](https://sqids.org/) which is a YouTube-like ID string.
The output alphabet is `abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789`.
@ -1786,7 +1786,7 @@ Do not use this function for hashing - the generated IDs can be decoded back int
**Syntax**
```sql
encodeSqid(number1, ...)
sqidEncode(number1, ...)
```
Alias: `sqid`
@ -1802,23 +1802,23 @@ A sqid [String](/docs/en/sql-reference/data-types/string.md).
**Example**
```sql
SELECT encodeSqid(1, 2, 3, 4, 5);
SELECT sqidEncode(1, 2, 3, 4, 5);
```
```response
┌─encodeSqid(1, 2, 3, 4, 5)─┐
┌─sqidEncode(1, 2, 3, 4, 5)─┐
│ gXHfJ1C6dN │
└───────────────────────────┘
```
## decodeSqid
## sqidDecode
Decodes a [Sqid](https://sqids.org/) into numbers.
**Syntax**
```sql
decodeSqid(number1, ...)
sqidDecode(sqid)
```
**Arguments**
@ -1827,16 +1827,16 @@ decodeSqid(number1, ...)
**Returned Value**
The sqid transformed to numbers [Tuple(UInt64)](/docs/en/sql-reference/data-types/tuple.md).
The sqid transformed to numbers [Array(UInt64)](/docs/en/sql-reference/data-types/array.md).
**Example**
```sql
SELECT decodeSqid('gXHfJ1C6dN');
SELECT sqidDecode('gXHfJ1C6dN');
```
```response
┌─decodeSqid('gXHfJ1C6dN')─┐
┌─sqidDecode('gXHfJ1C6dN')─┐
│ [1,2,3,4,5] │
└──────────────────────────┘
```

View File

@ -24,17 +24,17 @@ namespace ErrorCodes
extern const int NUMBER_OF_ARGUMENTS_DOESNT_MATCH;
}
/// encodeSqid(number1, ...)
class FunctionEncodeSqid : public IFunction
/// sqidEncode(number1, ...)
class FunctionSqidEncode : public IFunction
{
public:
static constexpr auto name = "encodeSqid";
static constexpr auto name = "sqidEncode";
String getName() const override { return name; }
size_t getNumberOfArguments() const override { return 0; }
bool isVariadic() const override { return true; }
bool isSuitableForShortCircuitArgumentsExecution(const DataTypesWithConstInfo & /*arguments*/) const override { return true; }
static FunctionPtr create(ContextPtr) { return std::make_shared<FunctionEncodeSqid>(); }
static FunctionPtr create(ContextPtr) { return std::make_shared<FunctionSqidEncode>(); }
DataTypePtr getReturnTypeImpl(const DataTypes & arguments) const override
{
@ -82,16 +82,16 @@ private:
sqidscxx::Sqids<> sqids;
};
/// decodeSqid(number1, ...)
class FunctionDecodeSqid : public IFunction
/// sqidDecode(number1, ...)
class FunctionSqidDecode : public IFunction
{
public:
static constexpr auto name = "decodeSqid";
static constexpr auto name = "sqidDecode";
String getName() const override { return name; }
size_t getNumberOfArguments() const override { return 1; }
bool isSuitableForShortCircuitArgumentsExecution(const DataTypesWithConstInfo & /*arguments*/) const override { return true; }
static FunctionPtr create(ContextPtr) { return std::make_shared<FunctionDecodeSqid>(); }
static FunctionPtr create(ContextPtr) { return std::make_shared<FunctionSqidDecode>(); }
DataTypePtr getReturnTypeImpl(const ColumnsWithTypeAndName & arguments) const override
{
@ -131,35 +131,35 @@ private:
REGISTER_FUNCTION(Sqid)
{
factory.registerFunction<FunctionEncodeSqid>(FunctionDocumentation{
factory.registerFunction<FunctionSqidEncode>(FunctionDocumentation{
.description=R"(
Transforms numbers into a [Sqid](https://sqids.org/) which is a Youtube-like ID string.)",
.syntax="encodeSqid(number1, ...)",
.syntax="sqidEncode(number1, ...)",
.arguments={{"number1, ...", "Arbitrarily many UInt8, UInt16, UInt32 or UInt64 arguments"}},
.returned_value="A hash id [String](/docs/en/sql-reference/data-types/string.md).",
.examples={
{"simple",
"SELECT encodeSqid(1, 2, 3, 4, 5);",
"SELECT sqidEncode(1, 2, 3, 4, 5);",
R"(
encodeSqid(1, 2, 3, 4, 5)
sqidEncode(1, 2, 3, 4, 5)
gXHfJ1C6dN
)"
}}
});
factory.registerAlias("sqid", FunctionEncodeSqid::name);
factory.registerAlias("sqid", FunctionSqidEncode::name);
factory.registerFunction<FunctionDecodeSqid>(FunctionDocumentation{
factory.registerFunction<FunctionSqidDecode>(FunctionDocumentation{
.description=R"(
Transforms a [Sqid](https://sqids.org/) back into a tuple of numbers.)",
.syntax="decodeSqid(number1, ...)",
.syntax="sqidDecode(number1, ...)",
.arguments={{"sqid", "A sqid"}},
.returned_value="A tuple of [UInt64](/docs/en/sql-reference/data-types/int-uint.md).",
.examples={
{"simple",
"SELECT decodeSqid('gXHfJ1C6dN');",
"SELECT sqidDecode('gXHfJ1C6dN');",
R"(
decodeSqid('gXHfJ1C6dN')
sqidDecode('gXHfJ1C6dN')
[1,2,3,4,5]
)"

View File

@ -3,24 +3,24 @@
SET allow_suspicious_low_cardinality_types = 1;
SELECT '-- negative tests';
SELECT encodeSqid(); -- { serverError NUMBER_OF_ARGUMENTS_DOESNT_MATCH }
SELECT decodeSqid(); -- { serverError NUMBER_OF_ARGUMENTS_DOESNT_MATCH }
SELECT encodeSqid('1'); -- { serverError ILLEGAL_TYPE_OF_ARGUMENT }
SELECT decodeSqid(1); -- { serverError ILLEGAL_TYPE_OF_ARGUMENT }
SELECT sqidEncode(); -- { serverError NUMBER_OF_ARGUMENTS_DOESNT_MATCH }
SELECT sqidDecode(); -- { serverError NUMBER_OF_ARGUMENTS_DOESNT_MATCH }
SELECT sqidEncode('1'); -- { serverError ILLEGAL_TYPE_OF_ARGUMENT }
SELECT sqidDecode(1); -- { serverError ILLEGAL_TYPE_OF_ARGUMENT }
SELECT '-- const UInt*';
SELECT encodeSqid(1) AS sqid, decodeSqid(sqid);
SELECT encodeSqid(1, 2) AS sqid, decodeSqid(sqid);
SELECT encodeSqid(1, 2, 3) AS sqid, decodeSqid(sqid);
SELECT encodeSqid(1::UInt8, 2::UInt16, 3::UInt32, 4::UInt64) AS sqid, decodeSqid(sqid);
SELECT encodeSqid(toNullable(1), toLowCardinality(2)) AS sqid;
SELECT sqidEncode(1) AS sqid, sqidDecode(sqid);
SELECT sqidEncode(1, 2) AS sqid, sqidDecode(sqid);
SELECT sqidEncode(1, 2, 3) AS sqid, sqidDecode(sqid);
SELECT sqidEncode(1::UInt8, 2::UInt16, 3::UInt32, 4::UInt64) AS sqid, sqidDecode(sqid);
SELECT sqidEncode(toNullable(1), toLowCardinality(2)) AS sqid;
SELECT '-- non-const UInt*';
SELECT encodeSqid(materialize(1)) AS sqid, decodeSqid(sqid);
SELECT encodeSqid(materialize(1), materialize(2)) AS sqid, decodeSqid(sqid);
SELECT encodeSqid(materialize(1), materialize(2), materialize(3)) AS sqid, decodeSqid(sqid);
SELECT encodeSqid(materialize(1::UInt8), materialize(2::UInt16), materialize(3::UInt32), materialize(4::UInt64)) AS sqid, decodeSqid(sqid);
SELECT encodeSqid(toNullable(materialize(1)), toLowCardinality(materialize(2)));
SELECT sqidEncode(materialize(1)) AS sqid, sqidDecode(sqid);
SELECT sqidEncode(materialize(1), materialize(2)) AS sqid, sqidDecode(sqid);
SELECT sqidEncode(materialize(1), materialize(2), materialize(3)) AS sqid, sqidDecode(sqid);
SELECT sqidEncode(materialize(1::UInt8), materialize(2::UInt16), materialize(3::UInt32), materialize(4::UInt64)) AS sqid, sqidDecode(sqid);
SELECT sqidEncode(toNullable(materialize(1)), toLowCardinality(materialize(2)));
SELECT '-- alias';
SELECT sqid(1, 2);

View File

@ -701,8 +701,6 @@ PrettySpaceMonoBlock
PrettySpaceNoEscapes
PrettySpaceNoEscapesMonoBlock
Prewhere
TotalPrimaryKeyBytesInMemory
TotalPrimaryKeyBytesInMemoryAllocated
PrivateKeyPassphraseHandler
ProfileEvents
Profiler
@ -924,6 +922,8 @@ Toolset
TopK
TotalBytesOfMergeTreeTables
TotalPartsOfMergeTreeTables
TotalPrimaryKeyBytesInMemory
TotalPrimaryKeyBytesInMemoryAllocated
TotalRowsOfMergeTreeTables
TotalTemporaryFiles
Tradeoff
@ -1848,14 +1848,14 @@ metrica
metroHash
mfedotov
minMap
minSampleSizeContinuous
minSampleSizeConversion
mindsdb
minimalistic
mininum
miniselect
minmap
minmax
minSampleSizeContinuous
minSampleSizeConversion
mins
misconfiguration
mispredictions
@ -2283,6 +2283,8 @@ splitByString
splitByWhitespace
splitby
sqid
sqidDecode
sqidEncode
sql
sqlalchemy
sqlinsert