Merge pull request #60494 from rschu1ze/byteSlice

Add convenience alias `byteSlice` for `substring`
This commit is contained in:
Robert Schulze 2024-03-01 11:23:22 +01:00 committed by GitHub
commit ed215a293a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 18 additions and 6 deletions

View File

@ -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.

View File

@ -558,6 +558,7 @@ substring(s, offset[, length])
Alias:
- `substr`
- `mid`
- `byteSlice`
**Arguments**

View File

@ -189,6 +189,7 @@ REGISTER_FUNCTION(Substring)
factory.registerFunction<FunctionSubstring<false>>({}, 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<FunctionSubstring<true>>({}, FunctionFactory::CaseSensitive);
}

View File

@ -170,4 +170,6 @@ g
UBSAN bug
-- UBSAN bug
-- Alias
el

View File

@ -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, пÑ<C2BF>ивеÑ<C2B5>', -9223372036854775808, number) FROM numbers(16) FORMAT Null;
SELECT '-- Alias';
SELECT byteSlice('hello', 2, 2);

View File

@ -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