Skip to content

Commit 1bd7c86

Browse files
committed
delet-useless-files
1 parent 882b223 commit 1bd7c86

File tree

4 files changed

+448
-34
lines changed
  • docs/sql-manual/sql-functions/scalar-functions/string-functions
  • i18n/zh-CN/docusaurus-plugin-content-docs
    • current/sql-manual/sql-functions/scalar-functions/string-functions
    • version-3.0/sql-manual/sql-functions/scalar-functions/string-functions
  • versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/string-functions

4 files changed

+448
-34
lines changed

docs/sql-manual/sql-functions/scalar-functions/string-functions/concat-ws.md

Lines changed: 112 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,32 +26,34 @@ under the License.
2626

2727
## Description
2828

29-
Use the first parameter sep as the connector to concatenate the second parameter and all subsequent parameters (or all strings in ARRAY) into a string. Special cases:
29+
Use the first parameter sep as the connector to concatenate the second parameter and all subsequent parameters (or all strings in one ARRAY or multi ARRAY ) into a string. Special cases:
3030

3131
- If the separator is NULL, NULL is returned.
3232

33-
The `CONCAT_WS` function does not skip empty strings, but skips NULL values.
34-
33+
- The `CONCAT_WS` function does not skip empty strings, but skips NULL values.
34+
- The `CONCAT_WS` function does not skip empty strings in any `ARRAY` parameters, but skips NULL values in `ARRAY` or - - parameters.
35+
- The first parameters must be a `string` type, and the others must be the same type ,belong to the `string` or `ARRAY` type
3536
## Syntax
3637

3738
```sql
3839
CONCAT_WS ( <sep> , <str> [ , <str> ] )
39-
CONCAT_WS ( <sep> , <array> )
40+
CONCAT_WS ( <sep> , <array> [ , <array> ])
4041
```
4142

4243
## Parameters
4344

4445
| Parameter | Description |
4546
|-------|-----------------|
46-
| `<sep>` | Connector for concatenating strings |
47-
| `<str>` | String to be concatenated |
48-
| `<array>` | Array to be concatenated |
47+
| `<sep>` | Connector for concatenating strings, it is `string` type or `varchar` type |
48+
| `<str>` | String to be concatenated , it is `string` or `varchar` type|
49+
| `<array>` | Array to be concatenated ,it is `ARRAY` type, and every element is `string` or `varchar` type|
4950

5051
## Return value
5152

5253
Parameter `<sep>` or `<array>` The string concatenated with `<str>`. Special cases:
5354

5455
- If delimiter is NULL, returns NULL.
56+
- If parameters with mutlti arrays and it contains a null,function will return empty string.
5557

5658
## Example
5759

@@ -81,4 +83,107 @@ SELECT CONCAT_WS("or", ["d", "is"]),CONCAT_WS(NULL, ["d", "is"]),CONCAT_WS("or",
8183
+------------------------------+------------------------------+------------------------------------+
8284
| doris | NULL | doris |
8385
+------------------------------+------------------------------+------------------------------------+
86+
```
87+
88+
Concatenating multiple arrays
89+
90+
```sql
91+
mysql> SELECT CONCAT_WS("-", ["a", "b"], ["c", NULL], ["d"]);
92+
93+
+------------------------------------------------+
94+
| CONCAT_WS("-", ["a", "b"], ["c", NULL], ["d"]) |
95+
+------------------------------------------------+
96+
| a-b-c-d |
97+
+------------------------------------------------+
98+
```
99+
100+
Handling NULL in string parameters
101+
102+
```sql
103+
mysql> SELECT CONCAT_WS("|", "hello", "", "world", NULL);
104+
105+
+--------------------------------------------+
106+
| CONCAT_WS("|", "hello", "", "world", NULL) |
107+
+--------------------------------------------+
108+
| hello||world |
109+
+--------------------------------------------+
110+
```
111+
112+
Return empty if NULL in multi arrays;
113+
114+
```sql
115+
mysql> SELECT CONCAT_WS("-", ["a", "b"], null,["c", NULL], ["d"]);
116+
+-----------------------------------------------------+
117+
| CONCAT_WS("-", ["a", "b"], null,["c", NULL], ["d"]) |
118+
+-----------------------------------------------------+
119+
| |
120+
+-----------------------------------------------------+
121+
```
122+
123+
Mixing strings and arrays (invalid)
124+
125+
```sql
126+
mysql> SELECT CONCAT_WS(",", "a", ["b", "c"]);
127+
128+
ERROR 1105 (HY000): errCode = 2, detailMessage = can not cast from origin type ARRAY<VARCHAR(1)> to target type=VARCHAR(65533)
129+
130+
```
131+
132+
All NULL inputs
133+
134+
```sql
135+
mysql> SELECT CONCAT_WS("x", NULL, NULL);
136+
137+
+----------------------------+
138+
| CONCAT_WS("x", NULL, NULL) |
139+
+----------------------------+
140+
| |
141+
+----------------------------+
142+
```
143+
144+
Chiese Charactors concat
145+
146+
```sql
147+
mysql> SELECT CONCAT_WS("x", '中文', '中文');
148+
149+
+------------------------------------+
150+
| CONCAT_WS("x", '中文', '中文') |
151+
+------------------------------------+
152+
| 中文x中文 |
153+
+------------------------------------+
154+
```
155+
156+
Chinese charactors in multi arrays
157+
158+
```sql
159+
mysql> SELECT CONCAT_WS("x", ['中文'], ['中文']);
160+
+----------------------------------------+
161+
| CONCAT_WS("x", ['中文'], ['中文']) |
162+
+----------------------------------------+
163+
| 中文x中文 |
164+
+----------------------------------------+
165+
```
166+
167+
Insert and concat them
168+
169+
```sql
170+
DROP TABLE IF EXISTS test_concat_ws_1;
171+
172+
CREATE TABLE test_concat_ws_1 (id INT, a ARRAY<VARCHAR>, b ARRAY<VARCHAR>) ENGINE=OLAP DISTRIBUTED BY HASH(id) BUCKETS 1 PROPERTIES ('replication_num' = '1')
173+
174+
INSERT INTO test_concat_ws_1 VALUES (1, ['a','b'], ['css',null,'d']), (2, ['x',null], ['y','z']),(3,['你好','世界'],['Doris',null,'Nereids'])
175+
176+
SELECT concat_ws('-', a, b) FROM test_concat_ws_1 ORDER BY id
177+
178+
```
179+
180+
```text
181+
182+
+-----------------------------+
183+
| concat_ws('-', a, b) |
184+
+-----------------------------+
185+
| a-b-css-d |
186+
| x-y-z |
187+
| 你好-世界-Doris-Nereids |
188+
+-----------------------------+
84189
```

i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/string-functions/concat-ws.md

Lines changed: 112 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,34 +26,34 @@ under the License.
2626

2727
## 描述
2828

29-
使用第一个参数 sep 作为连接符,将第二个参数以及后续所有参数 (或 ARRAY 中的所有字符串) 拼接成一个字符串。特殊情况:
30-
31-
- 如果分隔符是 NULL,返回 NULL。
32-
33-
`CONCAT_WS`函数不会跳过空字符串,会跳过 NULL 值。
29+
使用第一个参数sep作为连接符,将第二个参数及后续所有参数(或一个数组、多个数组中的所有字符串)拼接成一个字符串。特殊情况:
3430

31+
- 若分隔符为 NULL,则返回 NULL。​
32+
- CONCAT_WS函数不跳过空字符串(""),但会跳过 NULL 值。​
33+
- CONCAT_WS函数不跳过任何数组参数中的空字符串,但会跳过数组或参数中的 NULL 值。​
34+
- 第一个参数必须为字符串类型(string 或 varchar),其他参数必须为相同类型,即均为字符串类型(string 或 varchar)或均为数组类型(ARRAY)。
3535
## 语法
3636

3737
```sql
3838
CONCAT_WS ( <sep> , <str> [ , <str> ] )
39-
CONCAT_WS ( <sep> , <array> )
39+
CONCAT_WS ( <sep> , <array> [ , <array> ])
4040
```
4141

4242
## 参数
4343

4444
| 参数 | 说明 |
4545
|-------|-----------------|
46-
| `<sep>` | 拼接字符串的连接符 |
47-
| `<str>` | 需要被拼接的字符串 |
48-
| `<array>` | 需要被拼接的 array 数组 |
46+
| `<sep>` | 用于拼接字符串的连接符,类型为 string 或 varchar |
47+
| `<str>` | 待拼接的字符串,类型为 string 或 varchar |
48+
| `<array>` | 待拼接的数组,类型为 ARRAY,且数组元素为 string 或 varchar |
4949

5050

5151
## 返回值
5252

5353
参数 `<sep>` 或者 `<array>` 数组使用 `<str>` 拼接后字符串。特殊情况:
5454

5555
- 如果分隔符是 NULL,返回 NULL。
56-
56+
- 如果多个数组参数中含有NULL参数,则返回空字符串
5757
## 举例
5858

5959
将字符串通过 or 拼接到一起
@@ -82,4 +82,106 @@ SELECT CONCAT_WS("or", ["d", "is"]),CONCAT_WS(NULL, ["d", "is"]),CONCAT_WS("or",
8282
+------------------------------+------------------------------+------------------------------------+
8383
| doris | NULL | doris |
8484
+------------------------------+------------------------------+------------------------------------+
85+
```
86+
拼接多个数组
87+
88+
```sql
89+
mysql> SELECT CONCAT_WS("-", ["a", "b"], ["c", NULL], ["d"]);
90+
91+
+------------------------------------------------+
92+
| CONCAT_WS("-", ["a", "b"], ["c", NULL], ["d"]) |
93+
+------------------------------------------------+
94+
| a-b-c-d |
95+
+------------------------------------------------+
96+
```
97+
98+
如果在多个数组参数中包含NULL参数,则返回空字符串;
99+
100+
```sql
101+
mysql> SELECT CONCAT_WS("-", ["a", "b"], null,["c", NULL], ["d"]);
102+
+-----------------------------------------------------+
103+
| CONCAT_WS("-", ["a", "b"], null,["c", NULL], ["d"]) |
104+
+-----------------------------------------------------+
105+
| |
106+
+-----------------------------------------------------+
107+
```
108+
109+
处理空字符串
110+
111+
```sql
112+
mysql> SELECT CONCAT_WS("|", "hello", "", "world", NULL);
113+
114+
+--------------------------------------------+
115+
| CONCAT_WS("|", "hello", "", "world", NULL) |
116+
+--------------------------------------------+
117+
| hello||world |
118+
+--------------------------------------------+
119+
```
120+
121+
混合字符串和数组(无效)
122+
123+
```sql
124+
mysql> SELECT CONCAT_WS(",", "a", ["b", "c"]);
125+
126+
ERROR 1105 (HY000): errCode = 2, detailMessage = can not cast from origin type ARRAY<VARCHAR(1)> to target type=VARCHAR(65533)
127+
128+
```
129+
130+
全为 NULL 的输入
131+
132+
```sql
133+
mysql> SELECT CONCAT_WS("x", NULL, NULL);
134+
135+
+----------------------------+
136+
| CONCAT_WS("x", NULL, NULL) |
137+
+----------------------------+
138+
| |
139+
+----------------------------+
140+
```
141+
142+
Chiese Charactors concat
143+
144+
```sql
145+
mysql> SELECT CONCAT_WS("x", '中文', '中文');
146+
147+
+------------------------------------+
148+
| CONCAT_WS("x", '中文', '中文') |
149+
+------------------------------------+
150+
| 中文x中文 |
151+
+------------------------------------+
152+
```
153+
154+
中文字符拼接
155+
156+
```sql
157+
mysql> SELECT CONCAT_WS("x", ['中文'], ['中文']);
158+
+----------------------------------------+
159+
| CONCAT_WS("x", ['中文'], ['中文']) |
160+
+----------------------------------------+
161+
| 中文x中文 |
162+
+----------------------------------------+
163+
```
164+
165+
插入数据并拼接
166+
167+
```sql
168+
DROP TABLE IF EXISTS test_concat_ws_1;
169+
170+
CREATE TABLE test_concat_ws_1 (id INT, a ARRAY<VARCHAR>, b ARRAY<VARCHAR>) ENGINE=OLAP DISTRIBUTED BY HASH(id) BUCKETS 1 PROPERTIES ('replication_num' = '1')
171+
172+
INSERT INTO test_concat_ws_1 VALUES (1, ['a','b'], ['css',null,'d']), (2, ['x',null], ['y','z']),(3,['你好','世界'],['Doris',null,'Nereids'])
173+
174+
SELECT concat_ws('-', a, b) FROM test_concat_ws_1 ORDER BY id
175+
176+
```
177+
178+
```text
179+
180+
+-----------------------------+
181+
| concat_ws('-', a, b) |
182+
+-----------------------------+
183+
| a-b-css-d |
184+
| x-y-z |
185+
| 你好-世界-Doris-Nereids |
186+
+-----------------------------+
85187
```

0 commit comments

Comments
 (0)