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. Encodes numbers as a [Sqid](https://sqids.org/) which is a YouTube-like ID string.
The output alphabet is `abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789`. 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** **Syntax**
```sql ```sql
encodeSqid(number1, ...) sqidEncode(number1, ...)
``` ```
Alias: `sqid` Alias: `sqid`
@ -1802,23 +1802,23 @@ A sqid [String](/docs/en/sql-reference/data-types/string.md).
**Example** **Example**
```sql ```sql
SELECT encodeSqid(1, 2, 3, 4, 5); SELECT sqidEncode(1, 2, 3, 4, 5);
``` ```
```response ```response
┌─encodeSqid(1, 2, 3, 4, 5)─┐ ┌─sqidEncode(1, 2, 3, 4, 5)─┐
│ gXHfJ1C6dN │ │ gXHfJ1C6dN │
└───────────────────────────┘ └───────────────────────────┘
``` ```
## decodeSqid ## sqidDecode
Decodes a [Sqid](https://sqids.org/) into numbers. Decodes a [Sqid](https://sqids.org/) into numbers.
**Syntax** **Syntax**
```sql ```sql
decodeSqid(number1, ...) sqidDecode(sqid)
``` ```
**Arguments** **Arguments**
@ -1827,16 +1827,16 @@ decodeSqid(number1, ...)
**Returned Value** **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** **Example**
```sql ```sql
SELECT decodeSqid('gXHfJ1C6dN'); SELECT sqidDecode('gXHfJ1C6dN');
``` ```
```response ```response
┌─decodeSqid('gXHfJ1C6dN')─┐ ┌─sqidDecode('gXHfJ1C6dN')─┐
│ [1,2,3,4,5] │ │ [1,2,3,4,5] │
└──────────────────────────┘ └──────────────────────────┘
``` ```

View File

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

View File

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

View File

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