From e02c083e607e146bb5d366d41c1154a8b8cf0ba9 Mon Sep 17 00:00:00 2001 From: Robert Schulze Date: Wed, 28 Feb 2024 13:32:56 +0000 Subject: [PATCH 1/3] Add convenience alias byteSlice for substring --- docs/en/sql-reference/functions/bit-functions.md | 4 ++++ docs/en/sql-reference/functions/string-functions.md | 1 + src/Functions/substring.cpp | 1 + tests/queries/0_stateless/01033_function_substring.reference | 4 +++- tests/queries/0_stateless/01033_function_substring.sql | 5 ++++- 5 files changed, 13 insertions(+), 2 deletions(-) diff --git a/docs/en/sql-reference/functions/bit-functions.md b/docs/en/sql-reference/functions/bit-functions.md index 3c07fe8bcbe..0951c783aae 100644 --- a/docs/en/sql-reference/functions/bit-functions.md +++ b/docs/en/sql-reference/functions/bit-functions.md @@ -167,6 +167,10 @@ Result: └──────────────────────────────────────────┴───────────────────────────────┘ ``` +## byteSlice(s, offset, length) + +See function [substring](string-functions.md#substring). + ## bitTest Takes any integer and converts it into [binary form](https://en.wikipedia.org/wiki/Binary_number), returns the value of a bit at specified position. The countdown starts from 0 from the right to the left. diff --git a/docs/en/sql-reference/functions/string-functions.md b/docs/en/sql-reference/functions/string-functions.md index 9ae403be524..3b49e4954ed 100644 --- a/docs/en/sql-reference/functions/string-functions.md +++ b/docs/en/sql-reference/functions/string-functions.md @@ -558,6 +558,7 @@ substring(s, offset[, length]) Alias: - `substr` - `mid` +- `byteSlice` **Arguments** diff --git a/src/Functions/substring.cpp b/src/Functions/substring.cpp index e3dfdf3de5e..e809914f5f0 100644 --- a/src/Functions/substring.cpp +++ b/src/Functions/substring.cpp @@ -189,6 +189,7 @@ REGISTER_FUNCTION(Substring) factory.registerFunction>({}, FunctionFactory::CaseInsensitive); factory.registerAlias("substr", "substring", FunctionFactory::CaseInsensitive); // MySQL alias factory.registerAlias("mid", "substring", FunctionFactory::CaseInsensitive); /// MySQL alias + factory.registerAlias("byteSlice", "substring", FunctionFactory::CaseInsensitive); /// resembles PostgreSQL's get_byte function, similar to ClickHouse's bitSlice factory.registerFunction>({}, FunctionFactory::CaseSensitive); } diff --git a/tests/queries/0_stateless/01033_function_substring.reference b/tests/queries/0_stateless/01033_function_substring.reference index b0fac36e24a..362a14f80f3 100644 --- a/tests/queries/0_stateless/01033_function_substring.reference +++ b/tests/queries/0_stateless/01033_function_substring.reference @@ -170,4 +170,6 @@ g -UBSAN bug +-- UBSAN bug +-- Alias +el diff --git a/tests/queries/0_stateless/01033_function_substring.sql b/tests/queries/0_stateless/01033_function_substring.sql index 82c6b5859e2..15ac4d2701b 100644 --- a/tests/queries/0_stateless/01033_function_substring.sql +++ b/tests/queries/0_stateless/01033_function_substring.sql @@ -132,7 +132,7 @@ SELECT substring(s, l, r) FROM t; DROP table if exists t; -SELECT 'UBSAN bug'; +SELECT '-- UBSAN bug';l /** NOTE: The behaviour of substring and substringUTF8 is inconsistent when negative offset is greater than string size: * substring: @@ -144,3 +144,6 @@ SELECT 'UBSAN bug'; * This may be subject for change. */ SELECT substringUTF8('hello, пÑ�ивеÑ�', -9223372036854775808, number) FROM numbers(16) FORMAT Null; + +SELECT '-- Alias'; +SELECT byteSlice('hello', 2, 2); From e63a66e7d301d4f7b2b3a41135ce5112809500cb Mon Sep 17 00:00:00 2001 From: Robert Schulze Date: Wed, 28 Feb 2024 14:28:05 +0000 Subject: [PATCH 2/3] Fix spelling --- utils/check-style/aspell-ignore/en/aspell-dict.txt | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/utils/check-style/aspell-ignore/en/aspell-dict.txt b/utils/check-style/aspell-ignore/en/aspell-dict.txt index 7a387c50aec..abbd695770c 100644 --- a/utils/check-style/aspell-ignore/en/aspell-dict.txt +++ b/utils/check-style/aspell-ignore/en/aspell-dict.txt @@ -772,7 +772,6 @@ ReferenceKeyed Refreshable RegexpTree RemoteRead -SharedMergeTree ReplacingMergeTree ReplicasMaxAbsoluteDelay ReplicasMaxInsertsInQueue @@ -841,6 +840,8 @@ Sematext SendExternalTables SendScalars ShareAlike +SharedMergeTree +Shortkeys Shortkeys SimHash Simhash @@ -1238,6 +1239,7 @@ buildable builtins byteHammingDistance byteSize +byteSlice byteSwap bytebase bytesToCutForIPv @@ -1615,7 +1617,6 @@ greaterorequals greenspace groupArray groupArrayInsertAt -grouparrayintersect groupArrayIntersect groupArrayLast groupArrayMovingAvg @@ -1632,6 +1633,7 @@ groupBitmapXor groupUniqArray grouparray grouparrayinsertat +grouparrayintersect grouparraylast grouparraymovingavg grouparraymovingsum @@ -1697,6 +1699,7 @@ hyperscan hypot hyvor iTerm +iTerm icosahedron icudata idempotency @@ -1744,7 +1747,6 @@ isValidJSON isValidUTF isZeroOrNull iteratively -iTerm jaccard jaccardIndex jaroSimilarity @@ -2318,7 +2320,6 @@ shardNum sharded sharding shortcircuit -Shortkeys shortkeys shoutout simdjson From 9a4f912764a4c9bc876c03a537aaa4dc9d8dcf4b Mon Sep 17 00:00:00 2001 From: Robert Schulze Date: Wed, 28 Feb 2024 19:25:45 +0000 Subject: [PATCH 3/3] Fix test --- tests/queries/0_stateless/01033_function_substring.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/queries/0_stateless/01033_function_substring.sql b/tests/queries/0_stateless/01033_function_substring.sql index 15ac4d2701b..9955700f302 100644 --- a/tests/queries/0_stateless/01033_function_substring.sql +++ b/tests/queries/0_stateless/01033_function_substring.sql @@ -132,7 +132,7 @@ SELECT substring(s, l, r) FROM t; DROP table if exists t; -SELECT '-- UBSAN bug';l +SELECT '-- UBSAN bug'; /** NOTE: The behaviour of substring and substringUTF8 is inconsistent when negative offset is greater than string size: * substring: