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 a9f1b00259b [doc] posexplode func (#2317) a9f1b00259b is described below commit a9f1b00259b0d1287497c045509ec2da1fbf321b Author: yuanyuan8983 <99315889+yuanyuan8...@users.noreply.github.com> AuthorDate: Wed Apr 23 17:40:11 2025 +0800 [doc] posexplode func (#2317) ## Versions - [x] dev - [x] 3.0 - [x] 2.1 - [ ] 2.0 ## Languages - [x] Chinese - [x] English ## Docs Checklist - [ ] Checked by AI - [ ] Test Cases Built --- .../sql-functions/table-functions/posexplode.md | 71 +++++++++++----- .../sql-functions/table-functions/posexplode.md | 70 ++++++++++------ .../sql-functions/table-functions/posexplode.md | 30 +++---- .../table-functions/posexplode-outer.md | 97 ---------------------- .../sql-functions/table-functions/posexplode.md} | 74 +++++++++++------ .../table-functions/posexplode-outer.md | 97 ---------------------- .../sql-functions/table-functions/posexplode.md | 73 ++++++++++------ .../table-functions/posexplode-outer.md | 97 ---------------------- .../sql-functions/table-functions/posexplode.md | 47 +++++------ 9 files changed, 227 insertions(+), 429 deletions(-) diff --git a/docs/sql-manual/sql-functions/table-functions/posexplode.md b/docs/sql-manual/sql-functions/table-functions/posexplode.md index dcc6955223f..9f49f83734a 100644 --- a/docs/sql-manual/sql-functions/table-functions/posexplode.md +++ b/docs/sql-manual/sql-functions/table-functions/posexplode.md @@ -26,33 +26,51 @@ 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. +The `posexplode` table function expands an array column into multiple rows and adds a column indicating the position of each element, returning a struct type. It must be used with LATERAL VIEW and supports multiple LATERAL VIEWs. Only supported with the new optimizer. -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. +`posexplode_outer` is similar to `posexplode`, except for the handling of NULL values. ## Syntax + ```sql -posexplode(array) -posexplode_outer(array) +POSEXPLODE(<arr>) +POSEXPLODE_OUTER(<arr>) ``` -### Example +## Parameters -```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"); +| Parameter | Description | +| -- | -- | +| `<arr>` | An array that is to be expanded | + +## Return Value -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); +When the array is NULL or empty, posexplode_outer returns NULL. +Both `posexplode` and `posexplode_outer` include NULL elements inside the array. + +## Examples + +``` 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"); +``` +```sql +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 | +------+----------+--------------------------------+ @@ -62,8 +80,13 @@ mysql [test_query_qa]>select * from table_test order by id; | 3 | lisi2 | [null] | | 4 | amory | NULL | +------+----------+--------------------------------+ +``` -mysql [test_query_qa]>select id,name,score, k,v from table_test lateral view posexplode(score) tmp as k,v order by id; +```sql +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 | +------+----------+--------------------------------+------+---------+ @@ -76,8 +99,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 | +------+----------+--------------------------------+------+---------+ +``` -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; +```sql +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 | +------+----------+--------------------------------+------+---------+ @@ -91,7 +119,4 @@ mysql [test_query_qa]>select id,name,score, k,v from table_test lateral view pos | 3 | lisi2 | [null] | 0 | NULL | | 4 | amory | NULL | NULL | NULL | +------+----------+--------------------------------+------+---------+ -``` - -### Keywords -POSEXPLODE,POSEXPLODE_OUTER +``` \ No newline at end of file diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/table-functions/posexplode.md b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/table-functions/posexplode.md index a1395dadbc3..1455c393a7c 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/table-functions/posexplode.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/table-functions/posexplode.md @@ -24,37 +24,52 @@ specific language governing permissions and limitations under the License. --> -## Description +## 描述 -表函数,需配合 Lateral View 使用,可以支持多个 Lateral view, 仅仅支持新优化器。 +`posexplode` 表函数,将 array 列展开成多行, 并且增加一列标明位置的列,组成 struct类型返回。需配合 Lateral View 使用, 可以支持多个 Lateral view, 仅支持新优化器。 -将 array 列展开成多行,并且增加一列标明位置的列,组成 struct 类型返回。 -当 array 为 NULL 或者为空时,`posexplode_outer` 返回 NULL。 -`posexplode` 和 `posexplode_outer` 均会返回 array 内部的 NULL 元素。 +`posexplode_outer` 和 `posexplode` 类似,只是对于 NULL 值的处理不同。 -## Syntax +## 语法 ```sql -posexplode(expr) -posexplode_outer(expr) +POSEXPLODE(<arr>) +POSEXPLODE_OUTER(<arr>) ``` +## 参数 + +| 参数 | 说明 | +| -- | -- | +| `<arr>` | 待展开的 array 数组 | + + +## 返回值 + +当 array 为 NULL 或者为空时,`posexplode_outer` 返回NULL。 `posexplode` 和 `posexplode_outer` 均会返回 array 内部的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); +```sql +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 | +------+----------+--------------------------------+ @@ -64,8 +79,13 @@ mysql [test_query_qa]>select * from table_test order by id; | 3 | lisi2 | [null] | | 4 | amory | NULL | +------+----------+--------------------------------+ +``` -mysql [test_query_qa]>select id,name,score, k,v from table_test lateral view posexplode(score) tmp as k,v order by id; +```sql +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 | +------+----------+--------------------------------+------+---------+ @@ -78,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 | +------+----------+--------------------------------+------+---------+ +``` -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; +```sql +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 | +------+----------+--------------------------------+------+---------+ @@ -94,6 +119,3 @@ mysql [test_query_qa]>select id,name,score, k,v from table_test lateral view pos | 4 | amory | NULL | NULL | NULL | +------+----------+--------------------------------+------+---------+ ``` - -### Keywords -POSEXPLODE,POSEXPLODE_OUTER diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/table-functions/posexplode.md b/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/table-functions/posexplode.md index 528092dd93b..1455c393a7c 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/table-functions/posexplode.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/table-functions/posexplode.md @@ -26,33 +26,30 @@ under the License. ## 描述 -表函数,需配合 Lateral View 使用,并且支持多个 Lateral View。它仅支持新的优化器。 +`posexplode` 表函数,将 array 列展开成多行, 并且增加一列标明位置的列,组成 struct类型返回。需配合 Lateral View 使用, 可以支持多个 Lateral view, 仅支持新优化器。 -该函数将数组列展开为多行,并添加一个表示位置的列,返回一个结构体类型。当数组为 NULL 或空时,posexplode_outer 会返回 NULL。posexplode 和 posexplode_outer 均会返回数组中的 NULL 元素。 +`posexplode_outer` 和 `posexplode` 类似,只是对于 NULL 值的处理不同。 ## 语法 ```sql -POSEXPLODE(<array>) -POSEXPLODE_OUTER(<array>) +POSEXPLODE(<arr>) +POSEXPLODE_OUTER(<arr>) ``` ## 参数 | 参数 | 说明 | | -- | -- | -| `<array>` | 需要被展开为多行的数组 | +| `<arr>` | 待展开的 array 数组 | ## 返回值 -按照数组 array 展开的多行。特殊情况: +当 array 为 NULL 或者为空时,`posexplode_outer` 返回NULL。 `posexplode` 和 `posexplode_outer` 均会返回 array 内部的NULL元素。 -- 当数组为 NULL 或空时,返回 NULL。 -- 当数组存在 NULL 元素时,返回 NULL 元素。 +## 举例 -### 举例 - -```sql +``` sql CREATE TABLE IF NOT EXISTS `table_test`( `id` INT NULL, `name` TEXT NULL, @@ -62,11 +59,13 @@ CREATE TABLE IF NOT EXISTS `table_test`( COMMENT 'OLAP' DISTRIBUTED BY HASH(`id`) BUCKETS 1 PROPERTIES ("replication_allocation" = "tag.location.default: 1"); +``` +```sql 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 +```sql select * from table_test order by id; ``` @@ -82,7 +81,7 @@ select * from table_test order by id; +------+----------+--------------------------------+ ``` -```sql +```sql select id,name,score, k,v from table_test lateral view posexplode(score) tmp as k,v order by id; ``` @@ -101,7 +100,7 @@ select id,name,score, k,v from table_test lateral view posexplode(score) tmp as +------+----------+--------------------------------+------+---------+ ``` -```sql +```sql select id,name,score, k,v from table_test lateral view posexplode_outer(score) tmp as k,v order by id; ``` @@ -120,6 +119,3 @@ select id,name,score, k,v from table_test lateral view posexplode_outer(score) t | 4 | amory | NULL | NULL | NULL | +------+----------+--------------------------------+------+---------+ ``` - -### Keywords -POSEXPLODE,POSEXPLODE_OUTER diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/table-functions/posexplode-outer.md b/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/table-functions/posexplode-outer.md deleted file mode 100644 index f8260ceb164..00000000000 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/table-functions/posexplode-outer.md +++ /dev/null @@ -1,97 +0,0 @@ ---- -{ -"title": "posexplode_outer", -"language": "zh-CN" -} ---- - -<!-- -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. ---> - -## Description - -The table function is used in conjunction with Lateral View and can support multiple Lateral Views. It only supports the new optimizer. - -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. - -## Syntax -```sql -posexplode(array) -posexplode_outer(array) -``` - -### Example - -```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"); - -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); - - -mysql [test_query_qa]>select * from table_test order by id; -+------+----------+--------------------------------+ -| id | name | score | -+------+----------+--------------------------------+ -| 0 | zhangsan | ["Chinese", "Math", "English"] | -| 1 | lisi | ["null"] | -| 2 | wangwu | ["88a", "90b", "96c"] | -| 3 | lisi2 | [null] | -| 4 | amory | NULL | -+------+----------+--------------------------------+ - -mysql [test_query_qa]>select id,name,score, k,v from table_test lateral view posexplode(score) tmp as k,v order by id; -+------+----------+--------------------------------+------+---------+ -| id | name | score | k | v | -+------+----------+--------------------------------+------+---------+ -| 0 | zhangsan | ["Chinese", "Math", "English"] | 0 | Chinese | -| 0 | zhangsan | ["Chinese", "Math", "English"] | 1 | Math | -| 0 | zhangsan | ["Chinese", "Math", "English"] | 2 | English | -| 1 | lisi | ["null"] | 0 | null | -| 2 | wangwu | ["88a", "90b", "96c"] | 0 | 88a | -| 2 | wangwu | ["88a", "90b", "96c"] | 1 | 90b | -| 2 | wangwu | ["88a", "90b", "96c"] | 2 | 96c | -| 3 | lisi2 | [null] | 0 | NULL | -+------+----------+--------------------------------+------+---------+ - -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; -+------+----------+--------------------------------+------+---------+ -| id | name | score | k | v | -+------+----------+--------------------------------+------+---------+ -| 0 | zhangsan | ["Chinese", "Math", "English"] | 0 | Chinese | -| 0 | zhangsan | ["Chinese", "Math", "English"] | 1 | Math | -| 0 | zhangsan | ["Chinese", "Math", "English"] | 2 | English | -| 1 | lisi | ["null"] | 0 | null | -| 2 | wangwu | ["88a", "90b", "96c"] | 0 | 88a | -| 2 | wangwu | ["88a", "90b", "96c"] | 1 | 90b | -| 2 | wangwu | ["88a", "90b", "96c"] | 2 | 96c | -| 3 | lisi2 | [null] | 0 | NULL | -| 4 | amory | NULL | NULL | NULL | -+------+----------+--------------------------------+------+---------+ -``` - -### Keywords -POSEXPLODE,POSEXPLODE_OUTER diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/table-functions/posexplode-outer.md b/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/table-functions/posexplode.md similarity index 67% rename from i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/table-functions/posexplode-outer.md rename to i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/table-functions/posexplode.md index f8260ceb164..1455c393a7c 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/table-functions/posexplode-outer.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/table-functions/posexplode.md @@ -1,6 +1,6 @@ --- { -"title": "posexplode_outer", +"title": "POSEXPLODE", "language": "zh-CN" } --- @@ -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. +`posexplode` 表函数,将 array 列展开成多行, 并且增加一列标明位置的列,组成 struct类型返回。需配合 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. +`posexplode_outer` 和 `posexplode` 类似,只是对于 NULL 值的处理不同。 -## Syntax +## 语法 ```sql -posexplode(array) -posexplode_outer(array) +POSEXPLODE(<arr>) +POSEXPLODE_OUTER(<arr>) ``` -### Example +## 参数 -```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"); +| 参数 | 说明 | +| -- | -- | +| `<arr>` | 待展开的 array 数组 | + + +## 返回值 + +当 array 为 NULL 或者为空时,`posexplode_outer` 返回NULL。 `posexplode` 和 `posexplode_outer` 均会返回 array 内部的NULL元素。 + +## 举例 -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); +``` 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"); +``` +```sql +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 | +------+----------+--------------------------------+ @@ -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 | +------+----------+--------------------------------+------+---------+ @@ -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 | +------+----------+--------------------------------+------+---------+ +``` -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; +```sql +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 | +------+----------+--------------------------------+------+---------+ @@ -92,6 +119,3 @@ mysql [test_query_qa]>select id,name,score, k,v from table_test lateral view pos | 4 | amory | NULL | NULL | NULL | +------+----------+--------------------------------+------+---------+ ``` - -### Keywords -POSEXPLODE,POSEXPLODE_OUTER diff --git a/versioned_docs/version-2.1/sql-manual/sql-functions/table-functions/posexplode-outer.md b/versioned_docs/version-2.1/sql-manual/sql-functions/table-functions/posexplode-outer.md deleted file mode 100644 index 74adc0e8ba5..00000000000 --- a/versioned_docs/version-2.1/sql-manual/sql-functions/table-functions/posexplode-outer.md +++ /dev/null @@ -1,97 +0,0 @@ ---- -{ -"title": "posexplode_outer", -"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. ---> - -## Description - -The table function is used in conjunction with Lateral View and can support multiple Lateral Views. It only supports the new optimizer. - -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. - -## Syntax -```sql -posexplode(array) -posexplode_outer(array) -``` - -### Example - -```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"); - -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); - - -mysql [test_query_qa]>select * from table_test order by id; -+------+----------+--------------------------------+ -| id | name | score | -+------+----------+--------------------------------+ -| 0 | zhangsan | ["Chinese", "Math", "English"] | -| 1 | lisi | ["null"] | -| 2 | wangwu | ["88a", "90b", "96c"] | -| 3 | lisi2 | [null] | -| 4 | amory | NULL | -+------+----------+--------------------------------+ - -mysql [test_query_qa]>select id,name,score, k,v from table_test lateral view posexplode(score) tmp as k,v order by id; -+------+----------+--------------------------------+------+---------+ -| id | name | score | k | v | -+------+----------+--------------------------------+------+---------+ -| 0 | zhangsan | ["Chinese", "Math", "English"] | 0 | Chinese | -| 0 | zhangsan | ["Chinese", "Math", "English"] | 1 | Math | -| 0 | zhangsan | ["Chinese", "Math", "English"] | 2 | English | -| 1 | lisi | ["null"] | 0 | null | -| 2 | wangwu | ["88a", "90b", "96c"] | 0 | 88a | -| 2 | wangwu | ["88a", "90b", "96c"] | 1 | 90b | -| 2 | wangwu | ["88a", "90b", "96c"] | 2 | 96c | -| 3 | lisi2 | [null] | 0 | NULL | -+------+----------+--------------------------------+------+---------+ - -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; -+------+----------+--------------------------------+------+---------+ -| id | name | score | k | v | -+------+----------+--------------------------------+------+---------+ -| 0 | zhangsan | ["Chinese", "Math", "English"] | 0 | Chinese | -| 0 | zhangsan | ["Chinese", "Math", "English"] | 1 | Math | -| 0 | zhangsan | ["Chinese", "Math", "English"] | 2 | English | -| 1 | lisi | ["null"] | 0 | null | -| 2 | wangwu | ["88a", "90b", "96c"] | 0 | 88a | -| 2 | wangwu | ["88a", "90b", "96c"] | 1 | 90b | -| 2 | wangwu | ["88a", "90b", "96c"] | 2 | 96c | -| 3 | lisi2 | [null] | 0 | NULL | -| 4 | amory | NULL | NULL | NULL | -+------+----------+--------------------------------+------+---------+ -``` - -### Keywords -POSEXPLODE,POSEXPLODE_OUTER diff --git a/docs/sql-manual/sql-functions/table-functions/posexplode-outer.md b/versioned_docs/version-2.1/sql-manual/sql-functions/table-functions/posexplode.md similarity index 67% rename from docs/sql-manual/sql-functions/table-functions/posexplode-outer.md rename to versioned_docs/version-2.1/sql-manual/sql-functions/table-functions/posexplode.md index 74adc0e8ba5..9f49f83734a 100644 --- a/docs/sql-manual/sql-functions/table-functions/posexplode-outer.md +++ b/versioned_docs/version-2.1/sql-manual/sql-functions/table-functions/posexplode.md @@ -1,6 +1,6 @@ --- { -"title": "posexplode_outer", +"title": "POSEXPLODE", "language": "en" } --- @@ -26,33 +26,51 @@ 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. +The `posexplode` table function expands an array column into multiple rows and adds a column indicating the position of each element, returning a struct type. It must be used with LATERAL VIEW and supports multiple LATERAL VIEWs. Only supported with the new optimizer. -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. +`posexplode_outer` is similar to `posexplode`, except for the handling of NULL values. ## Syntax + ```sql -posexplode(array) -posexplode_outer(array) +POSEXPLODE(<arr>) +POSEXPLODE_OUTER(<arr>) ``` -### Example +## Parameters -```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"); +| Parameter | Description | +| -- | -- | +| `<arr>` | An array that is to be expanded | + +## Return Value -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); +When the array is NULL or empty, posexplode_outer returns NULL. +Both `posexplode` and `posexplode_outer` include NULL elements inside the array. + +## Examples + +``` 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"); +``` +```sql +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 | +------+----------+--------------------------------+ @@ -62,8 +80,13 @@ mysql [test_query_qa]>select * from table_test order by id; | 3 | lisi2 | [null] | | 4 | amory | NULL | +------+----------+--------------------------------+ +``` -mysql [test_query_qa]>select id,name,score, k,v from table_test lateral view posexplode(score) tmp as k,v order by id; +```sql +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 | +------+----------+--------------------------------+------+---------+ @@ -76,8 +99,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 | +------+----------+--------------------------------+------+---------+ +``` -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; +```sql +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 | +------+----------+--------------------------------+------+---------+ @@ -91,7 +119,4 @@ mysql [test_query_qa]>select id,name,score, k,v from table_test lateral view pos | 3 | lisi2 | [null] | 0 | NULL | | 4 | amory | NULL | NULL | NULL | +------+----------+--------------------------------+------+---------+ -``` - -### Keywords -POSEXPLODE,POSEXPLODE_OUTER +``` \ No newline at end of file diff --git a/versioned_docs/version-3.0/sql-manual/sql-functions/table-functions/posexplode-outer.md b/versioned_docs/version-3.0/sql-manual/sql-functions/table-functions/posexplode-outer.md deleted file mode 100644 index 74adc0e8ba5..00000000000 --- a/versioned_docs/version-3.0/sql-manual/sql-functions/table-functions/posexplode-outer.md +++ /dev/null @@ -1,97 +0,0 @@ ---- -{ -"title": "posexplode_outer", -"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. ---> - -## Description - -The table function is used in conjunction with Lateral View and can support multiple Lateral Views. It only supports the new optimizer. - -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. - -## Syntax -```sql -posexplode(array) -posexplode_outer(array) -``` - -### Example - -```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"); - -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); - - -mysql [test_query_qa]>select * from table_test order by id; -+------+----------+--------------------------------+ -| id | name | score | -+------+----------+--------------------------------+ -| 0 | zhangsan | ["Chinese", "Math", "English"] | -| 1 | lisi | ["null"] | -| 2 | wangwu | ["88a", "90b", "96c"] | -| 3 | lisi2 | [null] | -| 4 | amory | NULL | -+------+----------+--------------------------------+ - -mysql [test_query_qa]>select id,name,score, k,v from table_test lateral view posexplode(score) tmp as k,v order by id; -+------+----------+--------------------------------+------+---------+ -| id | name | score | k | v | -+------+----------+--------------------------------+------+---------+ -| 0 | zhangsan | ["Chinese", "Math", "English"] | 0 | Chinese | -| 0 | zhangsan | ["Chinese", "Math", "English"] | 1 | Math | -| 0 | zhangsan | ["Chinese", "Math", "English"] | 2 | English | -| 1 | lisi | ["null"] | 0 | null | -| 2 | wangwu | ["88a", "90b", "96c"] | 0 | 88a | -| 2 | wangwu | ["88a", "90b", "96c"] | 1 | 90b | -| 2 | wangwu | ["88a", "90b", "96c"] | 2 | 96c | -| 3 | lisi2 | [null] | 0 | NULL | -+------+----------+--------------------------------+------+---------+ - -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; -+------+----------+--------------------------------+------+---------+ -| id | name | score | k | v | -+------+----------+--------------------------------+------+---------+ -| 0 | zhangsan | ["Chinese", "Math", "English"] | 0 | Chinese | -| 0 | zhangsan | ["Chinese", "Math", "English"] | 1 | Math | -| 0 | zhangsan | ["Chinese", "Math", "English"] | 2 | English | -| 1 | lisi | ["null"] | 0 | null | -| 2 | wangwu | ["88a", "90b", "96c"] | 0 | 88a | -| 2 | wangwu | ["88a", "90b", "96c"] | 1 | 90b | -| 2 | wangwu | ["88a", "90b", "96c"] | 2 | 96c | -| 3 | lisi2 | [null] | 0 | NULL | -| 4 | amory | NULL | NULL | NULL | -+------+----------+--------------------------------+------+---------+ -``` - -### Keywords -POSEXPLODE,POSEXPLODE_OUTER diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/table-functions/posexplode.md b/versioned_docs/version-3.0/sql-manual/sql-functions/table-functions/posexplode.md similarity index 83% copy from i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/table-functions/posexplode.md copy to versioned_docs/version-3.0/sql-manual/sql-functions/table-functions/posexplode.md index 528092dd93b..9f49f83734a 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/table-functions/posexplode.md +++ b/versioned_docs/version-3.0/sql-manual/sql-functions/table-functions/posexplode.md @@ -1,7 +1,7 @@ --- { "title": "POSEXPLODE", -"language": "zh-CN" +"language": "en" } --- @@ -24,35 +24,33 @@ specific language governing permissions and limitations under the License. --> -## 描述 +## Description -表函数,需配合 Lateral View 使用,并且支持多个 Lateral View。它仅支持新的优化器。 +The `posexplode` table function expands an array column into multiple rows and adds a column indicating the position of each element, returning a struct type. It must be used with LATERAL VIEW and supports multiple LATERAL VIEWs. Only supported with the new optimizer. -该函数将数组列展开为多行,并添加一个表示位置的列,返回一个结构体类型。当数组为 NULL 或空时,posexplode_outer 会返回 NULL。posexplode 和 posexplode_outer 均会返回数组中的 NULL 元素。 +`posexplode_outer` is similar to `posexplode`, except for the handling of NULL values. + +## Syntax -## 语法 ```sql -POSEXPLODE(<array>) -POSEXPLODE_OUTER(<array>) +POSEXPLODE(<arr>) +POSEXPLODE_OUTER(<arr>) ``` -## 参数 +## Parameters -| 参数 | 说明 | +| Parameter | Description | | -- | -- | -| `<array>` | 需要被展开为多行的数组 | - - -## 返回值 +| `<arr>` | An array that is to be expanded | -按照数组 array 展开的多行。特殊情况: +## Return Value -- 当数组为 NULL 或空时,返回 NULL。 -- 当数组存在 NULL 元素时,返回 NULL 元素。 +When the array is NULL or empty, posexplode_outer returns NULL. +Both `posexplode` and `posexplode_outer` include NULL elements inside the array. -### 举例 +## Examples -```sql +``` sql CREATE TABLE IF NOT EXISTS `table_test`( `id` INT NULL, `name` TEXT NULL, @@ -62,11 +60,13 @@ CREATE TABLE IF NOT EXISTS `table_test`( COMMENT 'OLAP' DISTRIBUTED BY HASH(`id`) BUCKETS 1 PROPERTIES ("replication_allocation" = "tag.location.default: 1"); +``` +```sql 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 +```sql select * from table_test order by id; ``` @@ -82,7 +82,7 @@ select * from table_test order by id; +------+----------+--------------------------------+ ``` -```sql +```sql select id,name,score, k,v from table_test lateral view posexplode(score) tmp as k,v order by id; ``` @@ -101,7 +101,7 @@ select id,name,score, k,v from table_test lateral view posexplode(score) tmp as +------+----------+--------------------------------+------+---------+ ``` -```sql +```sql select id,name,score, k,v from table_test lateral view posexplode_outer(score) tmp as k,v order by id; ``` @@ -119,7 +119,4 @@ select id,name,score, k,v from table_test lateral view posexplode_outer(score) t | 3 | lisi2 | [null] | 0 | NULL | | 4 | amory | NULL | NULL | NULL | +------+----------+--------------------------------+------+---------+ -``` - -### Keywords -POSEXPLODE,POSEXPLODE_OUTER +``` \ No newline at end of file --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org