Skip to content

Commit 783c1df

Browse files
zhangstar333ixzc
authored andcommitted
[doc](function) update some array function doc (#1881)
## Versions - [x] dev - [ ] 3.0 - [ ] 2.1 - [ ] 2.0 ## Languages - [x] Chinese - [x] English ## Docs Checklist - [ ] Checked by AI - [ ] Test Cases Built
1 parent 76c373f commit 783c1df

File tree

20 files changed

+795
-480
lines changed

20 files changed

+795
-480
lines changed

docs/sql-manual/sql-functions/scalar-functions/array-functions/array-count.md

+44-30
Original file line numberDiff line numberDiff line change
@@ -24,66 +24,86 @@ specific language governing permissions and limitations
2424
under the License.
2525
-->
2626

27-
## array_count
27+
## Description
2828

29-
array_count
29+
Use lambda expressions as input parameters to perform corresponding expression calculations on the internal data of other input ARRAY parameters.
30+
Returns the number of elements such that the return value of `lambda(array1[i], ...)` is not 0. Returns 0 if no element is found that satisfies this condition.
31+
32+
There are one or more parameters are input in the lambda expression, which must be consistent with the number of input array columns later.The number of elements of all input arrays must be the same. Legal scalar functions can be executed in lambda, aggregate functions, etc. are not supported.
3033

31-
### description
34+
## Syntax
3235

3336
```sql
34-
array_count(lambda, array1, ...)
37+
ARRAY_COUNT(<arr>),
38+
ARRAY_COUNT(<lambda>, <arr>[, ... ])
3539
```
3640

41+
## Parameters
3742

38-
Use lambda expressions as input parameters to perform corresponding expression calculations on the internal data of other input ARRAY parameters.
39-
Returns the number of elements such that the return value of `lambda(array1[i], ...)` is not 0. Returns 0 if no element is found that satisfies this condition.
40-
41-
There are one or more parameters are input in the lambda expression, which must be consistent with the number of input array columns later.The number of elements of all input arrays must be the same. Legal scalar functions can be executed in lambda, aggregate functions, etc. are not supported.
43+
| Parameter | Description |
44+
| --- | --- |
45+
| `<lambda>` | A lambda expression where the input parameters must match the number of columns in the given array. The expression can execute valid scalar functions but does not support aggregate functions. |
46+
| `<arr>` | ARRAY array |
4247

48+
## Return Value
4349

44-
```
45-
array_count(x->x, array1);
46-
array_count(x->(x%2 = 0), array1);
47-
array_count(x->(abs(x)-1), array1);
48-
array_count((x,y)->(x = y), array1, array2);
49-
```
50+
After applying the lambda expression, returns the number of non-zero elements in the ARRAY. If no such elements are found, returns 0.
5051

51-
### example
52+
## Example
5253

54+
```sql
55+
select array_count(x -> x, [0, 1, 2, 3]);
5356
```
54-
mysql> select array_count(x -> x, [0, 1, 2, 3]);
57+
58+
```text
5559
+--------------------------------------------------------+
5660
| array_count(array_map([x] -> x(0), ARRAY(0, 1, 2, 3))) |
5761
+--------------------------------------------------------+
5862
| 3 |
5963
+--------------------------------------------------------+
60-
1 row in set (0.00 sec)
64+
```
65+
66+
```sql
67+
select array_count(x -> x > 2, [0, 1, 2, 3]);
68+
```
6169

62-
mysql> select array_count(x -> x > 2, [0, 1, 2, 3]);
70+
```text
6371
+------------------------------------------------------------+
6472
| array_count(array_map([x] -> x(0) > 2, ARRAY(0, 1, 2, 3))) |
6573
+------------------------------------------------------------+
6674
| 1 |
6775
+------------------------------------------------------------+
68-
1 row in set (0.01 sec)
76+
```
77+
78+
```sql
79+
select array_count(x -> x is null, [null, null, null, 1, 2]);
80+
```
6981

70-
mysql> select array_count(x -> x is null, [null, null, null, 1, 2]);
82+
```text
7183
+----------------------------------------------------------------------------+
7284
| array_count(array_map([x] -> x(0) IS NULL, ARRAY(NULL, NULL, NULL, 1, 2))) |
7385
+----------------------------------------------------------------------------+
7486
| 3 |
7587
+----------------------------------------------------------------------------+
76-
1 row in set (0.01 sec)
88+
```
89+
90+
```sql
91+
select array_count(x -> power(x,2)>10, [1, 2, 3, 4, 5]);
92+
```
7793

78-
mysql> select array_count(x -> power(x,2)>10, [1, 2, 3, 4, 5]);
94+
```text
7995
+------------------------------------------------------------------------------+
8096
| array_count(array_map([x] -> power(x(0), 2.0) > 10.0, ARRAY(1, 2, 3, 4, 5))) |
8197
+------------------------------------------------------------------------------+
8298
| 2 |
8399
+------------------------------------------------------------------------------+
84-
1 row in set (0.01 sec)
100+
```
101+
102+
```sql
103+
select *, array_count((x, y) -> x>y, c_array1, c_array2) from array_test;
104+
```
85105

86-
mysql> select *, array_count((x, y) -> x>y, c_array1, c_array2) from array_test;
106+
```text
87107
+------+-----------------+-------------------------+-----------------------------------------------------------------------+
88108
| id | c_array1 | c_array2 | array_count(array_map([x, y] -> x(0) > y(1), `c_array1`, `c_array2`)) |
89109
+------+-----------------+-------------------------+-----------------------------------------------------------------------+
@@ -94,11 +114,5 @@ mysql> select *, array_count((x, y) -> x>y, c_array1, c_array2) from array_test;
94114
| 5 | [] | [] | 0 |
95115
| 6 | NULL | NULL | 0 |
96116
+------+-----------------+-------------------------+-----------------------------------------------------------------------+
97-
6 rows in set (0.02 sec)
98-
99117
```
100118

101-
### keywords
102-
103-
ARRAY, COUNT, ARRAY_COUNT
104-

docs/sql-manual/sql-functions/scalar-functions/array-functions/array-exists.md

+45-33
Original file line numberDiff line numberDiff line change
@@ -24,36 +24,38 @@ specific language governing permissions and limitations
2424
under the License.
2525
-->
2626

27-
## array_exists
27+
## Description
28+
29+
Use an optional lambda expression as an input parameter to perform corresponding expression calculations on the internal data of other input ARRAY parameters. Returns 1 when the calculation returns something other than 0; otherwise returns 0.
30+
There are one or more parameters input in the lambda expression, which must be consistent with the number of input array columns later. Legal scalar functions can be executed in lambda, aggregate functions, etc. are not supported.
31+
When lambda expression is not used as a parameter, array1 is used as the calculation result.
2832

29-
array_exists(lambda,array1,array2....)
30-
array_exists(array1)
3133

32-
### description
34+
## Syntax
3335

34-
#### Syntax
3536
```sql
36-
BOOLEAN array_exists(lambda, ARRAY<T> arr1, ARRAY<T> arr2, ... )
37-
BOOLEAN array_exists(ARRAY<T> arr)
37+
ARRAY_EXISTS(<arr>)
38+
ARRAY_EXISTS(<lambda>, <arr> [, ...] )
3839
```
3940

40-
Use an optional lambda expression as an input parameter to perform corresponding expression calculations on the internal data of other input ARRAY parameters. Returns 1 when the calculation returns something other than 0; otherwise returns 0.
41-
There are one or more parameters input in the lambda expression, which must be consistent with the number of input array columns later. Legal scalar functions can be executed in lambda, aggregate functions, etc. are not supported.
42-
When lambda expression is not used as a parameter, array1 is used as the calculation result.
41+
## Parameters
4342

44-
```
45-
array_exists(x->x, array1);
46-
array_exists(x->(x%2 = 0), array1);
47-
array_exists(x->(abs(x)-1), array1);
48-
array_exists((x,y)->(x = y), array1, array2);
49-
array_exists(array1);
50-
```
43+
| Parameter | Description |
44+
| --- | --- |
45+
| `<lambda>` | A lambda expression where the input parameters must match the number of columns in the given array. The expression can execute valid scalar functions but does not support aggregate functions. |
46+
| `<arr>` | ARRAY array |
47+
48+
## Return Value
5149

52-
### example
50+
Performs the specified expression calculation on the internal data of the input ARRAY parameter. Returns 1 if the calculation result is non-zero; otherwise, returns 0.
51+
52+
## Example
5353

5454
```sql
55+
select *, array_exists(x->x>1,[1,2,3]) from array_test2 order by id;
56+
```
5557

56-
mysql [test]>select *, array_exists(x->x>1,[1,2,3]) from array_test2 order by id;
58+
```text
5759
+------+-----------------+-------------------------+-----------------------------------------------+
5860
| id | c_array1 | c_array2 | array_exists([x] -> x(0) > 1, ARRAY(1, 2, 3)) |
5961
+------+-----------------+-------------------------+-----------------------------------------------+
@@ -62,9 +64,13 @@ mysql [test]>select *, array_exists(x->x>1,[1,2,3]) from array_test2 order by id
6264
| 3 | [1] | [-100] | [0, 1, 1] |
6365
| 4 | NULL | NULL | [0, 1, 1] |
6466
+------+-----------------+-------------------------+-----------------------------------------------+
65-
4 rows in set (0.02 sec)
67+
```
68+
69+
```sql
70+
select c_array1, c_array2, array_exists(x->x%2=0,[1,2,3]) from array_test2 order by id;
71+
```
6672

67-
mysql [test]>select c_array1, c_array2, array_exists(x->x%2=0,[1,2,3]) from array_test2 order by id;
73+
```text
6874
+-----------------+-------------------------+---------------------------------------------------+
6975
| c_array1 | c_array2 | array_exists([x] -> x(0) % 2 = 0, ARRAY(1, 2, 3)) |
7076
+-----------------+-------------------------+---------------------------------------------------+
@@ -73,9 +79,13 @@ mysql [test]>select c_array1, c_array2, array_exists(x->x%2=0,[1,2,3]) from arra
7379
| [1] | [-100] | [0, 1, 0] |
7480
| NULL | NULL | [0, 1, 0] |
7581
+-----------------+-------------------------+---------------------------------------------------+
76-
4 rows in set (0.02 sec)
82+
```
83+
84+
```sql
85+
select c_array1, c_array2, array_exists(x->abs(x)-1,[1,2,3]) from array_test2 order by id;
86+
```
7787

78-
mysql [test]>select c_array1, c_array2, array_exists(x->abs(x)-1,[1,2,3]) from array_test2 order by id;
88+
```text
7989
+-----------------+-------------------------+----------------------------------------------------+
8090
| c_array1 | c_array2 | array_exists([x] -> abs(x(0)) - 1, ARRAY(1, 2, 3)) |
8191
+-----------------+-------------------------+----------------------------------------------------+
@@ -84,9 +94,13 @@ mysql [test]>select c_array1, c_array2, array_exists(x->abs(x)-1,[1,2,3]) from a
8494
| [1, NULL] | [-100] | [0, NULL] |
8595
| NULL | NULL | NULL |
8696
+-----------------+-------------------------+----------------------------------------------------+
87-
4 rows in set (0.02 sec)
97+
```
98+
99+
```sql
100+
select c_array1, c_array2, array_exists((x,y)->x>y,c_array1,c_array2) from array_test2 order by id;
101+
```
88102

89-
mysql [test]>select c_array1, c_array2, array_exists((x,y)->x>y,c_array1,c_array2) from array_test2 order by id;
103+
```text
90104
+-----------------+-------------------------+-------------------------------------------------------------+
91105
| c_array1 | c_array2 | array_exists([x, y] -> x(0) > y(1), `c_array1`, `c_array2`) |
92106
+-----------------+-------------------------+-------------------------------------------------------------+
@@ -95,9 +109,13 @@ mysql [test]>select c_array1, c_array2, array_exists((x,y)->x>y,c_array1,c_array
95109
| [1] | [-100] | [1] |
96110
| NULL | NULL | NULL |
97111
+-----------------+-------------------------+-------------------------------------------------------------+
98-
4 rows in set (0.02 sec)
112+
```
113+
114+
```sql
115+
select *, array_exists(c_array1) from array_test2 order by id;
116+
```
99117

100-
mysql [test]>select *, array_exists(c_array1) from array_test2 order by id;
118+
```text
101119
+------+-----------------+-------------------------+--------------------------+
102120
| id | c_array1 | c_array2 | array_exists(`c_array1`) |
103121
+------+-----------------+-------------------------+--------------------------+
@@ -106,11 +124,5 @@ mysql [test]>select *, array_exists(c_array1) from array_test2 order by id;
106124
| 3 | [0, NULL] | [-100] | [0, NULL] |
107125
| 4 | NULL | NULL | NULL |
108126
+------+-----------------+-------------------------+--------------------------+
109-
4 rows in set (0.02 sec)
110-
111127
```
112128

113-
### keywords
114-
115-
ARRAY,ARRAY_EXISTS
116-

docs/sql-manual/sql-functions/scalar-functions/array-functions/array-filter.md

+51-27
Original file line numberDiff line numberDiff line change
@@ -24,34 +24,36 @@ specific language governing permissions and limitations
2424
under the License.
2525
-->
2626

27-
## array_filter
27+
## Description
2828

29-
array_filter(lambda,array)
30-
31-
array array_filter(array arr, array_bool filter_column)
29+
Use the lambda expression as the input parameter to calculate and filter the data of the ARRAY column of the other input parameter.
30+
And filter out the values of 0 and NULL in the result.
3231

33-
### description
32+
## Syntax
3433

35-
#### Syntax
3634
```sql
37-
ARRAY<T> array_filter(lambda, ARRAY<T> arr)
38-
ARRAY<T> array_filter(ARRAY<T> arr, ARRAY<Bool> filter_column)
35+
ARRAY_FILTER(<lambda>, <arr>)
36+
ARRAY_FILTER(<arr>, <filter_column>)
3937
```
4038

41-
Use the lambda expression as the input parameter to calculate and filter the data of the ARRAY column of the other input parameter.
42-
And filter out the values of 0 and NULL in the result.
39+
## Parameters
4340

44-
```
45-
array_filter(x->x>0, array1);
46-
array_filter(x->(x+2)=10, array1);
47-
array_filter(x->(abs(x)-2)>0, array1);
48-
array_filter(c_array,[0,1,0]);
49-
```
41+
| Parameter | Description |
42+
| --- | --- |
43+
| `<lambda>` | A lambda expression where the input parameters must match the number of columns in the given array. The expression can execute valid scalar functions but does not support aggregate functions. |
44+
| `<arr>` | ARRAY array |
45+
46+
## Return Value
5047

51-
### example
48+
Performs the specified expression calculation on the internal data of the input ARRAY parameter, filtering out 0 and NULL values from the result.
5249

53-
```shell
54-
mysql [test]>select c_array,array_filter(c_array,[0,1,0]) from array_test;
50+
## Example
51+
52+
```sql
53+
select c_array,array_filter(c_array,[0,1,0]) from array_test;
54+
```
55+
56+
```text
5557
+-----------------+----------------------------------------------------+
5658
| c_array | array_filter(`c_array`, ARRAY(FALSE, TRUE, FALSE)) |
5759
+-----------------+----------------------------------------------------+
@@ -60,15 +62,25 @@ mysql [test]>select c_array,array_filter(c_array,[0,1,0]) from array_test;
6062
| [] | [] |
6163
| NULL | NULL |
6264
+-----------------+----------------------------------------------------+
65+
```
66+
67+
```sql
68+
select array_filter(x->(x > 1),[1,2,3,0,null]);
69+
```
6370

64-
mysql [test]>select array_filter(x->(x > 1),[1,2,3,0,null]);
71+
```text
6572
+----------------------------------------------------------------------------------------------+
6673
| array_filter(ARRAY(1, 2, 3, 0, NULL), array_map([x] -> (x(0) > 1), ARRAY(1, 2, 3, 0, NULL))) |
6774
+----------------------------------------------------------------------------------------------+
6875
| [2, 3] |
6976
+----------------------------------------------------------------------------------------------+
77+
```
78+
79+
```sql
80+
select *, array_filter(x->x>0,c_array2) from array_test2;
81+
```
7082

71-
mysql [test]>select *, array_filter(x->x>0,c_array2) from array_test2;
83+
```text
7284
+------+-----------------+-------------------------+------------------------------------------------------------------+
7385
| id | c_array1 | c_array2 | array_filter(`c_array2`, array_map([x] -> x(0) > 0, `c_array2`)) |
7486
+------+-----------------+-------------------------+------------------------------------------------------------------+
@@ -77,9 +89,13 @@ mysql [test]>select *, array_filter(x->x>0,c_array2) from array_test2;
7789
| 3 | [1] | [-100] | [] |
7890
| 4 | NULL | NULL | NULL |
7991
+------+-----------------+-------------------------+------------------------------------------------------------------+
80-
4 rows in set (0.01 sec)
92+
```
93+
94+
```sql
95+
select *, array_filter(x->x%2=0,c_array2) from array_test2;
96+
```
8197

82-
mysql [test]>select *, array_filter(x->x%2=0,c_array2) from array_test2;
98+
```text
8399
+------+-----------------+-------------------------+----------------------------------------------------------------------+
84100
| id | c_array1 | c_array2 | array_filter(`c_array2`, array_map([x] -> x(0) % 2 = 0, `c_array2`)) |
85101
+------+-----------------+-------------------------+----------------------------------------------------------------------+
@@ -88,8 +104,13 @@ mysql [test]>select *, array_filter(x->x%2=0,c_array2) from array_test2;
88104
| 3 | [1] | [-100] | [-100] |
89105
| 4 | NULL | NULL | NULL |
90106
+------+-----------------+-------------------------+----------------------------------------------------------------------+
107+
```
108+
109+
```sql
110+
select *, array_filter(x->(x*(-10)>0),c_array2) from array_test2;
111+
```
91112

92-
mysql [test]>select *, array_filter(x->(x*(-10)>0),c_array2) from array_test2;
113+
```text
93114
+------+-----------------+-------------------------+----------------------------------------------------------------------------+
94115
| id | c_array1 | c_array2 | array_filter(`c_array2`, array_map([x] -> (x(0) * (-10) > 0), `c_array2`)) |
95116
+------+-----------------+-------------------------+----------------------------------------------------------------------------+
@@ -98,8 +119,13 @@ mysql [test]>select *, array_filter(x->(x*(-10)>0),c_array2) from array_test2;
98119
| 3 | [1] | [-100] | [-100] |
99120
| 4 | NULL | NULL | NULL |
100121
+------+-----------------+-------------------------+----------------------------------------------------------------------------+
122+
```
123+
124+
```sql
125+
select *, array_filter(x->x>0, array_map((x,y)->(x>y), c_array1,c_array2)) as res from array_test2;
126+
```
101127

102-
mysql [test]>select *, array_filter(x->x>0, array_map((x,y)->(x>y), c_array1,c_array2)) as res from array_test2;
128+
```text
103129
+------+-----------------+-------------------------+--------+
104130
| id | c_array1 | c_array2 | res |
105131
+------+-----------------+-------------------------+--------+
@@ -110,7 +136,5 @@ mysql [test]>select *, array_filter(x->x>0, array_map((x,y)->(x>y), c_array1,c_a
110136
+------+-----------------+-------------------------+--------+
111137
```
112138

113-
### keywords
114139

115-
ARRAY,FILTER,ARRAY_FILTER
116140

0 commit comments

Comments
 (0)