mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-22 15:42:02 +00:00
Merge pull request #9767 from hczhcz/patch-0320
Fix splitByString in #9742
This commit is contained in:
commit
d335775208
@ -231,22 +231,23 @@ public:
|
||||
|
||||
/// Get the next token, if any, or return false.
|
||||
bool get(Pos & token_begin, Pos & token_end)
|
||||
{
|
||||
if (sep.empty())
|
||||
{
|
||||
if (pos == end)
|
||||
return false;
|
||||
|
||||
token_begin = pos;
|
||||
pos += 1;
|
||||
token_end = pos;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!pos)
|
||||
return false;
|
||||
|
||||
token_begin = pos;
|
||||
|
||||
if (sep.empty())
|
||||
{
|
||||
pos += 1;
|
||||
token_end = pos;
|
||||
|
||||
if (pos == end)
|
||||
pos = nullptr;
|
||||
}
|
||||
else
|
||||
{
|
||||
pos = reinterpret_cast<Pos>(memmem(pos, end - pos, sep.data(), sep.size()));
|
||||
|
||||
if (pos)
|
||||
|
@ -5,3 +5,5 @@
|
||||
['a','b','c','d','e']
|
||||
['hello','world']
|
||||
['gbye','bug']
|
||||
['']
|
||||
[]
|
||||
|
@ -4,3 +4,5 @@ select splitByString('ab', 'ababab');
|
||||
select splitByString('ababab', 'ababab');
|
||||
select splitByString('', 'abcde');
|
||||
select splitByString(', ', x) from (select arrayJoin(['hello, world', 'gbye, bug']) x);
|
||||
select splitByString('ab', '');
|
||||
select splitByString('', '');
|
||||
|
@ -2,10 +2,31 @@
|
||||
|
||||
## splitByChar(separator, s) {#splitbycharseparator-s}
|
||||
|
||||
Splits a string into substrings separated by ‘separator’.’separator’ must be a string constant consisting of exactly one character.
|
||||
Splits a string into substrings separated by a specified character. It uses a constant string `separator` which consisting of exactly one character.
|
||||
Returns an array of selected substrings. Empty substrings may be selected if the separator occurs at the beginning or end of the string, or if there are multiple consecutive separators.
|
||||
|
||||
**Example:**
|
||||
**Syntax**
|
||||
|
||||
```sql
|
||||
splitByChar(<separator>, <s>)
|
||||
```
|
||||
|
||||
**Parameters**
|
||||
|
||||
- `separator` — The separator which should contain exactly one character. [String](../../data_types/string.md).
|
||||
- `s` — The string to split. [String](../../data_types/string.md).
|
||||
|
||||
**Returned value(s)**
|
||||
|
||||
Returns an array of selected substrings. Empty substrings may be selected when:
|
||||
|
||||
* A separator occurs at the beginning or end of the string;
|
||||
* There are multiple consecutive separators;
|
||||
* The original string `s` is empty.
|
||||
|
||||
Type: [Array](../../data_types/array.md) of [String](../../data_types/string.md).
|
||||
|
||||
**Example**
|
||||
|
||||
``` sql
|
||||
SELECT splitByChar(',', '1,2,3,abcde')
|
||||
@ -19,9 +40,30 @@ SELECT splitByChar(',', '1,2,3,abcde')
|
||||
|
||||
## splitByString(separator, s) {#splitbystringseparator-s}
|
||||
|
||||
The same as above, but it uses a string of multiple characters as the separator. If the string is empty, it will split the string into an array of single characters.
|
||||
Splits a string into substrings separated by a string. It uses a constant string `separator` of multiple characters as the separator. If the string `separator` is empty, it will split the string `s` into an array of single characters.
|
||||
|
||||
**Example:**
|
||||
**Syntax**
|
||||
|
||||
```sql
|
||||
splitByString(<separator>, <s>)
|
||||
```
|
||||
|
||||
**Parameters**
|
||||
|
||||
- `separator` — The separator. [String](../../data_types/string.md).
|
||||
- `s` — The string to split. [String](../../data_types/string.md).
|
||||
|
||||
**Returned value(s)**
|
||||
|
||||
Returns an array of selected substrings. Empty substrings may be selected when:
|
||||
|
||||
Type: [Array](../../data_types/array.md) of [String](../../data_types/string.md).
|
||||
|
||||
* A non-empty separator occurs at the beginning or end of the string;
|
||||
* There are multiple consecutive non-empty separators;
|
||||
* The original string `s` is empty while the separator is not empty.
|
||||
|
||||
**Example**
|
||||
|
||||
``` sql
|
||||
SELECT splitByString(', ', '1, 2 3, 4,5, abcde')
|
||||
@ -52,7 +94,7 @@ Returns the string.
|
||||
|
||||
Selects substrings of consecutive bytes from the ranges a-z and A-Z.Returns an array of substrings.
|
||||
|
||||
**Example:**
|
||||
**Example**
|
||||
|
||||
``` sql
|
||||
SELECT alphaTokens('abca1abc')
|
||||
|
Loading…
Reference in New Issue
Block a user