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] translate explode json array double #1932

Merged
merged 8 commits into from
Feb 12, 2025
Original file line number Diff line number Diff line change
Expand Up @@ -24,35 +24,52 @@ specific language governing permissions and limitations
under the License.
-->

## Description
## 描述

The table function is used in conjunction with Lateral View and can support multiple Lateral Views. It only supports the new optimizer.
表函数,需配合 Lateral View使用,并且支持多个Lateral View。它仅支持新的优化器。

It expands an array column into multiple rows and adds a column indicating the position, returning a struct type. When the array is NULL or empty, posexplode_outer returns NULL. Both posexplode and posexplode_outer will return NULL elements within the array.
该函数将数组列展开为多行,并添加一个表示位置的列,返回一个结构体类型。当数组为NULL或空时,posexplode_outer会返回 NULL。posexplode和posexplode_outer均会返回数组中的NULL元素。

## Syntax
## 语法
```sql
posexplode(array)
posexplode_outer(array)
POSEXPLODE(<array>)
POSEXPLODE_OUTER(<array>)
```

### Example
## 参数

| 参数 | 说明 |
| -- | -- |
| `<array>` | 需要被展开为多行的数组 |

## 返回值

按照数组array展开的多行。特殊情况:

- 当数组为NULL或空时,返回NULL。
- 当数组存在NULL元素时,返回NULL元素。

### 举例

```sql
CREATE TABLE IF NOT EXISTS `table_test`(
`id` INT NULL,
`name` TEXT NULL,
`score` array<string> NULL
) ENGINE=OLAP
DUPLICATE KEY(`id`)
COMMENT 'OLAP'
DISTRIBUTED BY HASH(`id`) BUCKETS 1
PROPERTIES ("replication_allocation" = "tag.location.default: 1");
CREATE TABLE IF NOT EXISTS `table_test`(
`id` INT NULL,
`name` TEXT NULL,
`score` array<string> NULL
) ENGINE=OLAP
DUPLICATE KEY(`id`)
COMMENT 'OLAP'
DISTRIBUTED BY HASH(`id`) BUCKETS 1
PROPERTIES ("replication_allocation" = "tag.location.default: 1");

mysql> insert into table_test values (0, "zhangsan", ["Chinese","Math","English"]),(1, "lisi", ["null"]),(2, "wangwu", ["88a","90b","96c"]),(3, "lisi2", [null]),(4, "amory", NULL);
insert into table_test values (0, "zhangsan", ["Chinese","Math","English"]),(1, "lisi", ["null"]),(2, "wangwu", ["88a","90b","96c"]),(3, "lisi2", [null]),(4, "amory", NULL);
```

```sql
select * from table_test order by id;
```

mysql [test_query_qa]>select * from table_test order by id;
```text
+------+----------+--------------------------------+
| id | name | score |
+------+----------+--------------------------------+
Expand All @@ -62,8 +79,13 @@ mysql [test_query_qa]>select * from table_test order by id;
| 3 | lisi2 | [null] |
| 4 | amory | NULL |
+------+----------+--------------------------------+
```

```sql
select id,name,score, k,v from table_test lateral view posexplode(score) tmp as k,v order by id;
```

mysql [test_query_qa]>select id,name,score, k,v from table_test lateral view posexplode(score) tmp as k,v order by id;
```text
+------+----------+--------------------------------+------+---------+
| id | name | score | k | v |
+------+----------+--------------------------------+------+---------+
Expand All @@ -76,8 +98,13 @@ mysql [test_query_qa]>select id,name,score, k,v from table_test lateral view pos
| 2 | wangwu | ["88a", "90b", "96c"] | 2 | 96c |
| 3 | lisi2 | [null] | 0 | NULL |
+------+----------+--------------------------------+------+---------+
```

```sql
select id,name,score, k,v from table_test lateral view posexplode_outer(score) tmp as k,v order by id;
```

mysql [test_query_qa]>select id,name,score, k,v from table_test lateral view posexplode_outer(score) tmp as k,v order by id;
```text
+------+----------+--------------------------------+------+---------+
| id | name | score | k | v |
+------+----------+--------------------------------+------+---------+
Expand Down