diff --git a/docs/sql-manual/sql-functions/table-functions/posexplode.md b/docs/sql-manual/sql-functions/table-functions/posexplode.md index dcc6955223f5b..9f49f83734a2e 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() +POSEXPLODE_OUTER() ``` -### Example +## Parameters -```sql - CREATE TABLE IF NOT EXISTS `table_test`( - `id` INT NULL, - `name` TEXT NULL, - `score` array NULL - ) ENGINE=OLAP - DUPLICATE KEY(`id`) - COMMENT 'OLAP' - DISTRIBUTED BY HASH(`id`) BUCKETS 1 - PROPERTIES ("replication_allocation" = "tag.location.default: 1"); +| Parameter | Description | +| -- | -- | +| `` | 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 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 7c670ab5e4c22..1455c393a7c60 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() +POSEXPLODE_OUTER() ``` +## 参数 + +| 参数 | 说明 | +| -- | -- | +| `` | 待展开的 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 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 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/current/sql-manual/sql-functions/table-functions/posexplode-outer.md b/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/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-2.1/sql-manual/sql-functions/table-functions/posexplode.md index f8260ceb16490..1455c393a7c60 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-2.1/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() +POSEXPLODE_OUTER() ``` -### Example +## 参数 -```sql - CREATE TABLE IF NOT EXISTS `table_test`( - `id` INT NULL, - `name` TEXT NULL, - `score` array NULL - ) ENGINE=OLAP - DUPLICATE KEY(`id`) - COMMENT 'OLAP' - DISTRIBUTED BY HASH(`id`) BUCKETS 1 - PROPERTIES ("replication_allocation" = "tag.location.default: 1"); +| 参数 | 说明 | +| -- | -- | +| `` | 待展开的 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 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/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 f8260ceb16490..0000000000000 --- 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" -} ---- - - - -## 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 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-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/version-2.1/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 f8260ceb16490..1455c393a7c60 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/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() +POSEXPLODE_OUTER() ``` -### Example +## 参数 -```sql - CREATE TABLE IF NOT EXISTS `table_test`( - `id` INT NULL, - `name` TEXT NULL, - `score` array NULL - ) ENGINE=OLAP - DUPLICATE KEY(`id`) - COMMENT 'OLAP' - DISTRIBUTED BY HASH(`id`) BUCKETS 1 - PROPERTIES ("replication_allocation" = "tag.location.default: 1"); +| 参数 | 说明 | +| -- | -- | +| `` | 待展开的 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 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/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 74adc0e8ba560..9f49f83734a2e 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() +POSEXPLODE_OUTER() ``` -### Example +## Parameters -```sql - CREATE TABLE IF NOT EXISTS `table_test`( - `id` INT NULL, - `name` TEXT NULL, - `score` array NULL - ) ENGINE=OLAP - DUPLICATE KEY(`id`) - COMMENT 'OLAP' - DISTRIBUTED BY HASH(`id`) BUCKETS 1 - PROPERTIES ("replication_allocation" = "tag.location.default: 1"); +| Parameter | Description | +| -- | -- | +| `` | 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 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 74adc0e8ba560..0000000000000 --- 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" -} ---- - - - -## 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 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/versioned_docs/version-2.1/sql-manual/sql-functions/table-functions/posexplode-outer.md b/versioned_docs/version-3.0/sql-manual/sql-functions/table-functions/posexplode.md similarity index 67% rename from versioned_docs/version-2.1/sql-manual/sql-functions/table-functions/posexplode-outer.md rename to versioned_docs/version-3.0/sql-manual/sql-functions/table-functions/posexplode.md index 74adc0e8ba560..9f49f83734a2e 100644 --- a/versioned_docs/version-2.1/sql-manual/sql-functions/table-functions/posexplode-outer.md +++ b/versioned_docs/version-3.0/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() +POSEXPLODE_OUTER() ``` -### Example +## Parameters -```sql - CREATE TABLE IF NOT EXISTS `table_test`( - `id` INT NULL, - `name` TEXT NULL, - `score` array NULL - ) ENGINE=OLAP - DUPLICATE KEY(`id`) - COMMENT 'OLAP' - DISTRIBUTED BY HASH(`id`) BUCKETS 1 - PROPERTIES ("replication_allocation" = "tag.location.default: 1"); +| Parameter | Description | +| -- | -- | +| `` | 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 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