Update tests and docs related to splitByString

This commit is contained in:
hcz 2020-03-20 13:37:46 +08:00
parent 3c5670c0e2
commit ae2c60d224
3 changed files with 53 additions and 8 deletions

View File

@ -5,3 +5,5 @@
['a','b','c','d','e']
['hello','world']
['gbye','bug']
['']
[]

View File

@ -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('', '');

View File

@ -1,11 +1,31 @@
# Functions for splitting and merging strings and arrays
## splitByChar(separator, s)
## splitByChar
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.
Splits a string into substrings separated by a specified character. It uses a constant string `separator` which consisting of exactly one character.
**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')
@ -16,11 +36,32 @@ SELECT splitByChar(',', '1,2,3,abcde')
└─────────────────────────────────┘
```
## splitByString(separator, s)
## splitByString
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:
* 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.
Type: [Array](../../data_types/array.md) of [String](../../data_types/string.md).
**Example**
```sql
SELECT splitByString(', ', '1, 2 3, 4,5, abcde')
@ -49,7 +90,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')