This is an automated email from the ASF dual-hosted git repository. kassiez pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/doris-website.git
The following commit(s) were added to refs/heads/master by this push: new 4099ea059f0 [doc] Modify the documentation of functions of array, array_apply, array_avg, array_compact, array_concat,array_cum_sum,array_difference (#1865) 4099ea059f0 is described below commit 4099ea059f06e975d10e9cf98514af771ae73b68 Author: ZhenchaoXu <49646212+i...@users.noreply.github.com> AuthorDate: Thu Jan 23 16:55:50 2025 +0800 [doc] Modify the documentation of functions of array, array_apply, array_avg, array_compact, array_concat,array_cum_sum,array_difference (#1865) Modify the documentation of functions of array, array_apply, array_avg, array_compact, array_concat,array_cum_sum,array_difference ## Versions - [x] dev - [x] 3.0 - [x] 2.1 - [ ] 2.0 ## Languages - [x] Chinese - [x] English ## Docs Checklist - [ ] Checked by AI - [ ] Test Cases Built --- .../array-functions/array-apply.md | 47 ++++++------- .../scalar-functions/array-functions/array-avg.md | 60 ++++++++++------ .../array-functions/array-compact.md | 49 +++++++------ .../array-functions/array-concat.md | 69 +++++++++++++------ .../array-functions/array-cum-sum.md | 54 +++++++++------ .../array-functions/array-difference.md | 53 +++++++++----- .../scalar-functions/array-functions/array.md | 80 +++++++++++++--------- .../array-functions/array-apply.md | 37 ++++------ .../scalar-functions/array-functions/array-avg.md | 53 +++++++++----- .../array-functions/array-compact.md | 43 +++++------- .../array-functions/array-concat.md | 62 ++++++++++++----- .../array-functions/array-cum-sum.md | 43 +++++++----- .../array-functions/array-difference.md | 44 ++++++++---- .../scalar-functions/array-functions/array.md | 72 +++++++++++-------- .../array-functions/array-apply.md | 37 ++++------ .../scalar-functions/array-functions/array-avg.md | 52 +++++++++----- .../array-functions/array-compact.md | 43 +++++------- .../array-functions/array-concat.md | 62 ++++++++++++----- .../array-functions/array-cum-sum.md | 45 +++++++----- .../array-functions/array-difference.md | 47 +++++++++---- .../scalar-functions/array-functions/array.md | 72 +++++++++++-------- .../array-functions/array-apply.md | 37 ++++------ .../scalar-functions/array-functions/array-avg.md | 53 +++++++++----- .../array-functions/array-compact.md | 45 ++++++------ .../array-functions/array-concat.md | 62 ++++++++++++----- .../array-functions/array-cum-sum.md | 44 +++++++----- .../array-functions/array-difference.md | 48 +++++++++---- .../scalar-functions/array-functions/array.md | 73 ++++++++++++-------- .../array-functions/array-apply.md | 46 ++++++------- .../scalar-functions/array-functions/array-avg.md | 60 ++++++++++------ .../array-functions/array-compact.md | 50 +++++++------- .../array-functions/array-concat.md | 69 +++++++++++++------ .../array-functions/array-cum-sum.md | 54 +++++++++------ .../array-functions/array-difference.md | 54 ++++++++++----- .../scalar-functions/array-functions/array.md | 79 ++++++++++++--------- .../array-functions/array-apply.md | 46 ++++++------- .../scalar-functions/array-functions/array-avg.md | 60 ++++++++++------ .../array-functions/array-compact.md | 49 +++++++------ .../array-functions/array-concat.md | 69 +++++++++++++------ .../array-functions/array-cum-sum.md | 54 +++++++++------ .../array-functions/array-difference.md | 49 +++++++++---- .../scalar-functions/array-functions/array.md | 78 ++++++++++++--------- 42 files changed, 1399 insertions(+), 904 deletions(-) diff --git a/docs/sql-manual/sql-functions/scalar-functions/array-functions/array-apply.md b/docs/sql-manual/sql-functions/scalar-functions/array-functions/array-apply.md index ded252b168d..1c7027e1732 100644 --- a/docs/sql-manual/sql-functions/scalar-functions/array-functions/array-apply.md +++ b/docs/sql-manual/sql-functions/scalar-functions/array-functions/array-apply.md @@ -21,53 +21,46 @@ KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> - -## array_apply - -array_apply - -### description +## Description Filter array to match specific binary condition -#### Syntax +## Syntax ```sql -array_apply(arr, op, val) +ARRAY_APPLY(<arr>, <op>, <val>) ``` -#### Arguments - -`arr` — The array to inspect. If it null, null will be returned. -`op` — The compare operation, op includes `=`, `>=`, `<=`, `>`, `<`, `!=`. Support const value only. -`val` — The compared value.If it null, null will be returned. Support const value only. +## Parameters +| Parameter | Description | +|---|---| +| `<arr>` | Input array | +| `<op>` | Filter condition, including `=`, `>=`, `<=`, `>`, `<`, `!=` | +| `<val>` | Filter value. If `null`, the result will be `null`. Only constant values are supported. | -#### Returned value +## Return Value The filtered array matched with condition. -Type: Array. - -### example +## Example +```sql +select array_apply([1, 2, 3, 4, 5], ">=", 2); ``` -mysql> select array_apply([1, 2, 3, 4, 5], ">=", 2); +```text +--------------------------------------------+ | array_apply(ARRAY(1, 2, 3, 4, 5), '>=', 2) | +--------------------------------------------+ | [2, 3, 4, 5] | +--------------------------------------------+ -1 row in set (0.01 sec) - -mysql> select array_apply([1000000, 1000001, 1000002], "=", "1000002"); +``` +```sql +select array_apply([1000000, 1000001, 1000002], "=", "1000002"); +``` +```text +-------------------------------------------------------------+ | array_apply(ARRAY(1000000, 1000001, 1000002), '=', 1000002) | +-------------------------------------------------------------+ | [1000002] | +-------------------------------------------------------------+ -1 row in set (0.01 sec) -``` - -### keywords - -ARRAY,APPLY,ARRAY_APPLY \ No newline at end of file +``` \ No newline at end of file diff --git a/docs/sql-manual/sql-functions/scalar-functions/array-functions/array-avg.md b/docs/sql-manual/sql-functions/scalar-functions/array-functions/array-avg.md index 0de3886fc8c..f58c6e1eb5c 100644 --- a/docs/sql-manual/sql-functions/scalar-functions/array-functions/array-avg.md +++ b/docs/sql-manual/sql-functions/scalar-functions/array-functions/array-avg.md @@ -24,25 +24,42 @@ specific language governing permissions and limitations under the License. --> -## array_avg +## Description +Get the average of all elements in an array (`NULL` values are skipped). +When the array is empty or all elements in the array are `NULL` values, the function returns `NULL`. -array_avg +## Syntax +```sql +ARRAY_AVG(<arr>) +``` -### description -#### Syntax +## Parameters +| Parameter | Description | +|---|---| +| `<arr>` | The array to calculate the average values from | -`Array<T> array_avg(arr)` +## Return Value -Get the average of all elements in an array (`NULL` values are skipped). -When the array is empty or all elements in the array are `NULL` values, the function returns `NULL`. +Returns a constant. Special cases: +- `NULL` values in the array will be skipped. +- Strings and varchar in the array will be skipped. -### example +## Example -```shell -mysql> create table array_type_table(k1 INT, k2 Array<int>) duplicate key (k1) - -> distributed by hash(k1) buckets 1 properties('replication_num' = '1'); -mysql> insert into array_type_table values (0, []), (1, [NULL]), (2, [1, 2, 3]), (3, [1, NULL, 3]); -mysql> select k2, array_avg(k2) from array_type_table; +```sql +create table array_type_table( + k1 INT, + k2 Array<int> +) +duplicate key (k1) +distributed by hash(k1) buckets 1 +properties( + 'replication_num' = '1' +); +insert into array_type_table values (0, []), (1, [NULL]), (2, [1, 2, 3]), (3, [1, NULL, 3]); +select k2, array_avg(k2) from array_type_table; +``` +```text +--------------+-----------------+ | k2 | array_avg(`k2`) | +--------------+-----------------+ @@ -51,11 +68,14 @@ mysql> select k2, array_avg(k2) from array_type_table; | [1, 2, 3] | 2 | | [1, NULL, 3] | 2 | +--------------+-----------------+ -4 rows in set (0.01 sec) - ``` - -### keywords - -ARRAY,AVG,ARRAY_AVG - +```sql +select array_avg(['test',2,1,null]); +``` +```text ++------------------------------------------------------------+ +| array_avg(cast(['test', '2', '1', NULL] as ARRAY<DOUBLE>)) | ++------------------------------------------------------------+ +| 1.5 | ++------------------------------------------------------------+ +``` diff --git a/docs/sql-manual/sql-functions/scalar-functions/array-functions/array-compact.md b/docs/sql-manual/sql-functions/scalar-functions/array-functions/array-compact.md index 366f532cd8b..29b0aacf284 100644 --- a/docs/sql-manual/sql-functions/scalar-functions/array-functions/array-compact.md +++ b/docs/sql-manual/sql-functions/scalar-functions/array-functions/array-compact.md @@ -22,49 +22,50 @@ specific language governing permissions and limitations under the License. --> -## array_compact - -array_compact - -### description +## Description Removes consecutive duplicate elements from an array. The order of result values is determined by the order in the source array. -#### Syntax - -`Array<T> array_compact(arr)` - -#### Arguments - -`arr` — The array to inspect. +## Syntax +```sql +ARRAY_COMPACT(<arr>) +``` -#### Returned value +## Parameters +| Parameter | Description | +|---|---| +| `<arr>` | The array to remove consecutive duplicate elements from | -The array without continuous duplicate. +## Return Value -Type: Array. +An array without consecutive duplicate elements. -### example +## Example -``` +```sql select array_compact([1, 2, 3, 3, null, null, 4, 4]); - +``` +```text +----------------------------------------------------+ | array_compact(ARRAY(1, 2, 3, 3, NULL, NULL, 4, 4)) | +----------------------------------------------------+ | [1, 2, 3, NULL, 4] | +----------------------------------------------------+ - +``` +```sql select array_compact(['aaa','aaa','bbb','ccc','ccccc',null, null,'dddd']); - +``` +```text +-------------------------------------------------------------------------------+ | array_compact(ARRAY('aaa', 'aaa', 'bbb', 'ccc', 'ccccc', NULL, NULL, 'dddd')) | +-------------------------------------------------------------------------------+ | ['aaa', 'bbb', 'ccc', 'ccccc', NULL, 'dddd'] | +-------------------------------------------------------------------------------+ - +``` +```sql select array_compact(['2015-03-13','2015-03-13']); - +``` +```text +--------------------------------------------------+ | array_compact(ARRAY('2015-03-13', '2015-03-13')) | +--------------------------------------------------+ @@ -72,7 +73,3 @@ select array_compact(['2015-03-13','2015-03-13']); +--------------------------------------------------+ ``` -### keywords - -ARRAY,COMPACT,ARRAY_COMPACT - diff --git a/docs/sql-manual/sql-functions/scalar-functions/array-functions/array-concat.md b/docs/sql-manual/sql-functions/scalar-functions/array-functions/array-concat.md index 6454bb9b2a7..c6579e8b715 100644 --- a/docs/sql-manual/sql-functions/scalar-functions/array-functions/array-concat.md +++ b/docs/sql-manual/sql-functions/scalar-functions/array-functions/array-concat.md @@ -22,36 +22,69 @@ specific language governing permissions and limitations under the License. --> -## array_concat - -array_concat - -### description +### Description Concat all arrays passed in the arguments -#### Syntax - -`Array<T> array_concat(Array<T>, ...)` +## Syntax +```sql +ARRAY_CONCAT(<arr1> [,<arr2> , ...]) +``` -#### Returned value +## Parameters +| Parameter | Description | +|---|---| +| `<arr1>` | The source array | +| `<arr2>` | The array to be appended to arr1 | -The concated array. +## Return Value -Type: Array. +The concatenated array. Special cases: +- If an array is NULL (not `[NULL]`), the function returns NULL. -### example +## Example +```sql +select array_concat([1, 2], [7, 8], [5, 6]); ``` -mysql> select array_concat([1, 2], [7, 8], [5, 6]); +```text +-----------------------------------------------------+ | array_concat(ARRAY(1, 2), ARRAY(7, 8), ARRAY(5, 6)) | +-----------------------------------------------------+ | [1, 2, 7, 8, 5, 6] | +-----------------------------------------------------+ -1 row in set (0.02 sec) +``` +```sql +select array_concat([1, 2], [7, 8], [5, 6], NULL); +``` +```text ++--------------------------------------------+ +| array_concat([1, 2], [7, 8], [5, 6], NULL) | ++--------------------------------------------+ +| NULL | ++--------------------------------------------+ +``` + +```sql +CREATE TABLE array_test ( + id int, + col2 ARRAY<INT>, + col3 ARRAY<INT> +) +duplicate key (id) +distributed by hash(id) buckets 1 +properties( + 'replication_num' = '1' +); +INSERT INTO array_test (id, col2, col3) VALUES +(1,[1, 2, 3], [3, 4, 5]), +(2,[1, NULL, 2], [NULL]), +(3,[1, 2, 3], NULL), +(4,[], []); -mysql> select col2, col3, array_concat(col2, col3) from array_test; +select col2, col3, array_concat(col2, col3) from array_test; +``` +```text +--------------+-----------+------------------------------+ | col2 | col3 | array_concat(`col2`, `col3`) | +--------------+-----------+------------------------------+ @@ -60,8 +93,4 @@ mysql> select col2, col3, array_concat(col2, col3) from array_test; | [1, 2, 3] | NULL | NULL | | [] | [] | [] | +--------------+-----------+------------------------------+ -``` - -### keywords - -ARRAY,CONCAT,ARRAY_CONCAT \ No newline at end of file +``` \ No newline at end of file diff --git a/docs/sql-manual/sql-functions/scalar-functions/array-functions/array-cum-sum.md b/docs/sql-manual/sql-functions/scalar-functions/array-functions/array-cum-sum.md index 80acaa728ad..030b4118c80 100644 --- a/docs/sql-manual/sql-functions/scalar-functions/array-functions/array-cum-sum.md +++ b/docs/sql-manual/sql-functions/scalar-functions/array-functions/array-cum-sum.md @@ -22,27 +22,48 @@ specific language governing permissions and limitations under the License. --> -## array_cum_sum - -array_cum_sum - -### description +## Description Get the cumulative sum of an array (`NULL` values are skipped). If the array contains `NULL` values, then `NULL` is set at the same position in the result array. -#### Syntax +## Syntax ```sql -Array<T> array_cum_sum(Array<T>) +ARRAY_CUM_SUM(<arr>) ``` -### example +## Parameters + +| Parameter | Description | +|---|---| +| `<arr>` | The array to calculate the cumulative sum from | + +## Return Value + +Returns an array. Special cases: +- `NULL` values in the array are skipped, and `NULL` is set at the same position in the result array. + + +## Example -```shell -mysql> create table array_type_table(k1 INT, k2 Array<int>) duplicate key (k1) distributed by hash(k1) buckets 1 properties('replication_num' = '1'); -mysql> insert into array_type_table values (0, []), (1, [NULL]), (2, [1, 2, 3, 4]), (3, [1, NULL, 3, NULL, 5]); -mysql> select k2, array_cum_sum(k2) from array_type_table; +```sql +create table array_type_table( + k1 INT, + k2 Array<int> +) +duplicate key (k1) +distributed by hash(k1) buckets 1 +properties( + 'replication_num' = '1' +); +insert into array_type_table values (0, []), +(1, [NULL]), +(2, [1, 2, 3, 4]), +(3, [1, NULL, 3, NULL, 5]); +select k2, array_cum_sum(k2) from array_type_table; +``` +```text +-----------------------+-----------------------+ | k2 | array_cum_sum(`k2`) | +-----------------------+-----------------------+ @@ -51,11 +72,4 @@ mysql> select k2, array_cum_sum(k2) from array_type_table; | [1, 2, 3, 4] | [1, 3, 6, 10] | | [1, NULL, 3, NULL, 5] | [1, NULL, 4, NULL, 9] | +-----------------------+-----------------------+ - -4 rows in set -Time: 0.122s -``` - -### keywords - -ARRAY,CUM_SUM,ARRAY_CUM_SUM \ No newline at end of file +``` \ No newline at end of file diff --git a/docs/sql-manual/sql-functions/scalar-functions/array-functions/array-difference.md b/docs/sql-manual/sql-functions/scalar-functions/array-functions/array-difference.md index a4db0f8fc91..c733519a491 100644 --- a/docs/sql-manual/sql-functions/scalar-functions/array-functions/array-difference.md +++ b/docs/sql-manual/sql-functions/scalar-functions/array-functions/array-difference.md @@ -24,24 +24,50 @@ specific language governing permissions and limitations under the License. --> -## array_difference +## Description +Calculates the difference between adjacent array elements. +Returns an array where the first element will be 0, the second is the difference between a[1] - a[0]. +need notice that NULL will be return NULL -array_difference +## Syntax +```sql +ARRAY_DIFFERENCE(<arr>) +``` -### description +## Parameters -#### Syntax +| Parameter | Description | +|---|---| +| `<arr>` | The array to calculate the difference from | -`ARRAY<T> array_difference(ARRAY<T> arr)` +## Return Value -Calculates the difference between adjacent array elements. -Returns an array where the first element will be 0, the second is the difference between a[1] - a[0]. -need notice that NULL will be return NULL +Returns an array. Special cases: +- If a NULL value exists in the input, the result will be NULL. -### example +## Example +```sql +CREATE TABLE array_type_table ( + k1 INT, + k2 ARRAY<INT> +) +duplicate key (k1) +distributed by hash(k1) buckets 1 +properties( + 'replication_num' = '1' +); +INSERT INTO array_type_table (k1, k2) VALUES +(0, []), +(1, [NULL]), +(2, [1, 2, 3]), +(3, [1, NULL, 3]), +(4, [0, 1, 2, 3, NULL, 4, 6]), +(5, [1, 2, 3, 4, 5, 4, 3, 2, 1]), +(6, [6, 7, 8]); +select *,array_difference(k2) from array_type_table; ``` -mysql> select *,array_difference(k2) from array_type_table; +```text +------+-----------------------------+---------------------------------+ | k1 | k2 | array_difference(`k2`) | +------+-----------------------------+---------------------------------+ @@ -53,9 +79,4 @@ mysql> select *,array_difference(k2) from array_type_table; | 5 | [1, 2, 3, 4, 5, 4, 3, 2, 1] | [0, 1, 1, 1, 1, -1, -1, -1, -1] | | 6 | [6, 7, 8] | [0, 1, 1] | +------+-----------------------------+---------------------------------+ -``` - -### keywords - -ARRAY, DIFFERENCE, ARRAY_DIFFERENCE - +``` \ No newline at end of file diff --git a/docs/sql-manual/sql-functions/scalar-functions/array-functions/array.md b/docs/sql-manual/sql-functions/scalar-functions/array-functions/array.md index 32b3b72f9d7..ed62d197ca1 100644 --- a/docs/sql-manual/sql-functions/scalar-functions/array-functions/array.md +++ b/docs/sql-manual/sql-functions/scalar-functions/array-functions/array.md @@ -22,57 +22,69 @@ specific language governing permissions and limitations under the License. --> -## array() -array() -### description +## Description +construct an array with variadic elements and return it, T could be column or literal -#### Syntax +## Syntax -`ARRAY<T> array(T, ...)` +```sql +ARRAY([ <element> [, ...] ]) +``` -construct an array with variadic elements and return it, T could be column or literal +## Parameters +| Parameter | Description | +|---|---| +| `<element>` | The parameter can be multiple columns or constants | -### example +## Return Value +Returns an array. -``` -mysql> select array("1", 2, 1.1); -+----------------------+ -| array('1', 2, '1.1') | -+----------------------+ -| ['1', '2', '1.1'] | -+----------------------+ -1 row in set (0.00 sec) +## Example + +```sql +select array("1", 2, 1.1); +``` +```text ++------------------------------------------------+ +| array('1', cast(2 as TEXT), cast(1.1 as TEXT)) | ++------------------------------------------------+ +| ["1", "2", "1.1"] | ++------------------------------------------------+ +``` -mysql> select array(null, 1); +```sql +select array(null, 1); +``` +```text +----------------+ | array(NULL, 1) | +----------------+ | [NULL, 1] | +----------------+ -1 row in set (0.00 sec) +``` -mysql> select array(1, 2, 3); +```sql +select array(1, 2, 3); +``` +```text +----------------+ | array(1, 2, 3) | +----------------+ | [1, 2, 3] | +----------------+ -1 row in set (0.00 sec) - -mysql> select array(qid, creationDate, null) from nested limit 4; -+------------------------------------+ -| array(`qid`, `creationDate`, NULL) | -+------------------------------------+ -| [1000038, 20090616074056, NULL] | -| [1000069, 20090616075005, NULL] | -| [1000130, 20090616080918, NULL] | -| [1000145, 20090616081545, NULL] | -+------------------------------------+ -4 rows in set (0.01 sec) ``` -### keywords - -ARRAY,ARRAY,CONSTRUCTOR - +```sql +select array(qid, creationDate, null) from nested limit 4; +``` +```text ++-------------------------------------------------------+ +| array(cast(qid as DATETIMEV2(0)), creationDate, NULL) | ++-------------------------------------------------------+ +| [null, "2009-06-16 07:40:56", null] | +| [null, "2009-06-16 07:50:05", null] | +| [null, "2009-06-16 08:09:18", null] | +| [null, "2009-06-16 08:15:45", null] | ++-------------------------------------------------------+ +``` \ No newline at end of file diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/array-functions/array-apply.md b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/array-functions/array-apply.md index f8a487b4c4d..268e65ccf37 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/array-functions/array-apply.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/array-functions/array-apply.md @@ -22,51 +22,44 @@ specific language governing permissions and limitations under the License. --> -## array_apply - -array_apply - ## 描述 数组以特定的二元条件符过滤元素, 并返回过滤后的结果 ## 语法 ```sql -array_apply(arr, op, val) +ARRAY_APPLY(<arr>, <op>, <val>) ``` ## 参数 - -`arr` — 输入的数组, 如果是null, 则返回null -`op` — 过滤条件, 条件包括 `=`, `>=`, `<=`, `>`, `<`, `!=`,仅支持常量 -`val` — 过滤的条件值, 如果是null, 则返回null,仅支持常量 +| 参数 | 说明 | +|---|---| +| `<arr>` | 输入的数组 | +| `<op>` | 过滤条件,条件包括 `=`, `>=`, `<=`, `>`, `<`, `!=`| +| `<val>` | 过滤的条件值, 如果是null, 则返回null,仅支持常量 | ## 返回值 - 过滤后的数组 -类型: Array. - ## 举例 +```sql +select array_apply([1, 2, 3, 4, 5], ">=", 2); ``` -mysql> select array_apply([1, 2, 3, 4, 5], ">=", 2); +```text +--------------------------------------------+ | array_apply(ARRAY(1, 2, 3, 4, 5), '>=', 2) | +--------------------------------------------+ | [2, 3, 4, 5] | +--------------------------------------------+ -1 row in set (0.01 sec) - -mysql> select array_apply([1000000, 1000001, 1000002], "=", "1000002"); +``` +```sql +select array_apply([1000000, 1000001, 1000002], "=", "1000002"); +``` +```text +-------------------------------------------------------------+ | array_apply(ARRAY(1000000, 1000001, 1000002), '=', 1000002) | +-------------------------------------------------------------+ | [1000002] | +-------------------------------------------------------------+ -1 row in set (0.01 sec) -``` - -### keywords - -ARRAY,APPLY,ARRAY_APPLY \ No newline at end of file +``` \ No newline at end of file diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/array-functions/array-avg.md b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/array-functions/array-avg.md index 5f55ab0191a..2665e550f47 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/array-functions/array-avg.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/array-functions/array-avg.md @@ -24,25 +24,41 @@ specific language governing permissions and limitations under the License. --> -## array_avg - -array_avg - ## 描述 返回数组中所有元素的平均值,数组中的`NULL`值会被跳过。空数组以及元素全为`NULL`值的数组,结果返回`NULL`值。 ## 语法 +```sql +ARRAY_AVG(<arr>) +``` -`Array<T> array_avg(arr)` +## 参数 +| 参数 | 说明 | +|---|---| +| `<arr>` | 用于计算平均值的数组 | + +## 返回值 +返回一个常量,特殊情况: +- 数组中的`NULL`值会被跳过。 +- 数组的字符串会被跳过 ## 举例 -```shell -mysql> create table array_type_table(k1 INT, k2 Array<int>) duplicate key (k1) - -> distributed by hash(k1) buckets 1 properties('replication_num' = '1'); -mysql> insert into array_type_table values (0, []), (1, [NULL]), (2, [1, 2, 3]), (3, [1, NULL, 3]); -mysql> select k2, array_avg(k2) from array_type_table; +```sql +create table array_type_table( + k1 INT, + k2 Array<int> +) +duplicate key (k1) +distributed by hash(k1) buckets 1 +properties( + 'replication_num' = '1' +); +insert into array_type_table values (0, []), (1, [NULL]), (2, [1, 2, 3]), (3, [1, NULL, 3]); +select k2, array_avg(k2) from array_type_table; +``` +```text +--------------+-----------------+ | k2 | array_avg(`k2`) | +--------------+-----------------+ @@ -51,11 +67,14 @@ mysql> select k2, array_avg(k2) from array_type_table; | [1, 2, 3] | 2 | | [1, NULL, 3] | 2 | +--------------+-----------------+ -4 rows in set (0.01 sec) - ``` - -### keywords - -ARRAY,AVG,ARRAY_AVG - +```sql +select array_avg(['test',2,1,null]); +``` +```text ++------------------------------------------------------------+ +| array_avg(cast(['test', '2', '1', NULL] as ARRAY<DOUBLE>)) | ++------------------------------------------------------------+ +| 1.5 | ++------------------------------------------------------------+ +``` diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/array-functions/array-compact.md b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/array-functions/array-compact.md index ef7d023df4f..ca9fbe4ed0c 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/array-functions/array-compact.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/array-functions/array-compact.md @@ -22,56 +22,51 @@ specific language governing permissions and limitations under the License. --> -## array_compact - -array_compact - ## 描述 -从数组中删除连续的重复元素,结果值的顺序由源数组中的顺序决定。 +从数组中删除连续地重复元素,结果值的顺序由源数组中的顺序决定。 ## 语法 - -`Array<T> array_compact(arr)` +```sql +ARRAY_COMPACT(<arr>) +``` ## 参数 - -`arr` — 需要处理的数组。 +| 参数 | 说明 | +|---|---| +| `<arr>` | 用于删除其中连续重复元素的数组 | ## 返回值 - 不存在连续重复元素的数组。 -Type: Array. - ## 举例 - -``` +```sql select array_compact([1, 2, 3, 3, null, null, 4, 4]); - +``` +```text +----------------------------------------------------+ | array_compact(ARRAY(1, 2, 3, 3, NULL, NULL, 4, 4)) | +----------------------------------------------------+ | [1, 2, 3, NULL, 4] | +----------------------------------------------------+ - +``` +```sql select array_compact(['aaa','aaa','bbb','ccc','ccccc',null, null,'dddd']); - +``` +```text +-------------------------------------------------------------------------------+ | array_compact(ARRAY('aaa', 'aaa', 'bbb', 'ccc', 'ccccc', NULL, NULL, 'dddd')) | +-------------------------------------------------------------------------------+ | ['aaa', 'bbb', 'ccc', 'ccccc', NULL, 'dddd'] | +-------------------------------------------------------------------------------+ - +``` +```sql select array_compact(['2015-03-13','2015-03-13']); - +``` +```text +--------------------------------------------------+ | array_compact(ARRAY('2015-03-13', '2015-03-13')) | +--------------------------------------------------+ | ['2015-03-13'] | +--------------------------------------------------+ -``` - -### keywords - -ARRAY,COMPACT,ARRAY_COMPACT \ No newline at end of file +``` \ No newline at end of file diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/array-functions/array-concat.md b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/array-functions/array-concat.md index 7849d413421..bc7be722530 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/array-functions/array-concat.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/array-functions/array-concat.md @@ -22,36 +22,69 @@ specific language governing permissions and limitations under the License. --> -## array_concat - -array_concat - ## 描述 将输入的所有数组拼接为一个数组 ## 语法 +```sql +ARRAY_CONCAT(<arr1> [,<arr2> , ...]) +``` -`Array<T> array_concat(Array<T>, ...)` +## 参数 +| 参数 | 说明 | +|---|---| +| `<arr1>` | 源数组 | +| `<arr2>` | 要添加到arr1的数组 | ## 返回值 -拼接好的数组 - -类型: Array. +拼接好的数组,特殊情况: +- 如果数组是NULL(非[NULL]),则返回NULL ## 举例 +```sql +select array_concat([1, 2], [7, 8], [5, 6]); ``` -mysql> select array_concat([1, 2], [7, 8], [5, 6]); +```text +-----------------------------------------------------+ | array_concat(ARRAY(1, 2), ARRAY(7, 8), ARRAY(5, 6)) | +-----------------------------------------------------+ | [1, 2, 7, 8, 5, 6] | +-----------------------------------------------------+ -1 row in set (0.02 sec) +``` +```sql +select array_concat([1, 2], [7, 8], [5, 6], NULL); +``` +```text ++--------------------------------------------+ +| array_concat([1, 2], [7, 8], [5, 6], NULL) | ++--------------------------------------------+ +| NULL | ++--------------------------------------------+ +``` -mysql> select col2, col3, array_concat(col2, col3) from array_test; +```sql +CREATE TABLE array_test ( + id int, + col2 ARRAY<INT>, + col3 ARRAY<INT> +) +duplicate key (id) +distributed by hash(id) buckets 1 +properties( + 'replication_num' = '1' +); +INSERT INTO array_test (id, col2, col3) VALUES +(1,[1, 2, 3], [3, 4, 5]), +(2,[1, NULL, 2], [NULL]), +(3,[1, 2, 3], NULL), +(4,[], []); + +select col2, col3, array_concat(col2, col3) from array_test; +``` +```text +--------------+-----------+------------------------------+ | col2 | col3 | array_concat(`col2`, `col3`) | +--------------+-----------+------------------------------+ @@ -60,9 +93,4 @@ mysql> select col2, col3, array_concat(col2, col3) from array_test; | [1, 2, 3] | NULL | NULL | | [] | [] | [] | +--------------+-----------+------------------------------+ -``` - - -### keywords - -ARRAY,CONCAT,ARRAY_CONCAT \ No newline at end of file +``` \ No newline at end of file diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/array-functions/array-cum-sum.md b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/array-functions/array-cum-sum.md index 020005ba793..05fb107b745 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/array-functions/array-cum-sum.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/array-functions/array-cum-sum.md @@ -22,26 +22,43 @@ specific language governing permissions and limitations under the License. --> -## array_cum_sum - -array_cum_sum - ## 描述 返回数组的累计和。数组中的`NULL`值会被跳过,并在结果数组的相同位置设置`NULL`。 ## 语法 - ```sql -Array<T> array_cum_sum(Array<T>) +ARRAY_CUM_SUM(<arr>) ``` +## 参数 +| 参数 | 说明 | +|---|---| +| `<arr>` | 用于计算累加和的数组 | + +## 返回值 +返回一个数组。特殊情况: +- 数组中的`NULL`值会被跳过,并在结果数组的相同位置设置`NULL`。 + ## 举例 -```shell -mysql> create table array_type_table(k1 INT, k2 Array<int>) duplicate key (k1) distributed by hash(k1) buckets 1 properties('replication_num' = '1'); -mysql> insert into array_type_table values (0, []), (1, [NULL]), (2, [1, 2, 3, 4]), (3, [1, NULL, 3, NULL, 5]); -mysql> select k2, array_cum_sum(k2) from array_type_table; +```sql +create table array_type_table( + k1 INT, + k2 Array<int> +) +duplicate key (k1) +distributed by hash(k1) buckets 1 +properties( + 'replication_num' = '1' +); +insert into array_type_table values (0, []), +(1, [NULL]), +(2, [1, 2, 3, 4]), +(3, [1, NULL, 3, NULL, 5]); +select k2, array_cum_sum(k2) from array_type_table; +``` +```text +-----------------------+-----------------------+ | k2 | array_cum_sum(`k2`) | +-----------------------+-----------------------+ @@ -50,11 +67,5 @@ mysql> select k2, array_cum_sum(k2) from array_type_table; | [1, 2, 3, 4] | [1, 3, 6, 10] | | [1, NULL, 3, NULL, 5] | [1, NULL, 4, NULL, 9] | +-----------------------+-----------------------+ - -4 rows in set -Time: 0.122s ``` -### keywords - -ARRAY,CUM_SUM,ARRAY_CUM_SUM diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/array-functions/array-difference.md b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/array-functions/array-difference.md index 884e6a8b5cb..1bc60f05d3a 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/array-functions/array-difference.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/array-functions/array-difference.md @@ -24,23 +24,47 @@ specific language governing permissions and limitations under the License. --> -## array_difference - -array_difference - ## 描述 +计算相邻数组元素之间的差异。返回一个数组,其中第一个元素将为0,第二个元素是a[1]-a[0]之间的差值。 +注意若 NULL 值存在,返回结果为NULL ## 语法 +```sql +ARRAY_DIFFERENCE(<arr>) +``` -`ARRAY<T> array_difference(ARRAY<T> arr)` +## 参数 +| 参数 | 说明 | +|---|---| +| `<arr>` | 用于相邻数组元素之间的差异的数组 | -计算相邻数组元素之间的差异。返回一个数组,其中第一个元素将为0,第二个元素是a[1]-a[0]之间的差值。 -注意若 NULL 值存在,返回结果为NULL +## 返回值 +返回一个数组。特殊情况: +- 如果 NULL 值存在,返回结果为NULL ## 举例 +```sql +CREATE TABLE array_type_table ( + k1 INT, + k2 ARRAY<INT> +) +duplicate key (k1) +distributed by hash(k1) buckets 1 +properties( + 'replication_num' = '1' +); +INSERT INTO array_type_table (k1, k2) VALUES +(0, []), +(1, [NULL]), +(2, [1, 2, 3]), +(3, [1, NULL, 3]), +(4, [0, 1, 2, 3, NULL, 4, 6]), +(5, [1, 2, 3, 4, 5, 4, 3, 2, 1]), +(6, [6, 7, 8]); +select *,array_difference(k2) from array_type_table; ``` -mysql> select *,array_difference(k2) from array_type_table; +```text +------+-----------------------------+---------------------------------+ | k1 | k2 | array_difference(`k2`) | +------+-----------------------------+---------------------------------+ @@ -52,9 +76,5 @@ mysql> select *,array_difference(k2) from array_type_table; | 5 | [1, 2, 3, 4, 5, 4, 3, 2, 1] | [0, 1, 1, 1, 1, -1, -1, -1, -1] | | 6 | [6, 7, 8] | [0, 1, 1] | +------+-----------------------------+---------------------------------+ - ``` -### keywords - -ARRAY, DIFFERENCE, ARRAY_DIFFERENCE diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/array-functions/array.md b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/array-functions/array.md index bfa9f265a98..4a028a14f27 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/array-functions/array.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/array-functions/array.md @@ -22,55 +22,69 @@ specific language governing permissions and limitations under the License. --> -## array() -array() ## 描述 +根据参数构造并返回array, 参数可以是多列或者常量 ## 语法 -`ARRAY<T> array(T, ...)` -根据参数构造并返回array, 参数可以是多列或者常量 +```sql +ARRAY([ <element> [, ...] ]) +``` + +## 参数 +| 参数 | 说明 | +|---|---| +| `<element>` | 参数可以是多列或者常量 | + +## 返回值 +返回一个数组 ## 举例 +```sql +select array("1", 2, 1.1); +``` +```text ++------------------------------------------------+ +| array('1', cast(2 as TEXT), cast(1.1 as TEXT)) | ++------------------------------------------------+ +| ["1", "2", "1.1"] | ++------------------------------------------------+ ``` -mysql> select array("1", 2, 1.1); -+----------------------+ -| array('1', 2, '1.1') | -+----------------------+ -| ['1', '2', '1.1'] | -+----------------------+ -1 row in set (0.00 sec) - -mysql> select array(null, 1); +```sql +select array(null, 1); +``` +```text +----------------+ | array(NULL, 1) | +----------------+ | [NULL, 1] | +----------------+ -1 row in set (0.00 sec) +``` -mysql> select array(1, 2, 3); +```sql +select array(1, 2, 3); +``` +```text +----------------+ | array(1, 2, 3) | +----------------+ | [1, 2, 3] | +----------------+ -1 row in set (0.00 sec) - -mysql> select array(qid, creationDate, null) from nested limit 4; -+------------------------------------+ -| array(`qid`, `creationDate`, NULL) | -+------------------------------------+ -| [1000038, 20090616074056, NULL] | -| [1000069, 20090616075005, NULL] | -| [1000130, 20090616080918, NULL] | -| [1000145, 20090616081545, NULL] | -+------------------------------------+ -4 rows in set (0.01 sec) ``` -### keywords +```sql +select array(qid, creationDate, null) from nested limit 4; +``` +```text ++-------------------------------------------------------+ +| array(cast(qid as DATETIMEV2(0)), creationDate, NULL) | ++-------------------------------------------------------+ +| [null, "2009-06-16 07:40:56", null] | +| [null, "2009-06-16 07:50:05", null] | +| [null, "2009-06-16 08:09:18", null] | +| [null, "2009-06-16 08:15:45", null] | ++-------------------------------------------------------+ +``` -ARRAY,ARRAY,CONSTRUCTOR diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/array-functions/array-apply.md b/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/array-functions/array-apply.md index f8a487b4c4d..268e65ccf37 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/array-functions/array-apply.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/array-functions/array-apply.md @@ -22,51 +22,44 @@ specific language governing permissions and limitations under the License. --> -## array_apply - -array_apply - ## 描述 数组以特定的二元条件符过滤元素, 并返回过滤后的结果 ## 语法 ```sql -array_apply(arr, op, val) +ARRAY_APPLY(<arr>, <op>, <val>) ``` ## 参数 - -`arr` — 输入的数组, 如果是null, 则返回null -`op` — 过滤条件, 条件包括 `=`, `>=`, `<=`, `>`, `<`, `!=`,仅支持常量 -`val` — 过滤的条件值, 如果是null, 则返回null,仅支持常量 +| 参数 | 说明 | +|---|---| +| `<arr>` | 输入的数组 | +| `<op>` | 过滤条件,条件包括 `=`, `>=`, `<=`, `>`, `<`, `!=`| +| `<val>` | 过滤的条件值, 如果是null, 则返回null,仅支持常量 | ## 返回值 - 过滤后的数组 -类型: Array. - ## 举例 +```sql +select array_apply([1, 2, 3, 4, 5], ">=", 2); ``` -mysql> select array_apply([1, 2, 3, 4, 5], ">=", 2); +```text +--------------------------------------------+ | array_apply(ARRAY(1, 2, 3, 4, 5), '>=', 2) | +--------------------------------------------+ | [2, 3, 4, 5] | +--------------------------------------------+ -1 row in set (0.01 sec) - -mysql> select array_apply([1000000, 1000001, 1000002], "=", "1000002"); +``` +```sql +select array_apply([1000000, 1000001, 1000002], "=", "1000002"); +``` +```text +-------------------------------------------------------------+ | array_apply(ARRAY(1000000, 1000001, 1000002), '=', 1000002) | +-------------------------------------------------------------+ | [1000002] | +-------------------------------------------------------------+ -1 row in set (0.01 sec) -``` - -### keywords - -ARRAY,APPLY,ARRAY_APPLY \ No newline at end of file +``` \ No newline at end of file diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/array-functions/array-avg.md b/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/array-functions/array-avg.md index 5f55ab0191a..0c718bec739 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/array-functions/array-avg.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/array-functions/array-avg.md @@ -24,25 +24,41 @@ specific language governing permissions and limitations under the License. --> -## array_avg - -array_avg - ## 描述 返回数组中所有元素的平均值,数组中的`NULL`值会被跳过。空数组以及元素全为`NULL`值的数组,结果返回`NULL`值。 ## 语法 +```sql +ARRAY_AVG(<arr>) +``` -`Array<T> array_avg(arr)` +## 参数 +| 参数 | 说明 | +|---|---| +| `<arr>` | 用于计算平均值的数组 | + +## 返回值 +返回一个常量,特殊情况: +- 数组中的`NULL`值会被跳过。 +- 数组的字符串会被跳过 ## 举例 -```shell -mysql> create table array_type_table(k1 INT, k2 Array<int>) duplicate key (k1) - -> distributed by hash(k1) buckets 1 properties('replication_num' = '1'); -mysql> insert into array_type_table values (0, []), (1, [NULL]), (2, [1, 2, 3]), (3, [1, NULL, 3]); -mysql> select k2, array_avg(k2) from array_type_table; +```sql +create table array_type_table( + k1 INT, + k2 Array<int> +) +duplicate key (k1) +distributed by hash(k1) buckets 1 +properties( + 'replication_num' = '1' +); +insert into array_type_table values (0, []), (1, [NULL]), (2, [1, 2, 3]), (3, [1, NULL, 3]); +select k2, array_avg(k2) from array_type_table; +``` +```text +--------------+-----------------+ | k2 | array_avg(`k2`) | +--------------+-----------------+ @@ -51,11 +67,15 @@ mysql> select k2, array_avg(k2) from array_type_table; | [1, 2, 3] | 2 | | [1, NULL, 3] | 2 | +--------------+-----------------+ -4 rows in set (0.01 sec) - ``` - -### keywords - -ARRAY,AVG,ARRAY_AVG +```sql +select array_avg(['test',2,1,null]); +``` +```text ++------------------------------------------------------------+ +| array_avg(cast(['test', '2', '1', NULL] as ARRAY<DOUBLE>)) | ++------------------------------------------------------------+ +| 1.5 | ++------------------------------------------------------------+ +``` diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/array-functions/array-compact.md b/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/array-functions/array-compact.md index ef7d023df4f..ca9fbe4ed0c 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/array-functions/array-compact.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/array-functions/array-compact.md @@ -22,56 +22,51 @@ specific language governing permissions and limitations under the License. --> -## array_compact - -array_compact - ## 描述 -从数组中删除连续的重复元素,结果值的顺序由源数组中的顺序决定。 +从数组中删除连续地重复元素,结果值的顺序由源数组中的顺序决定。 ## 语法 - -`Array<T> array_compact(arr)` +```sql +ARRAY_COMPACT(<arr>) +``` ## 参数 - -`arr` — 需要处理的数组。 +| 参数 | 说明 | +|---|---| +| `<arr>` | 用于删除其中连续重复元素的数组 | ## 返回值 - 不存在连续重复元素的数组。 -Type: Array. - ## 举例 - -``` +```sql select array_compact([1, 2, 3, 3, null, null, 4, 4]); - +``` +```text +----------------------------------------------------+ | array_compact(ARRAY(1, 2, 3, 3, NULL, NULL, 4, 4)) | +----------------------------------------------------+ | [1, 2, 3, NULL, 4] | +----------------------------------------------------+ - +``` +```sql select array_compact(['aaa','aaa','bbb','ccc','ccccc',null, null,'dddd']); - +``` +```text +-------------------------------------------------------------------------------+ | array_compact(ARRAY('aaa', 'aaa', 'bbb', 'ccc', 'ccccc', NULL, NULL, 'dddd')) | +-------------------------------------------------------------------------------+ | ['aaa', 'bbb', 'ccc', 'ccccc', NULL, 'dddd'] | +-------------------------------------------------------------------------------+ - +``` +```sql select array_compact(['2015-03-13','2015-03-13']); - +``` +```text +--------------------------------------------------+ | array_compact(ARRAY('2015-03-13', '2015-03-13')) | +--------------------------------------------------+ | ['2015-03-13'] | +--------------------------------------------------+ -``` - -### keywords - -ARRAY,COMPACT,ARRAY_COMPACT \ No newline at end of file +``` \ No newline at end of file diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/array-functions/array-concat.md b/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/array-functions/array-concat.md index 7849d413421..58f4b881768 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/array-functions/array-concat.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/array-functions/array-concat.md @@ -22,36 +22,69 @@ specific language governing permissions and limitations under the License. --> -## array_concat - -array_concat - ## 描述 将输入的所有数组拼接为一个数组 ## 语法 +```sql +ARRAY_CONCAT(<arr1> [,<arr2> , ...]) +``` -`Array<T> array_concat(Array<T>, ...)` +## 参数 +| 参数 | 说明 | +|---|---| +| `<arr1>` | 源数组 | +| `<arr2>` | 要添加到arr1的数组 | ## 返回值 -拼接好的数组 - -类型: Array. +拼接好的数组,特殊情况: +- 如果数组是NULL(非[NULL]),则返回NULL ## 举例 +```sql +select array_concat([1, 2], [7, 8], [5, 6]); ``` -mysql> select array_concat([1, 2], [7, 8], [5, 6]); +```text +-----------------------------------------------------+ | array_concat(ARRAY(1, 2), ARRAY(7, 8), ARRAY(5, 6)) | +-----------------------------------------------------+ | [1, 2, 7, 8, 5, 6] | +-----------------------------------------------------+ -1 row in set (0.02 sec) +``` +```sql +select array_concat([1, 2], [7, 8], [5, 6], NULL); +``` +```text ++--------------------------------------------+ +| array_concat([1, 2], [7, 8], [5, 6], NULL) | ++--------------------------------------------+ +| NULL | ++--------------------------------------------+ +``` -mysql> select col2, col3, array_concat(col2, col3) from array_test; +```sql +CREATE TABLE array_test ( + id int, + col2 ARRAY<INT>, + col3 ARRAY<INT> +) +duplicate key (id) +distributed by hash(id) buckets 1 +properties( + 'replication_num' = '1' +); +INSERT INTO array_test (id, col2, col3) VALUES +(1,[1, 2, 3], [3, 4, 5]), +(2,[1, NULL, 2], [NULL]), +(3,[1, 2, 3], NULL), +(4,[], []); + +select col2, col3, array_concat(col2, col3) from array_test; +``` +```text +--------------+-----------+------------------------------+ | col2 | col3 | array_concat(`col2`, `col3`) | +--------------+-----------+------------------------------+ @@ -60,9 +93,4 @@ mysql> select col2, col3, array_concat(col2, col3) from array_test; | [1, 2, 3] | NULL | NULL | | [] | [] | [] | +--------------+-----------+------------------------------+ -``` - - -### keywords - -ARRAY,CONCAT,ARRAY_CONCAT \ No newline at end of file +``` \ No newline at end of file diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/array-functions/array-cum-sum.md b/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/array-functions/array-cum-sum.md index 020005ba793..4cf2dee99c9 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/array-functions/array-cum-sum.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/array-functions/array-cum-sum.md @@ -21,27 +21,43 @@ KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> - -## array_cum_sum - -array_cum_sum - ## 描述 返回数组的累计和。数组中的`NULL`值会被跳过,并在结果数组的相同位置设置`NULL`。 ## 语法 - ```sql -Array<T> array_cum_sum(Array<T>) +ARRAY_CUM_SUM(<arr>) ``` +## 参数 +| 参数 | 说明 | +|---|---| +| `<arr>` | 用于计算累加和的数组 | + +## 返回值 +返回一个数组。特殊情况: +- 数组中的`NULL`值会被跳过,并在结果数组的相同位置设置`NULL`。 + ## 举例 -```shell -mysql> create table array_type_table(k1 INT, k2 Array<int>) duplicate key (k1) distributed by hash(k1) buckets 1 properties('replication_num' = '1'); -mysql> insert into array_type_table values (0, []), (1, [NULL]), (2, [1, 2, 3, 4]), (3, [1, NULL, 3, NULL, 5]); -mysql> select k2, array_cum_sum(k2) from array_type_table; +```sql +create table array_type_table( + k1 INT, + k2 Array<int> +) +duplicate key (k1) +distributed by hash(k1) buckets 1 +properties( + 'replication_num' = '1' +); +insert into array_type_table values (0, []), +(1, [NULL]), +(2, [1, 2, 3, 4]), +(3, [1, NULL, 3, NULL, 5]); +select k2, array_cum_sum(k2) from array_type_table; +``` +```text +-----------------------+-----------------------+ | k2 | array_cum_sum(`k2`) | +-----------------------+-----------------------+ @@ -50,11 +66,4 @@ mysql> select k2, array_cum_sum(k2) from array_type_table; | [1, 2, 3, 4] | [1, 3, 6, 10] | | [1, NULL, 3, NULL, 5] | [1, NULL, 4, NULL, 9] | +-----------------------+-----------------------+ - -4 rows in set -Time: 0.122s ``` - -### keywords - -ARRAY,CUM_SUM,ARRAY_CUM_SUM diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/array-functions/array-difference.md b/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/array-functions/array-difference.md index 884e6a8b5cb..ea638ea5d35 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/array-functions/array-difference.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/array-functions/array-difference.md @@ -24,23 +24,47 @@ specific language governing permissions and limitations under the License. --> -## array_difference - -array_difference - ## 描述 +计算相邻数组元素之间的差异。返回一个数组,其中第一个元素将为0,第二个元素是a[1]-a[0]之间的差值。 +注意若 NULL 值存在,返回结果为NULL ## 语法 +```sql +ARRAY_DIFFERENCE(<arr>) +``` -`ARRAY<T> array_difference(ARRAY<T> arr)` +## 参数 +| 参数 | 说明 | +|---|---| +| `<arr>` | 用于相邻数组元素之间的差异的数组 | -计算相邻数组元素之间的差异。返回一个数组,其中第一个元素将为0,第二个元素是a[1]-a[0]之间的差值。 -注意若 NULL 值存在,返回结果为NULL +## 返回值 +返回一个数组。特殊情况: +- 如果 NULL 值存在,返回结果为NULL ## 举例 +```sql +CREATE TABLE array_type_table ( + k1 INT, + k2 ARRAY<INT> +) +duplicate key (k1) +distributed by hash(k1) buckets 1 +properties( + 'replication_num' = '1' +); +INSERT INTO array_type_table (k1, k2) VALUES +(0, []), +(1, [NULL]), +(2, [1, 2, 3]), +(3, [1, NULL, 3]), +(4, [0, 1, 2, 3, NULL, 4, 6]), +(5, [1, 2, 3, 4, 5, 4, 3, 2, 1]), +(6, [6, 7, 8]); +select *,array_difference(k2) from array_type_table; ``` -mysql> select *,array_difference(k2) from array_type_table; +```text +------+-----------------------------+---------------------------------+ | k1 | k2 | array_difference(`k2`) | +------+-----------------------------+---------------------------------+ @@ -52,9 +76,4 @@ mysql> select *,array_difference(k2) from array_type_table; | 5 | [1, 2, 3, 4, 5, 4, 3, 2, 1] | [0, 1, 1, 1, 1, -1, -1, -1, -1] | | 6 | [6, 7, 8] | [0, 1, 1] | +------+-----------------------------+---------------------------------+ - -``` - -### keywords - -ARRAY, DIFFERENCE, ARRAY_DIFFERENCE +``` \ No newline at end of file diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/array-functions/array.md b/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/array-functions/array.md index bfa9f265a98..4a028a14f27 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/array-functions/array.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/array-functions/array.md @@ -22,55 +22,69 @@ specific language governing permissions and limitations under the License. --> -## array() -array() ## 描述 +根据参数构造并返回array, 参数可以是多列或者常量 ## 语法 -`ARRAY<T> array(T, ...)` -根据参数构造并返回array, 参数可以是多列或者常量 +```sql +ARRAY([ <element> [, ...] ]) +``` + +## 参数 +| 参数 | 说明 | +|---|---| +| `<element>` | 参数可以是多列或者常量 | + +## 返回值 +返回一个数组 ## 举例 +```sql +select array("1", 2, 1.1); +``` +```text ++------------------------------------------------+ +| array('1', cast(2 as TEXT), cast(1.1 as TEXT)) | ++------------------------------------------------+ +| ["1", "2", "1.1"] | ++------------------------------------------------+ ``` -mysql> select array("1", 2, 1.1); -+----------------------+ -| array('1', 2, '1.1') | -+----------------------+ -| ['1', '2', '1.1'] | -+----------------------+ -1 row in set (0.00 sec) - -mysql> select array(null, 1); +```sql +select array(null, 1); +``` +```text +----------------+ | array(NULL, 1) | +----------------+ | [NULL, 1] | +----------------+ -1 row in set (0.00 sec) +``` -mysql> select array(1, 2, 3); +```sql +select array(1, 2, 3); +``` +```text +----------------+ | array(1, 2, 3) | +----------------+ | [1, 2, 3] | +----------------+ -1 row in set (0.00 sec) - -mysql> select array(qid, creationDate, null) from nested limit 4; -+------------------------------------+ -| array(`qid`, `creationDate`, NULL) | -+------------------------------------+ -| [1000038, 20090616074056, NULL] | -| [1000069, 20090616075005, NULL] | -| [1000130, 20090616080918, NULL] | -| [1000145, 20090616081545, NULL] | -+------------------------------------+ -4 rows in set (0.01 sec) ``` -### keywords +```sql +select array(qid, creationDate, null) from nested limit 4; +``` +```text ++-------------------------------------------------------+ +| array(cast(qid as DATETIMEV2(0)), creationDate, NULL) | ++-------------------------------------------------------+ +| [null, "2009-06-16 07:40:56", null] | +| [null, "2009-06-16 07:50:05", null] | +| [null, "2009-06-16 08:09:18", null] | +| [null, "2009-06-16 08:15:45", null] | ++-------------------------------------------------------+ +``` -ARRAY,ARRAY,CONSTRUCTOR diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/array-functions/array-apply.md b/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/array-functions/array-apply.md index f8a487b4c4d..268e65ccf37 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/array-functions/array-apply.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/array-functions/array-apply.md @@ -22,51 +22,44 @@ specific language governing permissions and limitations under the License. --> -## array_apply - -array_apply - ## 描述 数组以特定的二元条件符过滤元素, 并返回过滤后的结果 ## 语法 ```sql -array_apply(arr, op, val) +ARRAY_APPLY(<arr>, <op>, <val>) ``` ## 参数 - -`arr` — 输入的数组, 如果是null, 则返回null -`op` — 过滤条件, 条件包括 `=`, `>=`, `<=`, `>`, `<`, `!=`,仅支持常量 -`val` — 过滤的条件值, 如果是null, 则返回null,仅支持常量 +| 参数 | 说明 | +|---|---| +| `<arr>` | 输入的数组 | +| `<op>` | 过滤条件,条件包括 `=`, `>=`, `<=`, `>`, `<`, `!=`| +| `<val>` | 过滤的条件值, 如果是null, 则返回null,仅支持常量 | ## 返回值 - 过滤后的数组 -类型: Array. - ## 举例 +```sql +select array_apply([1, 2, 3, 4, 5], ">=", 2); ``` -mysql> select array_apply([1, 2, 3, 4, 5], ">=", 2); +```text +--------------------------------------------+ | array_apply(ARRAY(1, 2, 3, 4, 5), '>=', 2) | +--------------------------------------------+ | [2, 3, 4, 5] | +--------------------------------------------+ -1 row in set (0.01 sec) - -mysql> select array_apply([1000000, 1000001, 1000002], "=", "1000002"); +``` +```sql +select array_apply([1000000, 1000001, 1000002], "=", "1000002"); +``` +```text +-------------------------------------------------------------+ | array_apply(ARRAY(1000000, 1000001, 1000002), '=', 1000002) | +-------------------------------------------------------------+ | [1000002] | +-------------------------------------------------------------+ -1 row in set (0.01 sec) -``` - -### keywords - -ARRAY,APPLY,ARRAY_APPLY \ No newline at end of file +``` \ No newline at end of file diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/array-functions/array-avg.md b/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/array-functions/array-avg.md index 5f55ab0191a..5e5b54950c2 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/array-functions/array-avg.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/array-functions/array-avg.md @@ -24,25 +24,41 @@ specific language governing permissions and limitations under the License. --> -## array_avg - -array_avg - ## 描述 返回数组中所有元素的平均值,数组中的`NULL`值会被跳过。空数组以及元素全为`NULL`值的数组,结果返回`NULL`值。 ## 语法 +```sql +ARRAY_AVG(<arr>) +``` -`Array<T> array_avg(arr)` +## 参数 +| 参数 | 说明 | +|---|---| +| `<arr>` | 用于计算平均值的数组 | + +## 返回值 +返回一个常量,特殊情况: +- 数组中的`NULL`值会被跳过。 +- 数组的字符串会被跳过 ## 举例 -```shell -mysql> create table array_type_table(k1 INT, k2 Array<int>) duplicate key (k1) - -> distributed by hash(k1) buckets 1 properties('replication_num' = '1'); -mysql> insert into array_type_table values (0, []), (1, [NULL]), (2, [1, 2, 3]), (3, [1, NULL, 3]); -mysql> select k2, array_avg(k2) from array_type_table; +```sql +create table array_type_table( + k1 INT, + k2 Array<int> +) +duplicate key (k1) +distributed by hash(k1) buckets 1 +properties( + 'replication_num' = '1' +); +insert into array_type_table values (0, []), (1, [NULL]), (2, [1, 2, 3]), (3, [1, NULL, 3]); +select k2, array_avg(k2) from array_type_table; +``` +```text +--------------+-----------------+ | k2 | array_avg(`k2`) | +--------------+-----------------+ @@ -51,11 +67,14 @@ mysql> select k2, array_avg(k2) from array_type_table; | [1, 2, 3] | 2 | | [1, NULL, 3] | 2 | +--------------+-----------------+ -4 rows in set (0.01 sec) - ``` - -### keywords - -ARRAY,AVG,ARRAY_AVG - +```sql +select array_avg(['test',2,1,null]); +``` +```text ++------------------------------------------------------------+ +| array_avg(cast(['test', '2', '1', NULL] as ARRAY<DOUBLE>)) | ++------------------------------------------------------------+ +| 1.5 | ++------------------------------------------------------------+ +``` \ No newline at end of file diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/array-functions/array-compact.md b/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/array-functions/array-compact.md index ef7d023df4f..fa1e08f3908 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/array-functions/array-compact.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/array-functions/array-compact.md @@ -1,6 +1,6 @@ --- { - "title": "ARRAY_COMPACY", + "title": "ARRAY_COMPACT", "language": "zh-CN" } --- @@ -22,56 +22,51 @@ specific language governing permissions and limitations under the License. --> -## array_compact - -array_compact - ## 描述 -从数组中删除连续的重复元素,结果值的顺序由源数组中的顺序决定。 +从数组中删除连续地重复元素,结果值的顺序由源数组中的顺序决定。 ## 语法 - -`Array<T> array_compact(arr)` +```sql +ARRAY_COMPACT(<arr>) +``` ## 参数 - -`arr` — 需要处理的数组。 +| 参数 | 说明 | +|---|---| +| `<arr>` | 用于删除其中连续重复元素的数组 | ## 返回值 - 不存在连续重复元素的数组。 -Type: Array. - ## 举例 - -``` +```sql select array_compact([1, 2, 3, 3, null, null, 4, 4]); - +``` +```text +----------------------------------------------------+ | array_compact(ARRAY(1, 2, 3, 3, NULL, NULL, 4, 4)) | +----------------------------------------------------+ | [1, 2, 3, NULL, 4] | +----------------------------------------------------+ - +``` +```sql select array_compact(['aaa','aaa','bbb','ccc','ccccc',null, null,'dddd']); - +``` +```text +-------------------------------------------------------------------------------+ | array_compact(ARRAY('aaa', 'aaa', 'bbb', 'ccc', 'ccccc', NULL, NULL, 'dddd')) | +-------------------------------------------------------------------------------+ | ['aaa', 'bbb', 'ccc', 'ccccc', NULL, 'dddd'] | +-------------------------------------------------------------------------------+ - +``` +```sql select array_compact(['2015-03-13','2015-03-13']); - +``` +```text +--------------------------------------------------+ | array_compact(ARRAY('2015-03-13', '2015-03-13')) | +--------------------------------------------------+ | ['2015-03-13'] | +--------------------------------------------------+ -``` - -### keywords - -ARRAY,COMPACT,ARRAY_COMPACT \ No newline at end of file +``` \ No newline at end of file diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/array-functions/array-concat.md b/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/array-functions/array-concat.md index 7849d413421..58f4b881768 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/array-functions/array-concat.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/array-functions/array-concat.md @@ -22,36 +22,69 @@ specific language governing permissions and limitations under the License. --> -## array_concat - -array_concat - ## 描述 将输入的所有数组拼接为一个数组 ## 语法 +```sql +ARRAY_CONCAT(<arr1> [,<arr2> , ...]) +``` -`Array<T> array_concat(Array<T>, ...)` +## 参数 +| 参数 | 说明 | +|---|---| +| `<arr1>` | 源数组 | +| `<arr2>` | 要添加到arr1的数组 | ## 返回值 -拼接好的数组 - -类型: Array. +拼接好的数组,特殊情况: +- 如果数组是NULL(非[NULL]),则返回NULL ## 举例 +```sql +select array_concat([1, 2], [7, 8], [5, 6]); ``` -mysql> select array_concat([1, 2], [7, 8], [5, 6]); +```text +-----------------------------------------------------+ | array_concat(ARRAY(1, 2), ARRAY(7, 8), ARRAY(5, 6)) | +-----------------------------------------------------+ | [1, 2, 7, 8, 5, 6] | +-----------------------------------------------------+ -1 row in set (0.02 sec) +``` +```sql +select array_concat([1, 2], [7, 8], [5, 6], NULL); +``` +```text ++--------------------------------------------+ +| array_concat([1, 2], [7, 8], [5, 6], NULL) | ++--------------------------------------------+ +| NULL | ++--------------------------------------------+ +``` -mysql> select col2, col3, array_concat(col2, col3) from array_test; +```sql +CREATE TABLE array_test ( + id int, + col2 ARRAY<INT>, + col3 ARRAY<INT> +) +duplicate key (id) +distributed by hash(id) buckets 1 +properties( + 'replication_num' = '1' +); +INSERT INTO array_test (id, col2, col3) VALUES +(1,[1, 2, 3], [3, 4, 5]), +(2,[1, NULL, 2], [NULL]), +(3,[1, 2, 3], NULL), +(4,[], []); + +select col2, col3, array_concat(col2, col3) from array_test; +``` +```text +--------------+-----------+------------------------------+ | col2 | col3 | array_concat(`col2`, `col3`) | +--------------+-----------+------------------------------+ @@ -60,9 +93,4 @@ mysql> select col2, col3, array_concat(col2, col3) from array_test; | [1, 2, 3] | NULL | NULL | | [] | [] | [] | +--------------+-----------+------------------------------+ -``` - - -### keywords - -ARRAY,CONCAT,ARRAY_CONCAT \ No newline at end of file +``` \ No newline at end of file diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/array-functions/array-cum-sum.md b/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/array-functions/array-cum-sum.md index 020005ba793..d7dfe367d3f 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/array-functions/array-cum-sum.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/array-functions/array-cum-sum.md @@ -22,26 +22,43 @@ specific language governing permissions and limitations under the License. --> -## array_cum_sum - -array_cum_sum - ## 描述 返回数组的累计和。数组中的`NULL`值会被跳过,并在结果数组的相同位置设置`NULL`。 ## 语法 - ```sql -Array<T> array_cum_sum(Array<T>) +ARRAY_CUM_SUM(<arr>) ``` +## 参数 +| 参数 | 说明 | +|---|---| +| `<arr>` | 用于计算累加和的数组 | + +## 返回值 +返回一个数组。特殊情况: +- 数组中的`NULL`值会被跳过,并在结果数组的相同位置设置`NULL`。 + ## 举例 -```shell -mysql> create table array_type_table(k1 INT, k2 Array<int>) duplicate key (k1) distributed by hash(k1) buckets 1 properties('replication_num' = '1'); -mysql> insert into array_type_table values (0, []), (1, [NULL]), (2, [1, 2, 3, 4]), (3, [1, NULL, 3, NULL, 5]); -mysql> select k2, array_cum_sum(k2) from array_type_table; +```sql +create table array_type_table( + k1 INT, + k2 Array<int> +) +duplicate key (k1) +distributed by hash(k1) buckets 1 +properties( + 'replication_num' = '1' +); +insert into array_type_table values (0, []), +(1, [NULL]), +(2, [1, 2, 3, 4]), +(3, [1, NULL, 3, NULL, 5]); +select k2, array_cum_sum(k2) from array_type_table; +``` +```text +-----------------------+-----------------------+ | k2 | array_cum_sum(`k2`) | +-----------------------+-----------------------+ @@ -50,11 +67,4 @@ mysql> select k2, array_cum_sum(k2) from array_type_table; | [1, 2, 3, 4] | [1, 3, 6, 10] | | [1, NULL, 3, NULL, 5] | [1, NULL, 4, NULL, 9] | +-----------------------+-----------------------+ - -4 rows in set -Time: 0.122s ``` - -### keywords - -ARRAY,CUM_SUM,ARRAY_CUM_SUM diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/array-functions/array-difference.md b/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/array-functions/array-difference.md index 884e6a8b5cb..e58c27e5003 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/array-functions/array-difference.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/array-functions/array-difference.md @@ -23,24 +23,47 @@ KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> - -## array_difference - -array_difference - ## 描述 +计算相邻数组元素之间的差异。返回一个数组,其中第一个元素将为0,第二个元素是a[1]-a[0]之间的差值。 +注意若 NULL 值存在,返回结果为NULL ## 语法 +```sql +ARRAY_DIFFERENCE(<arr>) +``` -`ARRAY<T> array_difference(ARRAY<T> arr)` +## 参数 +| 参数 | 说明 | +|---|---| +| `<arr>` | 用于相邻数组元素之间的差异的数组 | -计算相邻数组元素之间的差异。返回一个数组,其中第一个元素将为0,第二个元素是a[1]-a[0]之间的差值。 -注意若 NULL 值存在,返回结果为NULL +## 返回值 +返回一个数组。特殊情况: +- 如果 NULL 值存在,返回结果为NULL ## 举例 +```sql +CREATE TABLE array_type_table ( + k1 INT, + k2 ARRAY<INT> +) +duplicate key (k1) +distributed by hash(k1) buckets 1 +properties( + 'replication_num' = '1' +); +INSERT INTO array_type_table (k1, k2) VALUES +(0, []), +(1, [NULL]), +(2, [1, 2, 3]), +(3, [1, NULL, 3]), +(4, [0, 1, 2, 3, NULL, 4, 6]), +(5, [1, 2, 3, 4, 5, 4, 3, 2, 1]), +(6, [6, 7, 8]); +select *,array_difference(k2) from array_type_table; ``` -mysql> select *,array_difference(k2) from array_type_table; +```text +------+-----------------------------+---------------------------------+ | k1 | k2 | array_difference(`k2`) | +------+-----------------------------+---------------------------------+ @@ -52,9 +75,4 @@ mysql> select *,array_difference(k2) from array_type_table; | 5 | [1, 2, 3, 4, 5, 4, 3, 2, 1] | [0, 1, 1, 1, 1, -1, -1, -1, -1] | | 6 | [6, 7, 8] | [0, 1, 1] | +------+-----------------------------+---------------------------------+ - -``` - -### keywords - -ARRAY, DIFFERENCE, ARRAY_DIFFERENCE +``` \ No newline at end of file diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/array-functions/array.md b/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/array-functions/array.md index bfa9f265a98..c92ec21a171 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/array-functions/array.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/array-functions/array.md @@ -22,55 +22,68 @@ specific language governing permissions and limitations under the License. --> -## array() -array() ## 描述 +根据参数构造并返回array, 参数可以是多列或者常量 ## 语法 -`ARRAY<T> array(T, ...)` -根据参数构造并返回array, 参数可以是多列或者常量 +```sql +ARRAY([ <element> [, ...] ]) +``` + +## 参数 +| 参数 | 说明 | +|---|---| +| `<element>` | 参数可以是多列或者常量 | + +## 返回值 +返回一个数组 ## 举例 +```sql +select array("1", 2, 1.1); +``` +```text ++------------------------------------------------+ +| array('1', cast(2 as TEXT), cast(1.1 as TEXT)) | ++------------------------------------------------+ +| ["1", "2", "1.1"] | ++------------------------------------------------+ ``` -mysql> select array("1", 2, 1.1); -+----------------------+ -| array('1', 2, '1.1') | -+----------------------+ -| ['1', '2', '1.1'] | -+----------------------+ -1 row in set (0.00 sec) - -mysql> select array(null, 1); +```sql +select array(null, 1); +``` +```text +----------------+ | array(NULL, 1) | +----------------+ | [NULL, 1] | +----------------+ -1 row in set (0.00 sec) +``` -mysql> select array(1, 2, 3); +```sql +select array(1, 2, 3); +``` +```text +----------------+ | array(1, 2, 3) | +----------------+ | [1, 2, 3] | +----------------+ -1 row in set (0.00 sec) - -mysql> select array(qid, creationDate, null) from nested limit 4; -+------------------------------------+ -| array(`qid`, `creationDate`, NULL) | -+------------------------------------+ -| [1000038, 20090616074056, NULL] | -| [1000069, 20090616075005, NULL] | -| [1000130, 20090616080918, NULL] | -| [1000145, 20090616081545, NULL] | -+------------------------------------+ -4 rows in set (0.01 sec) ``` -### keywords - -ARRAY,ARRAY,CONSTRUCTOR +```sql +select array(qid, creationDate, null) from nested limit 4; +``` +```text ++-------------------------------------------------------+ +| array(cast(qid as DATETIMEV2(0)), creationDate, NULL) | ++-------------------------------------------------------+ +| [null, "2009-06-16 07:40:56", null] | +| [null, "2009-06-16 07:50:05", null] | +| [null, "2009-06-16 08:09:18", null] | +| [null, "2009-06-16 08:15:45", null] | ++-------------------------------------------------------+ +``` diff --git a/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/array-functions/array-apply.md b/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/array-functions/array-apply.md index ded252b168d..e5d33fc63e7 100644 --- a/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/array-functions/array-apply.md +++ b/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/array-functions/array-apply.md @@ -22,52 +22,46 @@ specific language governing permissions and limitations under the License. --> -## array_apply - -array_apply - -### description +## Description Filter array to match specific binary condition -#### Syntax +## Syntax ```sql -array_apply(arr, op, val) +ARRAY_APPLY(<arr>, <op>, <val>) ``` -#### Arguments - -`arr` — The array to inspect. If it null, null will be returned. -`op` — The compare operation, op includes `=`, `>=`, `<=`, `>`, `<`, `!=`. Support const value only. -`val` — The compared value.If it null, null will be returned. Support const value only. +## Parameters +| Parameter | Description | +|---|---| +| `<arr>` | Input array | +| `<op>` | Filter condition, including `=`, `>=`, `<=`, `>`, `<`, `!=` | +| `<val>` | Filter value. If `null`, the result will be `null`. Only constant values are supported. | -#### Returned value +## Return Value The filtered array matched with condition. -Type: Array. - -### example +## Example +```sql +select array_apply([1, 2, 3, 4, 5], ">=", 2); ``` -mysql> select array_apply([1, 2, 3, 4, 5], ">=", 2); +```text +--------------------------------------------+ | array_apply(ARRAY(1, 2, 3, 4, 5), '>=', 2) | +--------------------------------------------+ | [2, 3, 4, 5] | +--------------------------------------------+ -1 row in set (0.01 sec) - -mysql> select array_apply([1000000, 1000001, 1000002], "=", "1000002"); +``` +```sql +select array_apply([1000000, 1000001, 1000002], "=", "1000002"); +``` +```text +-------------------------------------------------------------+ | array_apply(ARRAY(1000000, 1000001, 1000002), '=', 1000002) | +-------------------------------------------------------------+ | [1000002] | +-------------------------------------------------------------+ -1 row in set (0.01 sec) -``` - -### keywords - -ARRAY,APPLY,ARRAY_APPLY \ No newline at end of file +``` \ No newline at end of file diff --git a/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/array-functions/array-avg.md b/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/array-functions/array-avg.md index 0de3886fc8c..f58c6e1eb5c 100644 --- a/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/array-functions/array-avg.md +++ b/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/array-functions/array-avg.md @@ -24,25 +24,42 @@ specific language governing permissions and limitations under the License. --> -## array_avg +## Description +Get the average of all elements in an array (`NULL` values are skipped). +When the array is empty or all elements in the array are `NULL` values, the function returns `NULL`. -array_avg +## Syntax +```sql +ARRAY_AVG(<arr>) +``` -### description -#### Syntax +## Parameters +| Parameter | Description | +|---|---| +| `<arr>` | The array to calculate the average values from | -`Array<T> array_avg(arr)` +## Return Value -Get the average of all elements in an array (`NULL` values are skipped). -When the array is empty or all elements in the array are `NULL` values, the function returns `NULL`. +Returns a constant. Special cases: +- `NULL` values in the array will be skipped. +- Strings and varchar in the array will be skipped. -### example +## Example -```shell -mysql> create table array_type_table(k1 INT, k2 Array<int>) duplicate key (k1) - -> distributed by hash(k1) buckets 1 properties('replication_num' = '1'); -mysql> insert into array_type_table values (0, []), (1, [NULL]), (2, [1, 2, 3]), (3, [1, NULL, 3]); -mysql> select k2, array_avg(k2) from array_type_table; +```sql +create table array_type_table( + k1 INT, + k2 Array<int> +) +duplicate key (k1) +distributed by hash(k1) buckets 1 +properties( + 'replication_num' = '1' +); +insert into array_type_table values (0, []), (1, [NULL]), (2, [1, 2, 3]), (3, [1, NULL, 3]); +select k2, array_avg(k2) from array_type_table; +``` +```text +--------------+-----------------+ | k2 | array_avg(`k2`) | +--------------+-----------------+ @@ -51,11 +68,14 @@ mysql> select k2, array_avg(k2) from array_type_table; | [1, 2, 3] | 2 | | [1, NULL, 3] | 2 | +--------------+-----------------+ -4 rows in set (0.01 sec) - ``` - -### keywords - -ARRAY,AVG,ARRAY_AVG - +```sql +select array_avg(['test',2,1,null]); +``` +```text ++------------------------------------------------------------+ +| array_avg(cast(['test', '2', '1', NULL] as ARRAY<DOUBLE>)) | ++------------------------------------------------------------+ +| 1.5 | ++------------------------------------------------------------+ +``` diff --git a/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/array-functions/array-compact.md b/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/array-functions/array-compact.md index 366f532cd8b..0369e670e52 100644 --- a/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/array-functions/array-compact.md +++ b/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/array-functions/array-compact.md @@ -22,57 +22,53 @@ specific language governing permissions and limitations under the License. --> -## array_compact - -array_compact - -### description +## Description Removes consecutive duplicate elements from an array. The order of result values is determined by the order in the source array. -#### Syntax - -`Array<T> array_compact(arr)` - -#### Arguments - -`arr` — The array to inspect. +## Syntax +```sql +ARRAY_COMPACT(<arr>) +``` -#### Returned value +## Parameters +| Parameter | Description | +|---|---| +| `<arr>` | The array to remove consecutive duplicate elements from | -The array without continuous duplicate. +## Return Value -Type: Array. +An array without consecutive duplicate elements. -### example +## Example -``` +```sql select array_compact([1, 2, 3, 3, null, null, 4, 4]); - +``` +```text +----------------------------------------------------+ | array_compact(ARRAY(1, 2, 3, 3, NULL, NULL, 4, 4)) | +----------------------------------------------------+ | [1, 2, 3, NULL, 4] | +----------------------------------------------------+ - +``` +```sql select array_compact(['aaa','aaa','bbb','ccc','ccccc',null, null,'dddd']); - +``` +```text +-------------------------------------------------------------------------------+ | array_compact(ARRAY('aaa', 'aaa', 'bbb', 'ccc', 'ccccc', NULL, NULL, 'dddd')) | +-------------------------------------------------------------------------------+ | ['aaa', 'bbb', 'ccc', 'ccccc', NULL, 'dddd'] | +-------------------------------------------------------------------------------+ - +``` +```sql select array_compact(['2015-03-13','2015-03-13']); - +``` +```text +--------------------------------------------------+ | array_compact(ARRAY('2015-03-13', '2015-03-13')) | +--------------------------------------------------+ | ['2015-03-13'] | +--------------------------------------------------+ ``` - -### keywords - -ARRAY,COMPACT,ARRAY_COMPACT - diff --git a/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/array-functions/array-concat.md b/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/array-functions/array-concat.md index 6454bb9b2a7..42b82d65987 100644 --- a/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/array-functions/array-concat.md +++ b/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/array-functions/array-concat.md @@ -22,36 +22,69 @@ specific language governing permissions and limitations under the License. --> -## array_concat - -array_concat - -### description +## Description Concat all arrays passed in the arguments -#### Syntax - -`Array<T> array_concat(Array<T>, ...)` +## Syntax +```sql +ARRAY_CONCAT(<arr1> [,<arr2> , ...]) +``` -#### Returned value +## Parameters +| Parameter | Description | +|---|---| +| `<arr1>` | The source array | +| `<arr2>` | The array to be appended to arr1 | -The concated array. +## Return Value -Type: Array. +The concatenated array. Special cases: +- If an array is NULL (not `[NULL]`), the function returns NULL. -### example +## Example +```sql +select array_concat([1, 2], [7, 8], [5, 6]); ``` -mysql> select array_concat([1, 2], [7, 8], [5, 6]); +```text +-----------------------------------------------------+ | array_concat(ARRAY(1, 2), ARRAY(7, 8), ARRAY(5, 6)) | +-----------------------------------------------------+ | [1, 2, 7, 8, 5, 6] | +-----------------------------------------------------+ -1 row in set (0.02 sec) +``` +```sql +select array_concat([1, 2], [7, 8], [5, 6], NULL); +``` +```text ++--------------------------------------------+ +| array_concat([1, 2], [7, 8], [5, 6], NULL) | ++--------------------------------------------+ +| NULL | ++--------------------------------------------+ +``` + +```sql +CREATE TABLE array_test ( + id int, + col2 ARRAY<INT>, + col3 ARRAY<INT> +) +duplicate key (id) +distributed by hash(id) buckets 1 +properties( + 'replication_num' = '1' +); +INSERT INTO array_test (id, col2, col3) VALUES +(1,[1, 2, 3], [3, 4, 5]), +(2,[1, NULL, 2], [NULL]), +(3,[1, 2, 3], NULL), +(4,[], []); -mysql> select col2, col3, array_concat(col2, col3) from array_test; +select col2, col3, array_concat(col2, col3) from array_test; +``` +```text +--------------+-----------+------------------------------+ | col2 | col3 | array_concat(`col2`, `col3`) | +--------------+-----------+------------------------------+ @@ -60,8 +93,4 @@ mysql> select col2, col3, array_concat(col2, col3) from array_test; | [1, 2, 3] | NULL | NULL | | [] | [] | [] | +--------------+-----------+------------------------------+ -``` - -### keywords - -ARRAY,CONCAT,ARRAY_CONCAT \ No newline at end of file +``` \ No newline at end of file diff --git a/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/array-functions/array-cum-sum.md b/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/array-functions/array-cum-sum.md index 80acaa728ad..030b4118c80 100644 --- a/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/array-functions/array-cum-sum.md +++ b/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/array-functions/array-cum-sum.md @@ -22,27 +22,48 @@ specific language governing permissions and limitations under the License. --> -## array_cum_sum - -array_cum_sum - -### description +## Description Get the cumulative sum of an array (`NULL` values are skipped). If the array contains `NULL` values, then `NULL` is set at the same position in the result array. -#### Syntax +## Syntax ```sql -Array<T> array_cum_sum(Array<T>) +ARRAY_CUM_SUM(<arr>) ``` -### example +## Parameters + +| Parameter | Description | +|---|---| +| `<arr>` | The array to calculate the cumulative sum from | + +## Return Value + +Returns an array. Special cases: +- `NULL` values in the array are skipped, and `NULL` is set at the same position in the result array. + + +## Example -```shell -mysql> create table array_type_table(k1 INT, k2 Array<int>) duplicate key (k1) distributed by hash(k1) buckets 1 properties('replication_num' = '1'); -mysql> insert into array_type_table values (0, []), (1, [NULL]), (2, [1, 2, 3, 4]), (3, [1, NULL, 3, NULL, 5]); -mysql> select k2, array_cum_sum(k2) from array_type_table; +```sql +create table array_type_table( + k1 INT, + k2 Array<int> +) +duplicate key (k1) +distributed by hash(k1) buckets 1 +properties( + 'replication_num' = '1' +); +insert into array_type_table values (0, []), +(1, [NULL]), +(2, [1, 2, 3, 4]), +(3, [1, NULL, 3, NULL, 5]); +select k2, array_cum_sum(k2) from array_type_table; +``` +```text +-----------------------+-----------------------+ | k2 | array_cum_sum(`k2`) | +-----------------------+-----------------------+ @@ -51,11 +72,4 @@ mysql> select k2, array_cum_sum(k2) from array_type_table; | [1, 2, 3, 4] | [1, 3, 6, 10] | | [1, NULL, 3, NULL, 5] | [1, NULL, 4, NULL, 9] | +-----------------------+-----------------------+ - -4 rows in set -Time: 0.122s -``` - -### keywords - -ARRAY,CUM_SUM,ARRAY_CUM_SUM \ No newline at end of file +``` \ No newline at end of file diff --git a/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/array-functions/array-difference.md b/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/array-functions/array-difference.md index a4db0f8fc91..76a42bb03d5 100644 --- a/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/array-functions/array-difference.md +++ b/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/array-functions/array-difference.md @@ -23,25 +23,50 @@ KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> +## Description +Calculates the difference between adjacent array elements. +Returns an array where the first element will be 0, the second is the difference between a[1] - a[0]. +need notice that NULL will be return NULL -## array_difference - -array_difference +## Syntax +```sql +ARRAY_DIFFERENCE(<arr>) +``` -### description +## Parameters -#### Syntax +| Parameter | Description | +|---|---| +| `<arr>` | The array to calculate the difference from | -`ARRAY<T> array_difference(ARRAY<T> arr)` +## Return Value -Calculates the difference between adjacent array elements. -Returns an array where the first element will be 0, the second is the difference between a[1] - a[0]. -need notice that NULL will be return NULL +Returns an array. Special cases: +- If a NULL value exists in the input, the result will be NULL. -### example +## Example +```sql +CREATE TABLE array_type_table ( + k1 INT, + k2 ARRAY<INT> +) +duplicate key (k1) +distributed by hash(k1) buckets 1 +properties( + 'replication_num' = '1' +); +INSERT INTO array_type_table (k1, k2) VALUES +(0, []), +(1, [NULL]), +(2, [1, 2, 3]), +(3, [1, NULL, 3]), +(4, [0, 1, 2, 3, NULL, 4, 6]), +(5, [1, 2, 3, 4, 5, 4, 3, 2, 1]), +(6, [6, 7, 8]); +select *,array_difference(k2) from array_type_table; ``` -mysql> select *,array_difference(k2) from array_type_table; +```text +------+-----------------------------+---------------------------------+ | k1 | k2 | array_difference(`k2`) | +------+-----------------------------+---------------------------------+ @@ -53,9 +78,4 @@ mysql> select *,array_difference(k2) from array_type_table; | 5 | [1, 2, 3, 4, 5, 4, 3, 2, 1] | [0, 1, 1, 1, 1, -1, -1, -1, -1] | | 6 | [6, 7, 8] | [0, 1, 1] | +------+-----------------------------+---------------------------------+ -``` - -### keywords - -ARRAY, DIFFERENCE, ARRAY_DIFFERENCE - +``` \ No newline at end of file diff --git a/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/array-functions/array.md b/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/array-functions/array.md index 32b3b72f9d7..92da78398dc 100644 --- a/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/array-functions/array.md +++ b/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/array-functions/array.md @@ -22,57 +22,70 @@ specific language governing permissions and limitations under the License. --> -## array() -array() -### description +## Description +construct an array with variadic elements and return it, T could be column or literal -#### Syntax +## Syntax -`ARRAY<T> array(T, ...)` +```sql +ARRAY([ <element> [, ...] ]) +``` -construct an array with variadic elements and return it, T could be column or literal +## Parameters +| Parameter | Description | +|---|---| +| `<element>` | The parameter can be multiple columns or constants | -### example +## Return Value +Returns an array. -``` -mysql> select array("1", 2, 1.1); -+----------------------+ -| array('1', 2, '1.1') | -+----------------------+ -| ['1', '2', '1.1'] | -+----------------------+ -1 row in set (0.00 sec) +## Example + +```sql +select array("1", 2, 1.1); +``` +```text ++------------------------------------------------+ +| array('1', cast(2 as TEXT), cast(1.1 as TEXT)) | ++------------------------------------------------+ +| ["1", "2", "1.1"] | ++------------------------------------------------+ +``` -mysql> select array(null, 1); +```sql +select array(null, 1); +``` +```text +----------------+ | array(NULL, 1) | +----------------+ | [NULL, 1] | +----------------+ -1 row in set (0.00 sec) +``` -mysql> select array(1, 2, 3); +```sql +select array(1, 2, 3); +``` +```text +----------------+ | array(1, 2, 3) | +----------------+ | [1, 2, 3] | +----------------+ -1 row in set (0.00 sec) - -mysql> select array(qid, creationDate, null) from nested limit 4; -+------------------------------------+ -| array(`qid`, `creationDate`, NULL) | -+------------------------------------+ -| [1000038, 20090616074056, NULL] | -| [1000069, 20090616075005, NULL] | -| [1000130, 20090616080918, NULL] | -| [1000145, 20090616081545, NULL] | -+------------------------------------+ -4 rows in set (0.01 sec) ``` -### keywords - -ARRAY,ARRAY,CONSTRUCTOR +```sql +select array(qid, creationDate, null) from nested limit 4; +``` +```text ++-------------------------------------------------------+ +| array(cast(qid as DATETIMEV2(0)), creationDate, NULL) | ++-------------------------------------------------------+ +| [null, "2009-06-16 07:40:56", null] | +| [null, "2009-06-16 07:50:05", null] | +| [null, "2009-06-16 08:09:18", null] | +| [null, "2009-06-16 08:15:45", null] | ++-------------------------------------------------------+ +``` diff --git a/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/array-functions/array-apply.md b/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/array-functions/array-apply.md index ded252b168d..e5d33fc63e7 100644 --- a/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/array-functions/array-apply.md +++ b/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/array-functions/array-apply.md @@ -22,52 +22,46 @@ specific language governing permissions and limitations under the License. --> -## array_apply - -array_apply - -### description +## Description Filter array to match specific binary condition -#### Syntax +## Syntax ```sql -array_apply(arr, op, val) +ARRAY_APPLY(<arr>, <op>, <val>) ``` -#### Arguments - -`arr` — The array to inspect. If it null, null will be returned. -`op` — The compare operation, op includes `=`, `>=`, `<=`, `>`, `<`, `!=`. Support const value only. -`val` — The compared value.If it null, null will be returned. Support const value only. +## Parameters +| Parameter | Description | +|---|---| +| `<arr>` | Input array | +| `<op>` | Filter condition, including `=`, `>=`, `<=`, `>`, `<`, `!=` | +| `<val>` | Filter value. If `null`, the result will be `null`. Only constant values are supported. | -#### Returned value +## Return Value The filtered array matched with condition. -Type: Array. - -### example +## Example +```sql +select array_apply([1, 2, 3, 4, 5], ">=", 2); ``` -mysql> select array_apply([1, 2, 3, 4, 5], ">=", 2); +```text +--------------------------------------------+ | array_apply(ARRAY(1, 2, 3, 4, 5), '>=', 2) | +--------------------------------------------+ | [2, 3, 4, 5] | +--------------------------------------------+ -1 row in set (0.01 sec) - -mysql> select array_apply([1000000, 1000001, 1000002], "=", "1000002"); +``` +```sql +select array_apply([1000000, 1000001, 1000002], "=", "1000002"); +``` +```text +-------------------------------------------------------------+ | array_apply(ARRAY(1000000, 1000001, 1000002), '=', 1000002) | +-------------------------------------------------------------+ | [1000002] | +-------------------------------------------------------------+ -1 row in set (0.01 sec) -``` - -### keywords - -ARRAY,APPLY,ARRAY_APPLY \ No newline at end of file +``` \ No newline at end of file diff --git a/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/array-functions/array-avg.md b/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/array-functions/array-avg.md index 0de3886fc8c..1534aa063c8 100644 --- a/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/array-functions/array-avg.md +++ b/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/array-functions/array-avg.md @@ -24,25 +24,42 @@ specific language governing permissions and limitations under the License. --> -## array_avg +## Description +Get the average of all elements in an array (`NULL` values are skipped). +When the array is empty or all elements in the array are `NULL` values, the function returns `NULL`. -array_avg +## Syntax +```sql +ARRAY_AVG(<arr>) +``` -### description -#### Syntax +## Parameters +| Parameter | Description | +|---|---| +| `<arr>` | The array to calculate the average values from | -`Array<T> array_avg(arr)` +## Return Value -Get the average of all elements in an array (`NULL` values are skipped). -When the array is empty or all elements in the array are `NULL` values, the function returns `NULL`. +Returns a constant. Special cases: +- `NULL` values in the array will be skipped. +- Strings and varchar in the array will be skipped. -### example +## Example -```shell -mysql> create table array_type_table(k1 INT, k2 Array<int>) duplicate key (k1) - -> distributed by hash(k1) buckets 1 properties('replication_num' = '1'); -mysql> insert into array_type_table values (0, []), (1, [NULL]), (2, [1, 2, 3]), (3, [1, NULL, 3]); -mysql> select k2, array_avg(k2) from array_type_table; +```sql +create table array_type_table( + k1 INT, + k2 Array<int> +) +duplicate key (k1) +distributed by hash(k1) buckets 1 +properties( + 'replication_num' = '1' +); +insert into array_type_table values (0, []), (1, [NULL]), (2, [1, 2, 3]), (3, [1, NULL, 3]); +select k2, array_avg(k2) from array_type_table; +``` +```text +--------------+-----------------+ | k2 | array_avg(`k2`) | +--------------+-----------------+ @@ -51,11 +68,14 @@ mysql> select k2, array_avg(k2) from array_type_table; | [1, 2, 3] | 2 | | [1, NULL, 3] | 2 | +--------------+-----------------+ -4 rows in set (0.01 sec) - ``` - -### keywords - -ARRAY,AVG,ARRAY_AVG - +```sql +select array_avg(['test',2,1,null]); +``` +```text ++------------------------------------------------------------+ +| array_avg(cast(['test', '2', '1', NULL] as ARRAY<DOUBLE>)) | ++------------------------------------------------------------+ +| 1.5 | ++------------------------------------------------------------+ +``` \ No newline at end of file diff --git a/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/array-functions/array-compact.md b/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/array-functions/array-compact.md index 366f532cd8b..4678c1590d5 100644 --- a/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/array-functions/array-compact.md +++ b/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/array-functions/array-compact.md @@ -22,49 +22,50 @@ specific language governing permissions and limitations under the License. --> -## array_compact - -array_compact - -### description +## Description Removes consecutive duplicate elements from an array. The order of result values is determined by the order in the source array. -#### Syntax - -`Array<T> array_compact(arr)` - -#### Arguments - -`arr` — The array to inspect. +## Syntax +```sql +ARRAY_COMPACT(<arr>) +``` -#### Returned value +## Parameters +| Parameter | Description | +|---|---| +| `<arr>` | The array to remove consecutive duplicate elements from | -The array without continuous duplicate. +## Return Value -Type: Array. +An array without consecutive duplicate elements. -### example +## Example -``` +```sql select array_compact([1, 2, 3, 3, null, null, 4, 4]); - +``` +```text +----------------------------------------------------+ | array_compact(ARRAY(1, 2, 3, 3, NULL, NULL, 4, 4)) | +----------------------------------------------------+ | [1, 2, 3, NULL, 4] | +----------------------------------------------------+ - +``` +```sql select array_compact(['aaa','aaa','bbb','ccc','ccccc',null, null,'dddd']); - +``` +```text +-------------------------------------------------------------------------------+ | array_compact(ARRAY('aaa', 'aaa', 'bbb', 'ccc', 'ccccc', NULL, NULL, 'dddd')) | +-------------------------------------------------------------------------------+ | ['aaa', 'bbb', 'ccc', 'ccccc', NULL, 'dddd'] | +-------------------------------------------------------------------------------+ - +``` +```sql select array_compact(['2015-03-13','2015-03-13']); - +``` +```text +--------------------------------------------------+ | array_compact(ARRAY('2015-03-13', '2015-03-13')) | +--------------------------------------------------+ @@ -72,7 +73,3 @@ select array_compact(['2015-03-13','2015-03-13']); +--------------------------------------------------+ ``` -### keywords - -ARRAY,COMPACT,ARRAY_COMPACT - diff --git a/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/array-functions/array-concat.md b/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/array-functions/array-concat.md index 6454bb9b2a7..42b82d65987 100644 --- a/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/array-functions/array-concat.md +++ b/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/array-functions/array-concat.md @@ -22,36 +22,69 @@ specific language governing permissions and limitations under the License. --> -## array_concat - -array_concat - -### description +## Description Concat all arrays passed in the arguments -#### Syntax - -`Array<T> array_concat(Array<T>, ...)` +## Syntax +```sql +ARRAY_CONCAT(<arr1> [,<arr2> , ...]) +``` -#### Returned value +## Parameters +| Parameter | Description | +|---|---| +| `<arr1>` | The source array | +| `<arr2>` | The array to be appended to arr1 | -The concated array. +## Return Value -Type: Array. +The concatenated array. Special cases: +- If an array is NULL (not `[NULL]`), the function returns NULL. -### example +## Example +```sql +select array_concat([1, 2], [7, 8], [5, 6]); ``` -mysql> select array_concat([1, 2], [7, 8], [5, 6]); +```text +-----------------------------------------------------+ | array_concat(ARRAY(1, 2), ARRAY(7, 8), ARRAY(5, 6)) | +-----------------------------------------------------+ | [1, 2, 7, 8, 5, 6] | +-----------------------------------------------------+ -1 row in set (0.02 sec) +``` +```sql +select array_concat([1, 2], [7, 8], [5, 6], NULL); +``` +```text ++--------------------------------------------+ +| array_concat([1, 2], [7, 8], [5, 6], NULL) | ++--------------------------------------------+ +| NULL | ++--------------------------------------------+ +``` + +```sql +CREATE TABLE array_test ( + id int, + col2 ARRAY<INT>, + col3 ARRAY<INT> +) +duplicate key (id) +distributed by hash(id) buckets 1 +properties( + 'replication_num' = '1' +); +INSERT INTO array_test (id, col2, col3) VALUES +(1,[1, 2, 3], [3, 4, 5]), +(2,[1, NULL, 2], [NULL]), +(3,[1, 2, 3], NULL), +(4,[], []); -mysql> select col2, col3, array_concat(col2, col3) from array_test; +select col2, col3, array_concat(col2, col3) from array_test; +``` +```text +--------------+-----------+------------------------------+ | col2 | col3 | array_concat(`col2`, `col3`) | +--------------+-----------+------------------------------+ @@ -60,8 +93,4 @@ mysql> select col2, col3, array_concat(col2, col3) from array_test; | [1, 2, 3] | NULL | NULL | | [] | [] | [] | +--------------+-----------+------------------------------+ -``` - -### keywords - -ARRAY,CONCAT,ARRAY_CONCAT \ No newline at end of file +``` \ No newline at end of file diff --git a/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/array-functions/array-cum-sum.md b/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/array-functions/array-cum-sum.md index 80acaa728ad..030b4118c80 100644 --- a/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/array-functions/array-cum-sum.md +++ b/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/array-functions/array-cum-sum.md @@ -22,27 +22,48 @@ specific language governing permissions and limitations under the License. --> -## array_cum_sum - -array_cum_sum - -### description +## Description Get the cumulative sum of an array (`NULL` values are skipped). If the array contains `NULL` values, then `NULL` is set at the same position in the result array. -#### Syntax +## Syntax ```sql -Array<T> array_cum_sum(Array<T>) +ARRAY_CUM_SUM(<arr>) ``` -### example +## Parameters + +| Parameter | Description | +|---|---| +| `<arr>` | The array to calculate the cumulative sum from | + +## Return Value + +Returns an array. Special cases: +- `NULL` values in the array are skipped, and `NULL` is set at the same position in the result array. + + +## Example -```shell -mysql> create table array_type_table(k1 INT, k2 Array<int>) duplicate key (k1) distributed by hash(k1) buckets 1 properties('replication_num' = '1'); -mysql> insert into array_type_table values (0, []), (1, [NULL]), (2, [1, 2, 3, 4]), (3, [1, NULL, 3, NULL, 5]); -mysql> select k2, array_cum_sum(k2) from array_type_table; +```sql +create table array_type_table( + k1 INT, + k2 Array<int> +) +duplicate key (k1) +distributed by hash(k1) buckets 1 +properties( + 'replication_num' = '1' +); +insert into array_type_table values (0, []), +(1, [NULL]), +(2, [1, 2, 3, 4]), +(3, [1, NULL, 3, NULL, 5]); +select k2, array_cum_sum(k2) from array_type_table; +``` +```text +-----------------------+-----------------------+ | k2 | array_cum_sum(`k2`) | +-----------------------+-----------------------+ @@ -51,11 +72,4 @@ mysql> select k2, array_cum_sum(k2) from array_type_table; | [1, 2, 3, 4] | [1, 3, 6, 10] | | [1, NULL, 3, NULL, 5] | [1, NULL, 4, NULL, 9] | +-----------------------+-----------------------+ - -4 rows in set -Time: 0.122s -``` - -### keywords - -ARRAY,CUM_SUM,ARRAY_CUM_SUM \ No newline at end of file +``` \ No newline at end of file diff --git a/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/array-functions/array-difference.md b/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/array-functions/array-difference.md index a4db0f8fc91..2c1cf48f937 100644 --- a/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/array-functions/array-difference.md +++ b/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/array-functions/array-difference.md @@ -24,24 +24,50 @@ specific language governing permissions and limitations under the License. --> -## array_difference +## Description +Calculates the difference between adjacent array elements. +Returns an array where the first element will be 0, the second is the difference between a[1] - a[0]. +need notice that NULL will be return NULL -array_difference +## Syntax +```sql +ARRAY_DIFFERENCE(<arr>) +``` -### description +## Parameters -#### Syntax +| Parameter | Description | +|---|---| +| `<arr>` | The array to calculate the difference from | -`ARRAY<T> array_difference(ARRAY<T> arr)` +## Return Value -Calculates the difference between adjacent array elements. -Returns an array where the first element will be 0, the second is the difference between a[1] - a[0]. -need notice that NULL will be return NULL +Returns an array. Special cases: +- If a NULL value exists in the input, the result will be NULL. -### example +## Example +```sql +CREATE TABLE array_type_table ( + k1 INT, + k2 ARRAY<INT> +) +duplicate key (k1) +distributed by hash(k1) buckets 1 +properties( + 'replication_num' = '1' +); +INSERT INTO array_type_table (k1, k2) VALUES +(0, []), +(1, [NULL]), +(2, [1, 2, 3]), +(3, [1, NULL, 3]), +(4, [0, 1, 2, 3, NULL, 4, 6]), +(5, [1, 2, 3, 4, 5, 4, 3, 2, 1]), +(6, [6, 7, 8]); +select *,array_difference(k2) from array_type_table; ``` -mysql> select *,array_difference(k2) from array_type_table; +```text +------+-----------------------------+---------------------------------+ | k1 | k2 | array_difference(`k2`) | +------+-----------------------------+---------------------------------+ @@ -55,7 +81,4 @@ mysql> select *,array_difference(k2) from array_type_table; +------+-----------------------------+---------------------------------+ ``` -### keywords - -ARRAY, DIFFERENCE, ARRAY_DIFFERENCE diff --git a/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/array-functions/array.md b/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/array-functions/array.md index 32b3b72f9d7..323eb1ad535 100644 --- a/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/array-functions/array.md +++ b/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/array-functions/array.md @@ -21,58 +21,70 @@ KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> +## Description +construct an array with variadic elements and return it, T could be column or literal -## array() -array() -### description +## Syntax -#### Syntax +```sql +ARRAY([ <element> [, ...] ]) +``` -`ARRAY<T> array(T, ...)` +## Parameters +| Parameter | Description | +|---|---| +| `<element>` | The parameter can be multiple columns or constants | -construct an array with variadic elements and return it, T could be column or literal +## Return Value +Returns an array. -### example -``` -mysql> select array("1", 2, 1.1); -+----------------------+ -| array('1', 2, '1.1') | -+----------------------+ -| ['1', '2', '1.1'] | -+----------------------+ -1 row in set (0.00 sec) +## Example +```sql +select array("1", 2, 1.1); +``` +```text ++------------------------------------------------+ +| array('1', cast(2 as TEXT), cast(1.1 as TEXT)) | ++------------------------------------------------+ +| ["1", "2", "1.1"] | ++------------------------------------------------+ +``` -mysql> select array(null, 1); +```sql +select array(null, 1); +``` +```text +----------------+ | array(NULL, 1) | +----------------+ | [NULL, 1] | +----------------+ -1 row in set (0.00 sec) +``` -mysql> select array(1, 2, 3); +```sql +select array(1, 2, 3); +``` +```text +----------------+ | array(1, 2, 3) | +----------------+ | [1, 2, 3] | +----------------+ -1 row in set (0.00 sec) - -mysql> select array(qid, creationDate, null) from nested limit 4; -+------------------------------------+ -| array(`qid`, `creationDate`, NULL) | -+------------------------------------+ -| [1000038, 20090616074056, NULL] | -| [1000069, 20090616075005, NULL] | -| [1000130, 20090616080918, NULL] | -| [1000145, 20090616081545, NULL] | -+------------------------------------+ -4 rows in set (0.01 sec) ``` -### keywords - -ARRAY,ARRAY,CONSTRUCTOR +```sql +select array(qid, creationDate, null) from nested limit 4; +``` +```text ++-------------------------------------------------------+ +| array(cast(qid as DATETIMEV2(0)), creationDate, NULL) | ++-------------------------------------------------------+ +| [null, "2009-06-16 07:40:56", null] | +| [null, "2009-06-16 07:50:05", null] | +| [null, "2009-06-16 08:09:18", null] | +| [null, "2009-06-16 08:15:45", null] | ++-------------------------------------------------------+ +``` --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org