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..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'; +SELECT '-- UBSAN bug'; /** 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); diff --git a/utils/check-style/aspell-ignore/en/aspell-dict.txt b/utils/check-style/aspell-ignore/en/aspell-dict.txt index 3221a64beaf..6db3ac23b05 100644 --- a/utils/check-style/aspell-ignore/en/aspell-dict.txt +++ b/utils/check-style/aspell-ignore/en/aspell-dict.txt @@ -773,7 +773,6 @@ ReferenceKeyed Refreshable RegexpTree RemoteRead -SharedMergeTree ReplacingMergeTree ReplicasMaxAbsoluteDelay ReplicasMaxInsertsInQueue @@ -842,6 +841,8 @@ Sematext SendExternalTables SendScalars ShareAlike +SharedMergeTree +Shortkeys Shortkeys SimHash Simhash @@ -1239,6 +1240,7 @@ buildable builtins byteHammingDistance byteSize +byteSlice byteSwap bytebase bytesToCutForIPv @@ -1617,7 +1619,6 @@ greaterorequals greenspace groupArray groupArrayInsertAt -grouparrayintersect groupArrayIntersect groupArrayLast groupArrayMovingAvg @@ -1634,6 +1635,7 @@ groupBitmapXor groupUniqArray grouparray grouparrayinsertat +grouparrayintersect grouparraylast grouparraymovingavg grouparraymovingsum @@ -1699,6 +1701,7 @@ hyperscan hypot hyvor iTerm +iTerm icosahedron icudata idempotency @@ -1746,7 +1749,6 @@ isValidJSON isValidUTF isZeroOrNull iteratively -iTerm jaccard jaccardIndex jaroSimilarity @@ -2320,7 +2322,6 @@ shardNum sharded sharding shortcircuit -Shortkeys shortkeys shoutout simdjson