From c115757e7984d7a249ba496489bc8a44533613b5 Mon Sep 17 00:00:00 2001 From: hcz Date: Thu, 19 Mar 2020 10:35:18 +0800 Subject: [PATCH] Update tests and docs for string splitting functions --- .../01100_split_by_string.reference | 7 ++++ .../0_stateless/01100_split_by_string.sql | 6 ++++ .../functions/splitting_merging_functions.md | 33 ++++++++++++++++++- 3 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 dbms/tests/queries/0_stateless/01100_split_by_string.reference create mode 100644 dbms/tests/queries/0_stateless/01100_split_by_string.sql diff --git a/dbms/tests/queries/0_stateless/01100_split_by_string.reference b/dbms/tests/queries/0_stateless/01100_split_by_string.reference new file mode 100644 index 00000000000..802ad95b1d6 --- /dev/null +++ b/dbms/tests/queries/0_stateless/01100_split_by_string.reference @@ -0,0 +1,7 @@ +['cde','cde'] +['','cde','cde',''] +['','','',''] +['',''] +['a','b','c','d','e'] +['hello','world'] +['gbye','bug'] diff --git a/dbms/tests/queries/0_stateless/01100_split_by_string.sql b/dbms/tests/queries/0_stateless/01100_split_by_string.sql new file mode 100644 index 00000000000..c65c55902ea --- /dev/null +++ b/dbms/tests/queries/0_stateless/01100_split_by_string.sql @@ -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); diff --git a/docs/en/query_language/functions/splitting_merging_functions.md b/docs/en/query_language/functions/splitting_merging_functions.md index 514c2165376..5743fd6dc6d 100644 --- a/docs/en/query_language/functions/splitting_merging_functions.md +++ b/docs/en/query_language/functions/splitting_merging_functions.md @@ -5,9 +5,40 @@ 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. +**Example:** + +```sql +SELECT splitByChar(',', '1,2,3,abcde') +``` +```text +┌─splitByChar(',', '1,2,3,abcde')─┐ +│ ['1','2','3','abcde'] │ +└─────────────────────────────────┘ +``` + ## 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\])