Skip to content

Commit

Permalink
优化导航 - 调整函数文件和名称 (StarRocks#7068)
Browse files Browse the repository at this point in the history
* 优化导航 - 调整函数文件和名称

* Update replace.md

* Update TOC.md
  • Loading branch information
evelynzhaojie committed Nov 6, 2023
1 parent 15ccc92 commit 00c3780
Show file tree
Hide file tree
Showing 10 changed files with 230 additions and 9 deletions.
8 changes: 4 additions & 4 deletions TOC.md
Expand Up @@ -481,7 +481,7 @@
+ [str_to_map](/sql-reference/sql-functions/string-functions/str_to_map.md)
+ [strleft](/sql-reference/sql-functions/string-functions/strleft.md)
+ [strright](/sql-reference/sql-functions/string-functions/strright.md)
+ [substring](/sql-reference/sql-functions/string-functions/substr.md)
+ [substring](/sql-reference/sql-functions/string-functions/substring.md)
+ [trim](/sql-reference/sql-functions/string-functions/trim.md)
+ [ucase](/sql-reference/sql-functions/string-functions/ucase.md)
+ [unhex](/sql-reference/sql-functions/string-functions/unhex.md)
Expand Down Expand Up @@ -648,8 +648,8 @@
+ 模糊/正则匹配函数
+ [like](/sql-reference/sql-functions/like_predicate-functions/like.md)
+ [regexp](/sql-reference/sql-functions/like_predicate-functions/regexp.md)
+ [regexp_extract](/sql-reference/sql-functions/string-functions/regexp_extract.md)
+ [regexp_replace](/sql-reference/sql-functions/string-functions/regexp_replace.md)
+ [regexp_extract](/sql-reference/sql-functions/like_predicate-functions/regexp_extract.md)
+ [regexp_replace](/sql-reference/sql-functions/like_predicate-functions/regexp_replace.md)
+ 条件函数
+ [case](/sql-reference/sql-functions/condition-functions/case_when.md)
+ [coalesce](/sql-reference/sql-functions/condition-functions/coalesce.md)
Expand Down Expand Up @@ -763,7 +763,7 @@
+ [其他](/faq/Others.md)
+ 性能测试
+ [SSB Flat Table 性能测试](/benchmarking/SSB_Benchmarking.md)
+ [TPC-H 基准测试](/benchmarking/TPC-H_Benchmark.md)
+ [TPC-H 基准测试](/benchmarking/TPC-H_Benchmarking.md)
+ [TPC-DS 基准测试](/benchmarking/TPC_DS_Benchmark.md)
+ 开发指南
+ [编译 StarRocks](/developers/build-starrocks/Build_in_docker.md)
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion introduction/StarRocks_intro.md
Expand Up @@ -139,7 +139,7 @@
<NavBoxPartItem>

- [SSB 基准测试](../benchmarking/SSB_Benchmarking)
- [TPC-H 基准测试](../benchmarking/TPC-H_Benchmark)
- [TPC-H 基准测试](../benchmarking/TPC-H_Benchmarking)

</NavBoxPartItem>
</NavBoxPart>
Expand Down
176 changes: 176 additions & 0 deletions sql-reference/sql-functions/aggregate-functions/group_concat.md
@@ -0,0 +1,176 @@
# group_concat

## 功能

将分组中的多个非 NULL 值连接成一个字符串,参数 `sep` 为字符串之间的连接符,该参数可选,默认为 `,`。该函数在连接时会忽略 NULL 值。

从 3.0.6,3.1.3 版本开始,group_concat 支持使用 DISTINCT 和 ORDER BY。

## 语法

```Haskell
VARCHAR GROUP_CONCAT([DISTINCT] expr [,expr ...]
[ORDER BY {unsigned_integer | col_name | expr}
[ASC | DESC] [,col_name ...]]
[SEPARATOR sep])
```

## 参数说明

- `expr`: 待拼接的值,支持的数据类型为 VARCHAR。可以指定 DISTINCT 关键字在连接之前移除分组中的重复值。如果想直接连接多个值,可以使用 [concat](../string-functions/concat.md)[concat_ws](../string-functions/concat_ws.md) 来指定连接的方式。
- ORDER BY 后可以跟 unsigned_integer (从 1 开始)、列名、或普通表达式。ORDER BY 用于指定按升序或降序对要连接的值进行排序。默认按升序排序。如果要按降序排序,需要指定 DESC。
- `sep`:字符串之间的连接符,可选。如果不指定,则默认使用逗号 `,` 作为连接符。如果要使用空字符来连接,可以使用 `''`

> **NOTE**
>
> 从 v3.0.6 和 v3.1.3 版本起,分隔符必须使用 `SEPARATOR` 关键字来声明。 举例,`select group_concat(name SEPARATOR '-') as res from ss;`
## 返回值说明

返回值的数据类型为 VARCHAR。如果没有非 NULL 值,则返回 NULL。

您可以使用系统变量 [group_concat_max_len](../../../reference/System_variable.md#group_concat_max_len) 来控制可以返回的最大字符长度。默认值:1024。最小值:4。单位:字符。

变量的设置方法:

```sql
SET [GLOBAL | SESSION] group_concat_max_len = <value>
```

## 示例

1. 建表并插入数据。

```sql
CREATE TABLE `ss` (
`id` int(11) NULL COMMENT "",
`name` varchar(255) NULL COMMENT "",
`subject` varchar(255) NULL COMMENT "",
`score` int(11) NULL COMMENT ""
) ENGINE=OLAP
DUPLICATE KEY(`id`)
DISTRIBUTED BY HASH(`id`) BUCKETS 4
PROPERTIES (
"replication_num" = "1"
);

insert into ss values (1,"Tom","English",90);
insert into ss values (1,"Tom","Math",80);
insert into ss values (2,"Tom","English",NULL);
insert into ss values (2,"Tom",NULL,NULL);
insert into ss values (3,"May",NULL,NULL);
insert into ss values (3,"Ti","English",98);
insert into ss values (4,NULL,NULL,NULL);
insert into ss values (NULL,"Ti","Phy",98);

select * from ss order by id;
+------+------+---------+-------+
| id | name | subject | score |
+------+------+---------+-------+
| NULL | Ti | Phy | 98 |
| 1 | Tom | English | 90 |
| 1 | Tom | Math | 80 |
| 2 | Tom | English | NULL |
| 2 | Tom | NULL | NULL |
| 3 | May | NULL | NULL |
| 3 | Ti | English | 98 |
| 4 | NULL | NULL | NULL |
+------+------+---------+-------+
```

2. 使用 group_concat 对值进行拼接。

示例一:对 `name` 列的值进行拼接,使用默认连接符,忽略 NULL 值。不对数据进行去重。

```plain
select group_concat(name) as res from ss;
+---------------------------+
| res |
+---------------------------+
| Tom,Tom,Ti,Tom,Tom,May,Ti |
+---------------------------+
```

示例二:对 `name` 列的值进行拼接,使用 `SEPARATOR` 来声明分隔符 `-`,忽略 NULL 值。不对数据进行去重。

```sql
select group_concat(name SEPARATOR '-') as res from ss;
+---------------------------+
| res |
+---------------------------+
| Ti-May-Ti-Tom-Tom-Tom-Tom |
+---------------------------+
```

示例三:对 `name` 列的值进行拼接,使用默认连接符,忽略 NULL 值。使用 DISTINCT 对数据进行去重。

```plain
select group_concat(distinct name) as res from ss;
+---------------------------+
| res |
+---------------------------+
| Ti,May,Tom |
+---------------------------+
```

示例四:将相同 ID 的 `name``subject` 组合按照 `score` 的升序进行连接。比如返回示例中的第二行数据 `TomMath,TomEnglish` 就是将 ID 为 1 的 `TomMath` and `TomEnglish` 组合按照 `score` 进行升序排序。

```plain
select id, group_concat(distinct name,subject order by score) as res from ss group by id order by id;
+------+--------------------+
| id | res |
+------+--------------------+
| NULL | TiPhy |
| 1 | TomMath,TomEnglish |
| 2 | TomEnglish |
| 3 | TiEnglish |
| 4 | NULL |
+------+--------------------+
```

示例五:在 group_concat 中嵌套 concat 函数。concat 指定 `name``subject` 的连接格式为 "name-subject"。查询逻辑和示例三相同。

```plain
select id, group_concat(distinct concat(name,'-',subject) order by score) as res from ss group by id order by id;
+------+----------------------+
| id | res |
+------+----------------------+
| NULL | Ti-Phy |
| 1 | Tom-Math,Tom-English |
| 2 | Tom-English |
| 3 | Ti-English |
| 4 | NULL |
+------+----------------------+
```

示例六:没有符合条件的结果,返回 NULL。

```plain
select group_concat(distinct name) as res from ss where id < 0;
+------+
| res |
+------+
| NULL |
+------+
```

示例七:将返回字符串的最大长度限制在 6 个字符。查询逻辑和示例三相同。

```plain
set group_concat_max_len = 6;
select id, group_concat(distinct name,subject order by score) as res from ss group by id order by id;
+------+--------+
| id | res |
+------+--------+
| NULL | TiPhy |
| 1 | TomMat |
| 2 | NULL |
| 3 | TiEngl |
| 4 | NULL |
+------+--------+
```

## keywords

GROUP_CONCAT,CONCAT,ARRAY_AGG
45 changes: 45 additions & 0 deletions sql-reference/sql-functions/array-functions/reverse.md
@@ -0,0 +1,45 @@
# reverse

## 功能

将字符串或数组反转,返回的字符串或数组的顺序和源字符串或数组的顺序相反。

## 语法

```Haskell
reverse(param)
```

## 参数说明

`param`:需要反转的字符串或数组,目前只支持一维数组且数组元素的数据类型不允许为 `DECIMAL``param` 支持的数据类型为 VARCHAR、CHAR、ARRAY。

数组中的元素支持以下类型:BOOLEAN、TINYINT、SMALLINT、INT、BIGINT、LARGEINT、FLOAT、DOUBLE、VARCHAR、DECIMALV2、DATETIME、DATE、JSON。**从 2.5 版本开始,该函数支持 JSON 类型的数组元素。**

## 返回值说明

返回的数据类型与 `param` 一致。

## 示例

反转字符串。

```Plain Text
MySQL > SELECT REVERSE('hello');
+------------------+
| REVERSE('hello') |
+------------------+
| olleh |
+------------------+
```

反转数组。

```Plain Text
MYSQL> SELECT REVERSE([4,1,5,8]);
+--------------------+
| REVERSE([4,1,5,8]) |
+--------------------+
| [8,5,1,4] |
+--------------------+
```
6 changes: 3 additions & 3 deletions sql-reference/sql-functions/function-list.md
Expand Up @@ -140,7 +140,7 @@ StarRocks 提供了丰富的函数,方便您在日常数据查询和分析时
| [str_to_map](./string-functions/str_to_map.md) | 将给定的字符串分割成键值对 (Key-Value pair),返回包含这些键值对的 Map。 |
| [strleft](./string-functions/strleft.md) | 从字符串左边部分返回指定长度的字符。 |
| [strright](./string-functions/strright.md) | 从字符串右边部分返回指定长度的字符。 |
| [substr, substring](./string-functions/substr.md) | 返回字符串中从位置 pos 开始的指定长度的子字符串。 |
| [substr, substring](./string-functions/substring.md) | 返回字符串中从位置 pos 开始的指定长度的子字符串。 |
| [trim](./string-functions/trim.md) | 从字符串的左侧和右侧移除连续出现的空格或指定的字符。 |
| [ucase](./string-functions/ucase.md) | 该函数与 upper 一致,将字符串转换为大写形式。 |
| [unhex](./string-functions/unhex.md) | 将输入的字符串中的两个字符为一组转化为 16 进制的字符,然后拼接成字符串输出。 |
Expand Down Expand Up @@ -396,8 +396,8 @@ StarRocks 提供了丰富的函数,方便您在日常数据查询和分析时
| :-: | :-: |
| [like](./like_predicate-functions/like.md) | 判断字符串是否**模糊匹配**给定的模式 `pattern`|
| [regexp](./like_predicate-functions/regexp.md) | 判断字符串是否匹配给定的正则表达式 `pattern`|
| [regexp_extract](./string-functions/regexp_extract.md) | 对字符串进行正则匹配,抽取符合 pattern 的第 pos 个匹配部分,需要 pattern 完全匹配 str 中的某部分,才能返回 pattern 部分中需匹配部分,如果没有匹配就返回空字符串。 |
| [regexp_replace](./string-functions/regexp_replace.md) | 对字符串进行正则匹配,将命中 pattern 的部分使用 repl 来进行替换。 |
| [regexp_extract](./like_predicate-functions/regexp_extract.md) | 对字符串进行正则匹配,抽取符合 pattern 的第 pos 个匹配部分,需要 pattern 完全匹配 str 中的某部分,才能返回 pattern 部分中需匹配部分,如果没有匹配就返回空字符串。 |
| [regexp_replace](./like_predicate-functions/regexp_replace.md) | 对字符串进行正则匹配,将命中 pattern 的部分使用 repl 来进行替换。 |

## 条件函数

Expand Down
2 changes: 1 addition & 1 deletion sql-reference/sql-functions/string-functions/replace.md
Expand Up @@ -8,7 +8,7 @@

> **注意**
>
> 在 3.0 版本之前,该函数通过 [regexp_replace](../string-functions/regexp_replace.md) 来实现。
> 在 3.0 版本之前,该函数通过 [regexp_replace](../like_predicate-functions/regexp_replace.md) 来实现。
## 语法

Expand Down

0 comments on commit 00c3780

Please sign in to comment.