Update tests and docs for string splitting functions

This commit is contained in:
hcz 2020-03-19 10:35:18 +08:00
parent 08f9413e64
commit c115757e79
3 changed files with 45 additions and 1 deletions

View File

@ -0,0 +1,7 @@
['cde','cde']
['','cde','cde','']
['','','','']
['','']
['a','b','c','d','e']
['hello','world']
['gbye','bug']

View File

@ -0,0 +1,6 @@
select splitByString('ab', 'cdeabcde');
select splitByString('ab', 'abcdeabcdeab');
select splitByString('ab', 'ababab');
select splitByString('ababab', 'ababab');
select splitByString('', 'abcde');
select splitByString(', ', x) from (select arrayJoin(['hello, world', 'gbye, bug']) x);

View File

@ -5,9 +5,40 @@
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 'separator'.'separator' must be a string constant 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. 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:**
```sql
SELECT splitByChar(',', '1,2,3,abcde')
```
```text
┌─splitByChar(',', '1,2,3,abcde')─┐
│ ['1','2','3','abcde'] │
└─────────────────────────────────┘
```
## splitByString(separator, s) ## splitByString(separator, s)
The same as above, but it uses a string of multiple characters as the separator. The string must be non-empty. 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.
**Example:**
```sql
SELECT splitByString(', ', '1, 2 3, 4,5, abcde')
```
```text
┌─splitByString(', ', '1, 2 3, 4,5, abcde')─┐
│ ['1','2 3','4,5','abcde'] │
└───────────────────────────────────────────┘
```
```sql
SELECT splitByString('', 'abcde')
```
```text
┌─splitByString('', 'abcde')─┐
│ ['a','b','c','d','e'] │
└────────────────────────────┘
```
## arrayStringConcat(arr\[, separator\]) ## arrayStringConcat(arr\[, separator\])