Skip to content
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
11 changes: 11 additions & 0 deletions docs/.vuepress/sidebar/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,16 @@ module.exports = [
"WINDOW-FUNCTION-ROW-NUMBER",
],
},
{
title: "Array Functions",
directoryPath: "array-functions/",
initialOpenGroupIndex: -1,
children: [
"array_contains",
"array_position",
"element_at",
],
},
"cast",
"digital-masking",
],
Expand Down Expand Up @@ -812,6 +822,7 @@ module.exports = [
"STRING",
"TINYINT",
"VARCHAR",
"ARRAY",
],
},
{
Expand Down
11 changes: 11 additions & 0 deletions docs/.vuepress/sidebar/zh-CN.js
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,16 @@ module.exports = [
"WINDOW-FUNCTION-ROW-NUMBER",
],
},
{
title: "Array函数",
directoryPath: "array-functions/",
initialOpenGroupIndex: -1,
children: [
"array_contains",
"array_position",
"element_at",
],
},
"cast",
"digital-masking",
],
Expand Down Expand Up @@ -812,6 +822,7 @@ module.exports = [
"STRING",
"TINYINT",
"VARCHAR",
"ARRAY",
],
},
{
Expand Down
65 changes: 65 additions & 0 deletions docs/en/sql-manual/sql-functions/array-functions/array_contains.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
---
{
"title": "array_contains",
"language": "en"
}
---

<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->

## array_contains

### description

#### Syntax

`BOOLEAN array_contains(ARRAY<T> arr, T value)`

Check if a value presents in an array column. Return below values:

```
1 - if value presents in an array;
0 - if value does not present in an array;
NULL - when array is NULL;
```

### notice

`Only supported in vectorized engine`

### example

```
mysql> set enable_vectorized_engine=true;

mysql> SELECT id,c_array,array_contains(c_array, 5) FROM `array_test`;
+------+-----------------+------------------------------+
| id | c_array | array_contains(`c_array`, 5) |
+------+-----------------+------------------------------+
| 1 | [1, 2, 3, 4, 5] | 1 |
| 2 | [6, 7, 8] | 0 |
| 3 | [] | 0 |
| 4 | NULL | NULL |
+------+-----------------+------------------------------+
```

### keywords

ARRAY_CONTAINS
65 changes: 65 additions & 0 deletions docs/en/sql-manual/sql-functions/array-functions/array_position.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
---
{
"title": "array_position",
"language": "en"
}
---

<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->

## array_position

### description

#### Syntax

`BIGINT array_position(ARRAY<T> arr, T value)`

Returns a position/index of first occurrence of the `value` in the given array.

```
position - value position in array (starts with 1);
0 - if value does not present in the array;
NULL - when array is NULL or value is NULL.
```

### notice

`Only supported in vectorized engine`

### example

```
mysql> set enable_vectorized_engine=true;

mysql> SELECT id,c_array,array_position(c_array, 5) FROM `array_test`;
+------+-----------------+------------------------------+
| id | c_array | array_position(`c_array`, 5) |
+------+-----------------+------------------------------+
| 1 | [1, 2, 3, 4, 5] | 5 |
| 2 | [6, 7, 8] | 0 |
| 3 | [] | 0 |
| 4 | NULL | NULL |
+------+-----------------+------------------------------+
```

### keywords

ARRAY_POSITION
81 changes: 81 additions & 0 deletions docs/en/sql-manual/sql-functions/array-functions/element_at.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
---
{
"title": "element_at",
"language": "en"
}
---

<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->

## element_at

### description

#### Syntax

`T element_at(ARRAY<T> arr, BIGINT position)`

`T arr[position]`

Returns an element of an array located at the input position. If there is no element at the position, return NULL.

`position` is 1-based and support negtive number.

### notice

`Only supported in vectorized engine`

### example

positive `position` example:

```
mysql> set enable_vectorized_engine=true;

mysql> SELECT id,c_array,element_at(c_array, 5) FROM `array_test`;
+------+-----------------+--------------------------+
| id | c_array | element_at(`c_array`, 5) |
+------+-----------------+--------------------------+
| 1 | [1, 2, 3, 4, 5] | 5 |
| 2 | [6, 7, 8] | NULL |
| 3 | [] | NULL |
| 4 | NULL | NULL |
+------+-----------------+--------------------------+
```

negtive `position` example:

```
mysql> set enable_vectorized_engine=true;

mysql> SELECT id,c_array,c_array[-2] FROM `array_test`;
+------+-----------------+----------------------------------+
| id | c_array | %element_extract%(`c_array`, -2) |
+------+-----------------+----------------------------------+
| 1 | [1, 2, 3, 4, 5] | 4 |
| 2 | [6, 7, 8] | 7 |
| 3 | [] | NULL |
| 4 | NULL | NULL |
+------+-----------------+----------------------------------+
```

### keywords

ELEMENT_AT, SUBSCRIPT
84 changes: 84 additions & 0 deletions docs/en/sql-manual/sql-reference/Data-Types/ARRAY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
---
{
"title": "ARRAY",
"language": "en"
}
---

<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->

## ARRAY

### description

ARRAY\<T\>

An array of T-type items, it cannot be used as a key column. Now ARRAY can only used in Duplicate Model Tables.

T-type could be any of:

```
BOOLEAN, TINYINT, SMALLINT, INT, BIGINT, LARGEINT, FLOAT, DOUBLE, DECIMAL, DATE,
DATETIME, CHAR, VARCHAR, STRING
```

### example

Create table example:

```
mysql> CREATE TABLE `array_test` (
`id` int(11) NULL COMMENT "",
`c_array` ARRAY<int(11)> NULL COMMENT ""
) ENGINE=OLAP
DUPLICATE KEY(`id`)
COMMENT "OLAP"
DISTRIBUTED BY HASH(`id`) BUCKETS 1
PROPERTIES (
"replication_allocation" = "tag.location.default: 1",
"in_memory" = "false",
"storage_format" = "V2"
);
```

Insert data example:

```
mysql> INSERT INTO `array_test` VALUES (1, [1,2,3,4,5]);
mysql> INSERT INTO `array_test` VALUES (2, array(6,7,8)), (3, array()), (4, null);
```

Select data example:

```
mysql> SELECT * FROM `array_test`;
+------+-----------------+
| id | c_array |
+------+-----------------+
| 1 | [1, 2, 3, 4, 5] |
| 2 | [6, 7, 8] |
| 3 | [] |
| 4 | NULL |
+------+-----------------+
```

### keywords

ARRAY, array_contains, array_position, element_at
Loading