Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[doc] Modify the documentation of functions of array_distinct, array_enumerate,array_enumerate_uniq, array_except, array_exists,array_intersect, array_join #1864

Merged
merged 6 commits into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,47 @@ specific language governing permissions and limitations
under the License.
-->

## array_distinct

array_distinct

### description
## Description
Return the array which has been removed duplicate values.
Return NULL for NULL input.

#### Syntax
## Syntax
```sql
ARRAY_DISTINCT(<arr> )
```

`ARRAY<T> array_distinct(ARRAY<T> arr)`
## Parameters
| Parameter | Description |
|---|---|
| `<arr>` | An array that might contain duplicate elements to be removed |

Return the array which has been removed duplicate values.
Return NULL for NULL input.
## Return Value
Return the array which has been removed duplicate values. Special case:
- If the input array is NULL, the result is NULL.

### example
## Example

```sql
CREATE TABLE array_test (
k1 INT,
k2 ARRAY<INT>
)
duplicate key (k1)
distributed by hash(k1) buckets 1
properties(
'replication_num' = '1'
);
INSERT INTO array_test VALUES
(1, [1, 2, 3, 4, 5]),
(2, [6, 7, 8]),
(3, []),
(4, NULL),
(5, [1, 2, 3, 4, 5, 4, 3, 2, 1]),
(6, [1, 2, 3, NULL]),
(7, [1, 2, 3, NULL, NULL]);
select k1, k2, array_distinct(k2) from array_test;
```
mysql> select k1, k2, array_distinct(k2) from array_test;
```text
+------+-----------------------------+---------------------------+
| k1 | k2 | array_distinct(k2) |
+------+-----------------------------+---------------------------+
Expand All @@ -50,10 +74,31 @@ mysql> select k1, k2, array_distinct(k2) from array_test;
| 4 | NULL | NULL |
| 5 | [1, 2, 3, 4, 5, 4, 3, 2, 1] | [1, 2, 3, 4, 5] |
| 6 | [1, 2, 3, NULL] | [1, 2, 3, NULL] |
| 7 | [1, 2, 3, NULL, NULL] | [1, 2, 3, NULL] |
| 7 | [1, 2, 3, NULL, NULL] | [1, 2, 3, NULL] |
+------+-----------------------------+---------------------------+

mysql> select k1, k2, array_distinct(k2) from array_test01;
```
```sql
CREATE TABLE array_test01 (
k1 INT,
k2 ARRAY<VARCHAR>
)
duplicate key (k1)
distributed by hash(k1) buckets 1
properties(
'replication_num' = '1'
);
INSERT INTO array_test01 VALUES
(1, ['a', 'b', 'c', 'd', 'e']),
(2, ['f', 'g', 'h']),
(3, ['']),
(3, [NULL]),
(5, ['a', 'b', 'c', 'd', 'e', 'a', 'b', 'c']),
(6, NULL),
(7, ['a', 'b', NULL]),
(8, ['a', 'b', NULL, NULL]);
select k1, k2, array_distinct(k2) from array_test01;
```
```text
+------+------------------------------------------+---------------------------+
| k1 | k2 | array_distinct(`k2`) |
+------+------------------------------------------+---------------------------+
Expand All @@ -64,11 +109,6 @@ mysql> select k1, k2, array_distinct(k2) from array_test01;
| 5 | ['a', 'b', 'c', 'd', 'e', 'a', 'b', 'c'] | ['a', 'b', 'c', 'd', 'e'] |
| 6 | NULL | NULL |
| 7 | ['a', 'b', NULL] | ['a', 'b', NULL] |
| 8 | ['a', 'b', NULL, NULL] | ['a', 'b', NULL] |
| 8 | ['a', 'b', NULL, NULL] | ['a', 'b', NULL] |
+------+------------------------------------------+---------------------------+
```

### keywords

ARRAY, DISTINCT, ARRAY_DISTINCT

```
Original file line number Diff line number Diff line change
Expand Up @@ -24,35 +24,43 @@ specific language governing permissions and limitations
under the License.
-->

## array_enumerate_uniq

array_enumerate_uniq

### description
#### Syntax

`ARRAY<T> array_enumerate_uniq(ARRAY<T> arr)`

## Description
Returns an array the same size as the source array, indicating for each element what its position is among elements with the same value. For example, array_enumerate_uniq([1, 2, 1, 4]) = [1, 1, 2, 1].
The array_enumerate_uniq function can take multiple arrays of the same size as arguments. In this case, uniqueness is considered for tuples of elements in the same positions in all the arrays. For example, array_enumerate_uniq([1, 2, 1, 1, 2], [2, 1, 2, 2, 1]) = [1, 1, 2, 3, 2].

### example
## Syntax
```sql
ARRAY_ENUMERATE_UNIQ(<arr1> [,<arr2> , ... ])
```
## Parameters
| Parameter | Description |
|---|---|
| `<arr1>` | Needed be computed array arr1 |
| `<arr2>` | Needed be computed array arr2 |

## Return Value
Returns an array the same size as the source array, indicating for each element what its position is among elements with the same value.

```shell
mysql> select k2, array_enumerate_uniq([1, 2, 3, 1, 2, 3]);
## Example

```sql
select array_enumerate_uniq([1, 2, 3, 1, 2, 3]);
```
```text
+-----------------------------------------------------+
| array_enumerate_uniq(ARRAY(1, 2, 3, 1, 2, 3)) |
+-----------------------------------------------------+
| [1, 1, 1, 2, 2, 2] |
+-----------------------------------------------------+
mysql> select array_enumerate_uniq([1, 1, 1, 1, 1], [2, 1, 2, 1, 2], [3, 1, 3, 1, 3]);
```
```sql
select array_enumerate_uniq([1, 1, 1, 1, 1], [2, 1, 2, 1, 2], [3, 1, 3, 1, 3]);
```
```text
+----------------------------------------------------------------------------------------+
| array_enumerate_uniq(ARRAY(1, 1, 1, 1, 1), ARRAY(2, 1, 2, 1, 2), ARRAY(3, 1, 3, 1, 3)) |
+----------------------------------------------------------------------------------------+
| [1, 1, 2, 1, 3] |
+----------------------------------------------------------------------------------------+
```

### keywords

ARRAY,ENUMERATE_UNIQ,ARRAY_ENUMERATE_UNIQ
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,41 @@ specific language governing permissions and limitations
under the License.
-->

## Description
Returns array sub item indexes e.g. [1, 2, 3, …, length (arr) ]

## array_enumerate

array_enumerate

### description
#### Syntax

`ARRAY<T> array_enumerate(ARRAY<T> arr)`
## Syntax
```sql
ARRAY_ENUMERATE(<arr>)
```

Returns array sub item indexes eg. [1, 2, 3, …, length (arr) ]
## Parameters
| Parameter | Description |
|---|---|
| `<arr>` | The array that returns array sub item indexes |

### example
## Return Value
Returns an array containing the index of the array.

```shell
mysql> create table array_type_table(k1 INT, k2 Array<STRING>) 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"]), ("4", NULL);
mysql> select k2, array_enumerate(k2) from array_type_table;
## Example
```sql
create table array_type_table(
k1 INT,
k2 Array<STRING>
)
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"]),
("4", NULL);
select k2, array_enumerate(k2) from array_type_table;
```
```text
+------------------+-----------------------+
| k2 | array_enumerate(`k2`) |
+------------------+-----------------------+
Expand All @@ -52,9 +68,4 @@ mysql> select k2, array_enumerate(k2) from array_type_table;
| ['1', NULL, '3'] | [1, 2, 3] |
| NULL | NULL |
+------------------+-----------------------+
5 rows in set (0.01 sec)
```

### keywords

ARRAY,ENUMERATE,ARRAY_ENUMERATE
```
Loading
Loading