ClickHouse/tests/queries/0_stateless/03130_generateSnowflakeId.sql

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

26 lines
1.1 KiB
MySQL
Raw Normal View History

-- Test SQL function 'generateSnowflakeID'
2024-07-15 06:39:33 +00:00
SELECT 'Negative tests';
SELECT generateSnowflakeID(1, 2, 3); -- { serverError NUMBER_OF_ARGUMENTS_DOESNT_MATCH }
SELECT generateSnowflakeID(1, 'not_an_int'); -- { serverError ILLEGAL_TYPE_OF_ARGUMENT }
SELECT generateSnowflakeID(1, materialize(2)); -- { serverError ILLEGAL_COLUMN }
2024-07-15 06:39:33 +00:00
SELECT 'The first bit must be zero';
SELECT bitAnd(bitShiftRight(generateSnowflakeID(), 63), 1) = 0;
2024-07-15 06:39:33 +00:00
SELECT 'Test disabling of common subexpression elimination via first parameter';
SELECT generateSnowflakeID(1) = generateSnowflakeID(2); -- disabled common subexpression elimination --> lhs != rhs
SELECT generateSnowflakeID() = generateSnowflakeID(1); -- same as ^^
SELECT generateSnowflakeID(1) = generateSnowflakeID(1); -- with common subexpression elimination
2024-07-15 06:39:33 +00:00
SELECT 'Test user-provided machine ID';
SELECT bitAnd(bitShiftRight(generateSnowflakeID(1, 123), 12), 1024 - 1) = 123; -- the machine id is actually set in the generated snowflake ID (1024 = 2^10)
2024-05-22 15:59:39 +00:00
2024-07-15 06:39:33 +00:00
SELECT 'Generated Snowflake IDs are unique';
2024-05-22 15:59:39 +00:00
SELECT count(*)
FROM
(
SELECT DISTINCT generateSnowflakeID()
FROM numbers(100)
);