From 572ff4ed89605818c349bed7db7189e6536208a7 Mon Sep 17 00:00:00 2001 From: nagisa-kun <1434936049@qq.com> Date: Wed, 24 Dec 2025 22:20:04 +0800 Subject: [PATCH 01/11] feat: mapconcat --- .../map-functions/mapconcat.md | 72 +++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 docs/sql-manual/sql-functions/scalar-functions/map-functions/mapconcat.md diff --git a/docs/sql-manual/sql-functions/scalar-functions/map-functions/mapconcat.md b/docs/sql-manual/sql-functions/scalar-functions/map-functions/mapconcat.md new file mode 100644 index 0000000000000..1888829ba124a --- /dev/null +++ b/docs/sql-manual/sql-functions/scalar-functions/map-functions/mapconcat.md @@ -0,0 +1,72 @@ +--- +{ + "title": "MAP_CONCAT", + "language": "en" +} +--- + +## Description + +Concatenates multiple maps into a single map. + +## Syntax + +```sql +MAP_CONCAT( [, [, ... ]]) +``` + +## Parameters +- ``, ``, ``, ...: [`MAP`](../../../basic-element/sql-data-types/semi-structured/MAP.md) type, the input maps to concatenate. + +## Return Value +Returns a concatenated `MAP` containing all key-value pairs from the input maps. + +## Usage Notes +1. The function accepts zero or more map arguments. +2. If any argument is NULL, the result is NULL. + +## Examples +1. Basic usage + ```sql + select map_concat() as empty_map; + ``` + ```text + +-----------+ + | empty_map | + +-----------+ + | {} | + +-----------+ + ``` + + ```sql + select map_concat(map('single', 'argument')) as single_argument; + ``` + ```text + +-----------------+ + | single_argument | + +-----------------+ + | {"single":"argument"} | + +-----------------+ + ``` + + ```sql + select map_concat({'a': 'apple'}, {'b': 'banana'}, {'c': 'cherry'}) as literal_maps_merged; + ``` + ```text + +-------------------------------+ + | literal_maps_merged | + +-------------------------------+ + | {"a":"apple", "b":"banana", "c":"cherry"} | + +-------------------------------+ + ``` + +2. NULL parameters + ```sql + select map_concat({'a': 'apple'}, NULL) as with_null; + ``` + ```text + +------------+ + | with_null | + +------------+ + | NULL | + +------------+ From 7e70ef44ada446c5d69d9c8e338578ad32b3c525 Mon Sep 17 00:00:00 2001 From: nagisa-kun <1434936049@qq.com> Date: Wed, 24 Dec 2025 22:28:04 +0800 Subject: [PATCH 02/11] feat: map-concat doc --- .../{mapconcat.md => map-concat.md} | 0 .../map-functions/map-concat.md | 79 +++++++++++++++++++ 2 files changed, 79 insertions(+) rename docs/sql-manual/sql-functions/scalar-functions/map-functions/{mapconcat.md => map-concat.md} (100%) create mode 100644 i18n/zh-CN/docusaurus-plugin-content-docs/version-4.x/sql-manual/sql-functions/scalar-functions/map-functions/map-concat.md diff --git a/docs/sql-manual/sql-functions/scalar-functions/map-functions/mapconcat.md b/docs/sql-manual/sql-functions/scalar-functions/map-functions/map-concat.md similarity index 100% rename from docs/sql-manual/sql-functions/scalar-functions/map-functions/mapconcat.md rename to docs/sql-manual/sql-functions/scalar-functions/map-functions/map-concat.md diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/version-4.x/sql-manual/sql-functions/scalar-functions/map-functions/map-concat.md b/i18n/zh-CN/docusaurus-plugin-content-docs/version-4.x/sql-manual/sql-functions/scalar-functions/map-functions/map-concat.md new file mode 100644 index 0000000000000..e235400ff80ce --- /dev/null +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/version-4.x/sql-manual/sql-functions/scalar-functions/map-functions/map-concat.md @@ -0,0 +1,79 @@ +--- +{ + "title": "MAP_CONCAT", + "language": "zh-CN" +} +--- + +## 描述 + +将多个 map 合并为一个 map。 + +## 语法 + +```sql +MAP_CONCAT( [, [, ... ]]) +``` + +## 参数 + +| 参数 | 说明 | +| -- | -- | +| ``, ``, ``, ... | [`MAP`](../../../basic-element/sql-data-types/semi-structured/MAP.md) 类型,需要合并的输入 map | + +## 返回值 + +返回一个合并后的 `MAP`,包含所有输入 map 中的键值对。 + +## 使用说明 + +1. 该函数接受零个或多个 map 参数。 +2. 如果任何参数为 NULL,则结果为 NULL。 + +## 示例 + +1. 基本用法 + ```sql + select map_concat() as empty_map; + ``` + ```text + +-----------+ + | empty_map | + +-----------+ + | {} | + +-----------+ + ``` + + ```sql + select map_concat(map('single', 'argument')) as single_argument; + ``` + ```text + +-----------------+ + | single_argument | + +-----------------+ + | {"single":"argument"} | + +-----------------+ + ``` + + ```sql + select map_concat({'a': 'apple'}, {'b': 'banana'}, {'c': 'cherry'}) as literal_maps_merged; + ``` + ```text + +-------------------------------+ + | literal_maps_merged | + +-------------------------------+ + | {"a":"apple", "b":"banana", "c":"cherry"} | + +-------------------------------+ + ``` + +2. NULL 参数 + ```sql + select map_concat({'a': 'apple'}, NULL) as with_null; + ``` + ```text + +------------+ + | with_null | + +------------+ + | NULL | + +------------+ + ``` From 999d44b7aed40dfc3086e2cff6fdb11e8a836fb9 Mon Sep 17 00:00:00 2001 From: nagisa-kun <1434936049@qq.com> Date: Wed, 24 Dec 2025 22:32:13 +0800 Subject: [PATCH 03/11] feat: sidebar of map-concat --- versioned_sidebars/version-4.x-sidebars.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/versioned_sidebars/version-4.x-sidebars.json b/versioned_sidebars/version-4.x-sidebars.json index 951cb6404bd9a..d538e10e1bc35 100644 --- a/versioned_sidebars/version-4.x-sidebars.json +++ b/versioned_sidebars/version-4.x-sidebars.json @@ -1630,7 +1630,8 @@ "sql-manual/sql-functions/scalar-functions/map-functions/map-keys", "sql-manual/sql-functions/scalar-functions/map-functions/map-size", "sql-manual/sql-functions/scalar-functions/map-functions/map-values", - "sql-manual/sql-functions/scalar-functions/map-functions/str-to-map" + "sql-manual/sql-functions/scalar-functions/map-functions/str-to-map", + "sql-manual/sql-functions/scalar-functions/map-functions/map-concat" ] }, { From 2587fabdde0d67d8432b20d826db630666e5579e Mon Sep 17 00:00:00 2001 From: nagisa-kun <1434936049@qq.com> Date: Tue, 6 Jan 2026 03:06:57 +0800 Subject: [PATCH 04/11] fix: map concat --- .../map-functions/map-concat.md | 142 ++++++++++++++--- .../map-functions/map-concat.md | 147 ++++++++++++++---- 2 files changed, 233 insertions(+), 56 deletions(-) diff --git a/docs/sql-manual/sql-functions/scalar-functions/map-functions/map-concat.md b/docs/sql-manual/sql-functions/scalar-functions/map-functions/map-concat.md index 1888829ba124a..0fd59d5e768c5 100644 --- a/docs/sql-manual/sql-functions/scalar-functions/map-functions/map-concat.md +++ b/docs/sql-manual/sql-functions/scalar-functions/map-functions/map-concat.md @@ -7,7 +7,7 @@ ## Description -Concatenates multiple maps into a single map. +Concatenates multiple maps into a single map. When concatenating maps with different key or value types, the function finds common types for keys and values. ## Syntax @@ -18,55 +18,147 @@ MAP_CONCAT( [, [, ... ]]) ## Parameters - ``, ``, ``, ...: [`MAP`](../../../basic-element/sql-data-types/semi-structured/MAP.md) type, the input maps to concatenate. +**Supported key and value types:** +- **Key types**: All primitive types that support comparison (numeric, string, date/time, boolean, IP) +- **Value types**: All primitive types plus complex types (ARRAY, MAP, STRUCT) + +**Type compatibility notes:** +- When concatenating maps with different key types, the function finds a common key type +- When concatenating maps with different value types, the function finds a common value type + ## Return Value Returns a concatenated `MAP` containing all key-value pairs from the input maps. +**Behavior:** +- The resulting map's key type is the common type of all input map key types +- The resulting map's value type is the common type of all input map value types +- If types cannot be converted (e.g., incompatible key types), an error is thrown + ## Usage Notes 1. The function accepts zero or more map arguments. 2. If any argument is NULL, the result is NULL. +3. Duplicate keys: If multiple maps contain the same key, the value from the last map wins ## Examples 1. Basic usage ```sql - select map_concat() as empty_map; + select map_concat(); ``` ```text - +-----------+ - | empty_map | - +-----------+ - | {} | - +-----------+ + +--------------+ + | map_concat() | + +--------------+ + | {} | + +--------------+ ``` ```sql - select map_concat(map('single', 'argument')) as single_argument; + select map_concat(map('single', 'argument')); ``` ```text - +-----------------+ - | single_argument | - +-----------------+ - | {"single":"argument"} | - +-----------------+ + +---------------------------------------+ + | map_concat(map('single', 'argument')) | + +---------------------------------------+ + | {"single":"argument"} | + +---------------------------------------+ ``` ```sql - select map_concat({'a': 'apple'}, {'b': 'banana'}, {'c': 'cherry'}) as literal_maps_merged; + select map_concat({'a': 'apple'}, {'b': 'banana'}, {'c': 'cherry'}); ``` ```text - +-------------------------------+ - | literal_maps_merged | - +-------------------------------+ - | {"a":"apple", "b":"banana", "c":"cherry"} | - +-------------------------------+ + +-----------------------------------------------------------+ + | map_concat({'a':'apple'},{'b':'banana'},{'c':'cherry'}) | + +-----------------------------------------------------------+ + | {"a":"apple", "b":"banana", "c":"cherry"} | + +-----------------------------------------------------------+ ``` 2. NULL parameters ```sql - select map_concat({'a': 'apple'}, NULL) as with_null; + select map_concat({'a': 'apple'}, NULL); + ``` + ```text + +---------------------------------+ + | map_concat({'a':'apple'}, NULL) | + +---------------------------------+ + | NULL | + +---------------------------------+ + ``` + + Map concatenation containing null elements: null elements will be normally retained in the concatenation result. + +3. Type conversion examples + ```sql + -- INT and DOUBLE value types + select map_concat({'a': 1, 'b': 2}, {'c': 3.5, 'd': 4.7}); ``` ```text - +------------+ - | with_null | - +------------+ - | NULL | - +------------+ + +----------------------------------------------------+ + | map_concat({'a': 1, 'b': 2}, {'c': 3.5, 'd': 4.7}) | + +----------------------------------------------------+ + | {"a":1.0, "b":2.0, "c":3.5, "d":4.7} | + +----------------------------------------------------+ + ``` + INT values are converted to DOUBLE to match the common type. + + ```sql + -- INT and VARCHAR key types + select map_concat({1: 'one', 2: 'two'}, {'a': 'apple', 'b': 'banana'}); + ``` + ```text + +-----------------------------------------------------------------+ + | map_concat({1: 'one', 2: 'two'}, {'a': 'apple', 'b': 'banana'}) | + +-----------------------------------------------------------------+ + | {"1":"one", "2":"two", "a":"apple", "b":"banana"} | + +-----------------------------------------------------------------+ + ``` + INT keys are converted to VARCHAR to match the common type. + + ```sql + -- INT and BIGINT value types + select map_concat({'small': 100}, {'large': 10000000000}); + ``` + ```text + +----------------------------------------------------+ + | map_concat({'small': 100}, {'large': 10000000000}) | + +----------------------------------------------------+ + | {"small":100, "large":10000000000} | + +----------------------------------------------------+ + ``` + INT values are converted to BIGINT to match the common type. + + ```sql + -- INT and VARCHAR value types + select map_concat({'a': 1}, {'b': '2'}); + ``` + ```text + +----------------------------------+ + | map_concat({'a': 1}, {'b': '2'}) | + +----------------------------------+ + | {"a":"1", "b":"2"} | + +----------------------------------+ + ``` + INT values are converted to VARCHAR to match the common type. + + ```sql + -- Complex types with nested arrays + select map_concat({'a':[1,2,3]},{1:['1','2']}); + ``` + ```text + +-----------------------------------------+ + | map_concat({'a':[1,2,3]},{1:['1','2']}) | + +-----------------------------------------+ + | {"a":["1", "2", "3"], "1":["1", "2"]} | + +-----------------------------------------+ + ``` + For complex types (like ARRAY), type conversion is performed recursively. + + ```sql + -- Error example: cannot find common type + select map_concat({'a':[1,2,3]},{1:3}); + ``` + ```text + ERROR 1105 (HY000): errCode = 2, detailMessage = mapconcat cannot find the common value type of map_concat(map('a', [1, 2, 3]), map(1, 3)) + ``` + When a common type cannot be found (e.g., ARRAY and INT), an error is thrown. diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/version-4.x/sql-manual/sql-functions/scalar-functions/map-functions/map-concat.md b/i18n/zh-CN/docusaurus-plugin-content-docs/version-4.x/sql-manual/sql-functions/scalar-functions/map-functions/map-concat.md index e235400ff80ce..fd2ca6eb4fbed 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/version-4.x/sql-manual/sql-functions/scalar-functions/map-functions/map-concat.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/version-4.x/sql-manual/sql-functions/scalar-functions/map-functions/map-concat.md @@ -7,7 +7,7 @@ ## 描述 -将多个 map 合并为一个 map。 +将多个 map 合并为一个 map。当合并具有不同键或值类型的 map 时,该函数会找到键和值的公共类型。 ## 语法 @@ -16,64 +16,149 @@ MAP_CONCAT( [, [, ... ]]) ``` ## 参数 +- ``, ``, ``, ...: [`MAP`](../../../basic-element/sql-data-types/semi-structured/MAP.md) 类型,需要合并的输入 map。 -| 参数 | 说明 | -| -- | -- | -| ``, ``, ``, ... | [`MAP`](../../../basic-element/sql-data-types/semi-structured/MAP.md) 类型,需要合并的输入 map | +**支持的键和值类型:** +- **键类型**:所有支持比较的基本类型(数值、字符串、日期/时间、布尔值、IP) +- **值类型**:所有基本类型加上复杂类型(ARRAY、MAP、STRUCT) -## 返回值 +**类型兼容性说明:** +- 当合并具有不同键类型的 map 时,函数会找到公共键类型 +- 当合并具有不同值类型的 map 时,函数会找到公共值类型 +## 返回值 返回一个合并后的 `MAP`,包含所有输入 map 中的键值对。 -## 使用说明 +**行为:** +- 结果 map 的键类型是所有输入 map 键类型的公共类型 +- 结果 map 的值类型是所有输入 map 值类型的公共类型 +- 如果类型无法转换(例如,不兼容的键类型),则抛出错误 +## 使用说明 1. 该函数接受零个或多个 map 参数。 2. 如果任何参数为 NULL,则结果为 NULL。 +3. 重复键:如果多个 map 包含相同的键,则最后一个 map 的值生效 ## 示例 - 1. 基本用法 ```sql - select map_concat() as empty_map; + select map_concat(); ``` ```text - +-----------+ - | empty_map | - +-----------+ - | {} | - +-----------+ + +--------------+ + | map_concat() | + +--------------+ + | {} | + +--------------+ ``` ```sql - select map_concat(map('single', 'argument')) as single_argument; + select map_concat(map('single', 'argument')); ``` ```text - +-----------------+ - | single_argument | - +-----------------+ - | {"single":"argument"} | - +-----------------+ + +---------------------------------------+ + | map_concat(map('single', 'argument')) | + +---------------------------------------+ + | {"single":"argument"} | + +---------------------------------------+ ``` ```sql - select map_concat({'a': 'apple'}, {'b': 'banana'}, {'c': 'cherry'}) as literal_maps_merged; + select map_concat({'a': 'apple'}, {'b': 'banana'}, {'c': 'cherry'}); ``` ```text - +-------------------------------+ - | literal_maps_merged | - +-------------------------------+ - | {"a":"apple", "b":"banana", "c":"cherry"} | - +-------------------------------+ + +-----------------------------------------------------------+ + | map_concat({'a':'apple'},{'b':'banana'},{'c':'cherry'}) | + +-----------------------------------------------------------+ + | {"a":"apple", "b":"banana", "c":"cherry"} | + +-----------------------------------------------------------+ ``` 2. NULL 参数 ```sql - select map_concat({'a': 'apple'}, NULL) as with_null; + select map_concat({'a': 'apple'}, NULL); + ``` + ```text + +---------------------------------+ + | map_concat({'a':'apple'}, NULL) | + +---------------------------------+ + | NULL | + +---------------------------------+ + ``` + + 包含 null 元素的 map 合并:null 元素通常会在合并结果中保留。 + +3. 类型转换示例 + ```sql + -- INT 和 DOUBLE 值类型 + select map_concat({'a': 1, 'b': 2}, {'c': 3.5, 'd': 4.7}); + ``` + ```text + +----------------------------------------------------+ + | map_concat({'a': 1, 'b': 2}, {'c': 3.5, 'd': 4.7}) | + +----------------------------------------------------+ + | {"a":1.0, "b":2.0, "c":3.5, "d":4.7} | + +----------------------------------------------------+ + ``` + INT 值被转换为 DOUBLE 以匹配公共类型。 + + ```sql + -- INT 和 VARCHAR 键类型 + select map_concat({1: 'one', 2: 'two'}, {'a': 'apple', 'b': 'banana'}); + ``` + ```text + +-----------------------------------------------------------------+ + | map_concat({1: 'one', 2: 'two'}, {'a': 'apple', 'b': 'banana'}) | + +-----------------------------------------------------------------+ + | {"1":"one", "2":"two", "a":"apple", "b":"banana"} | + +-----------------------------------------------------------------+ + ``` + INT 键被转换为 VARCHAR 以匹配公共类型。 + + ```sql + -- INT 和 BIGINT 值类型 + select map_concat({'small': 100}, {'large': 10000000000}); + ``` + ```text + +----------------------------------------------------+ + | map_concat({'small': 100}, {'large': 10000000000}) | + +----------------------------------------------------+ + | {"small":100, "large":10000000000} | + +----------------------------------------------------+ + ``` + INT 值被转换为 BIGINT 以匹配公共类型。 + + ```sql + -- INT 和 VARCHAR 值类型 + select map_concat({'a': 1}, {'b': '2'}); + ``` + ```text + +----------------------------------+ + | map_concat({'a': 1}, {'b': '2'}) | + +----------------------------------+ + | {"a":"1", "b":"2"} | + +----------------------------------+ + ``` + INT 值被转换为 VARCHAR 以匹配公共类型。 + + ```sql + -- 包含嵌套数组的复杂类型 + select map_concat({'a':[1,2,3]},{1:['1','2']}); + ``` + ```text + +-----------------------------------------+ + | map_concat({'a':[1,2,3]},{1:['1','2']}) | + +-----------------------------------------+ + | {"a":["1", "2", "3"], "1":["1", "2"]} | + +-----------------------------------------+ + ``` + 对于复杂类型(如 ARRAY),会递归执行类型转换。 + + ```sql + -- 错误示例:找不到公共类型 + select map_concat({'a':[1,2,3]},{1:3}); ``` ```text - +------------+ - | with_null | - +------------+ - | NULL | - +------------+ + ERROR 1105 (HY000): errCode = 2, detailMessage = mapconcat cannot find the common value type of map_concat(map('a', [1, 2, 3]), map(1, 3)) ``` + 当找不到公共类型时(例如 ARRAY 和 INT),会抛出错误。 From e35ac65b37182d59a6409266571cc6e607164427 Mon Sep 17 00:00:00 2001 From: nagisa-kun <1434936049@qq.com> Date: Fri, 30 Jan 2026 01:26:18 +0800 Subject: [PATCH 05/11] fix: info --- .../scalar-functions/map-functions/map-concat.md | 4 ++++ .../scalar-functions/map-functions/map-concat.md | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/docs/sql-manual/sql-functions/scalar-functions/map-functions/map-concat.md b/docs/sql-manual/sql-functions/scalar-functions/map-functions/map-concat.md index 0fd59d5e768c5..e5c44e93669ec 100644 --- a/docs/sql-manual/sql-functions/scalar-functions/map-functions/map-concat.md +++ b/docs/sql-manual/sql-functions/scalar-functions/map-functions/map-concat.md @@ -9,6 +9,10 @@ Concatenates multiple maps into a single map. When concatenating maps with different key or value types, the function finds common types for keys and values. +:::info Note +Supported since Apache Doris 4.0.4. +::: + ## Syntax ```sql diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/version-4.x/sql-manual/sql-functions/scalar-functions/map-functions/map-concat.md b/i18n/zh-CN/docusaurus-plugin-content-docs/version-4.x/sql-manual/sql-functions/scalar-functions/map-functions/map-concat.md index fd2ca6eb4fbed..4e3bc6209024d 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/version-4.x/sql-manual/sql-functions/scalar-functions/map-functions/map-concat.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/version-4.x/sql-manual/sql-functions/scalar-functions/map-functions/map-concat.md @@ -9,6 +9,10 @@ 将多个 map 合并为一个 map。当合并具有不同键或值类型的 map 时,该函数会找到键和值的公共类型。 +:::info Note +Supported since Apache Doris 4.0.4. +::: + ## 语法 ```sql From a16e18a7f7984b630b20413ebfc50d71183d160b Mon Sep 17 00:00:00 2001 From: nagisa-kun <1434936049@qq.com> Date: Sat, 31 Jan 2026 14:03:08 +0800 Subject: [PATCH 06/11] fix: doc --- .../map-functions/map-concat.md | 168 ++++++++++++++++++ sidebars.ts | 1 + .../map-functions/map-concat.md | 168 ++++++++++++++++++ 3 files changed, 337 insertions(+) create mode 100644 i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/map-functions/map-concat.md create mode 100644 versioned_docs/version-4.x/sql-manual/sql-functions/scalar-functions/map-functions/map-concat.md diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/map-functions/map-concat.md b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/map-functions/map-concat.md new file mode 100644 index 0000000000000..4e3bc6209024d --- /dev/null +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/map-functions/map-concat.md @@ -0,0 +1,168 @@ +--- +{ + "title": "MAP_CONCAT", + "language": "zh-CN" +} +--- + +## 描述 + +将多个 map 合并为一个 map。当合并具有不同键或值类型的 map 时,该函数会找到键和值的公共类型。 + +:::info Note +Supported since Apache Doris 4.0.4. +::: + +## 语法 + +```sql +MAP_CONCAT( [, [, ... ]]) +``` + +## 参数 +- ``, ``, ``, ...: [`MAP`](../../../basic-element/sql-data-types/semi-structured/MAP.md) 类型,需要合并的输入 map。 + +**支持的键和值类型:** +- **键类型**:所有支持比较的基本类型(数值、字符串、日期/时间、布尔值、IP) +- **值类型**:所有基本类型加上复杂类型(ARRAY、MAP、STRUCT) + +**类型兼容性说明:** +- 当合并具有不同键类型的 map 时,函数会找到公共键类型 +- 当合并具有不同值类型的 map 时,函数会找到公共值类型 + +## 返回值 +返回一个合并后的 `MAP`,包含所有输入 map 中的键值对。 + +**行为:** +- 结果 map 的键类型是所有输入 map 键类型的公共类型 +- 结果 map 的值类型是所有输入 map 值类型的公共类型 +- 如果类型无法转换(例如,不兼容的键类型),则抛出错误 + +## 使用说明 +1. 该函数接受零个或多个 map 参数。 +2. 如果任何参数为 NULL,则结果为 NULL。 +3. 重复键:如果多个 map 包含相同的键,则最后一个 map 的值生效 + +## 示例 +1. 基本用法 + ```sql + select map_concat(); + ``` + ```text + +--------------+ + | map_concat() | + +--------------+ + | {} | + +--------------+ + ``` + + ```sql + select map_concat(map('single', 'argument')); + ``` + ```text + +---------------------------------------+ + | map_concat(map('single', 'argument')) | + +---------------------------------------+ + | {"single":"argument"} | + +---------------------------------------+ + ``` + + ```sql + select map_concat({'a': 'apple'}, {'b': 'banana'}, {'c': 'cherry'}); + ``` + ```text + +-----------------------------------------------------------+ + | map_concat({'a':'apple'},{'b':'banana'},{'c':'cherry'}) | + +-----------------------------------------------------------+ + | {"a":"apple", "b":"banana", "c":"cherry"} | + +-----------------------------------------------------------+ + ``` + +2. NULL 参数 + ```sql + select map_concat({'a': 'apple'}, NULL); + ``` + ```text + +---------------------------------+ + | map_concat({'a':'apple'}, NULL) | + +---------------------------------+ + | NULL | + +---------------------------------+ + ``` + + 包含 null 元素的 map 合并:null 元素通常会在合并结果中保留。 + +3. 类型转换示例 + ```sql + -- INT 和 DOUBLE 值类型 + select map_concat({'a': 1, 'b': 2}, {'c': 3.5, 'd': 4.7}); + ``` + ```text + +----------------------------------------------------+ + | map_concat({'a': 1, 'b': 2}, {'c': 3.5, 'd': 4.7}) | + +----------------------------------------------------+ + | {"a":1.0, "b":2.0, "c":3.5, "d":4.7} | + +----------------------------------------------------+ + ``` + INT 值被转换为 DOUBLE 以匹配公共类型。 + + ```sql + -- INT 和 VARCHAR 键类型 + select map_concat({1: 'one', 2: 'two'}, {'a': 'apple', 'b': 'banana'}); + ``` + ```text + +-----------------------------------------------------------------+ + | map_concat({1: 'one', 2: 'two'}, {'a': 'apple', 'b': 'banana'}) | + +-----------------------------------------------------------------+ + | {"1":"one", "2":"two", "a":"apple", "b":"banana"} | + +-----------------------------------------------------------------+ + ``` + INT 键被转换为 VARCHAR 以匹配公共类型。 + + ```sql + -- INT 和 BIGINT 值类型 + select map_concat({'small': 100}, {'large': 10000000000}); + ``` + ```text + +----------------------------------------------------+ + | map_concat({'small': 100}, {'large': 10000000000}) | + +----------------------------------------------------+ + | {"small":100, "large":10000000000} | + +----------------------------------------------------+ + ``` + INT 值被转换为 BIGINT 以匹配公共类型。 + + ```sql + -- INT 和 VARCHAR 值类型 + select map_concat({'a': 1}, {'b': '2'}); + ``` + ```text + +----------------------------------+ + | map_concat({'a': 1}, {'b': '2'}) | + +----------------------------------+ + | {"a":"1", "b":"2"} | + +----------------------------------+ + ``` + INT 值被转换为 VARCHAR 以匹配公共类型。 + + ```sql + -- 包含嵌套数组的复杂类型 + select map_concat({'a':[1,2,3]},{1:['1','2']}); + ``` + ```text + +-----------------------------------------+ + | map_concat({'a':[1,2,3]},{1:['1','2']}) | + +-----------------------------------------+ + | {"a":["1", "2", "3"], "1":["1", "2"]} | + +-----------------------------------------+ + ``` + 对于复杂类型(如 ARRAY),会递归执行类型转换。 + + ```sql + -- 错误示例:找不到公共类型 + select map_concat({'a':[1,2,3]},{1:3}); + ``` + ```text + ERROR 1105 (HY000): errCode = 2, detailMessage = mapconcat cannot find the common value type of map_concat(map('a', [1, 2, 3]), map(1, 3)) + ``` + 当找不到公共类型时(例如 ARRAY 和 INT),会抛出错误。 diff --git a/sidebars.ts b/sidebars.ts index b845e4013c780..c50db9382589d 100644 --- a/sidebars.ts +++ b/sidebars.ts @@ -1613,6 +1613,7 @@ const sidebars: SidebarsConfig = { 'sql-manual/sql-functions/scalar-functions/map-functions/map-size', 'sql-manual/sql-functions/scalar-functions/map-functions/map-values', 'sql-manual/sql-functions/scalar-functions/map-functions/str-to-map', + 'sql-manual/sql-functions/scalar-functions/map-functions/map-concat', ], }, { diff --git a/versioned_docs/version-4.x/sql-manual/sql-functions/scalar-functions/map-functions/map-concat.md b/versioned_docs/version-4.x/sql-manual/sql-functions/scalar-functions/map-functions/map-concat.md new file mode 100644 index 0000000000000..e5c44e93669ec --- /dev/null +++ b/versioned_docs/version-4.x/sql-manual/sql-functions/scalar-functions/map-functions/map-concat.md @@ -0,0 +1,168 @@ +--- +{ + "title": "MAP_CONCAT", + "language": "en" +} +--- + +## Description + +Concatenates multiple maps into a single map. When concatenating maps with different key or value types, the function finds common types for keys and values. + +:::info Note +Supported since Apache Doris 4.0.4. +::: + +## Syntax + +```sql +MAP_CONCAT( [, [, ... ]]) +``` + +## Parameters +- ``, ``, ``, ...: [`MAP`](../../../basic-element/sql-data-types/semi-structured/MAP.md) type, the input maps to concatenate. + +**Supported key and value types:** +- **Key types**: All primitive types that support comparison (numeric, string, date/time, boolean, IP) +- **Value types**: All primitive types plus complex types (ARRAY, MAP, STRUCT) + +**Type compatibility notes:** +- When concatenating maps with different key types, the function finds a common key type +- When concatenating maps with different value types, the function finds a common value type + +## Return Value +Returns a concatenated `MAP` containing all key-value pairs from the input maps. + +**Behavior:** +- The resulting map's key type is the common type of all input map key types +- The resulting map's value type is the common type of all input map value types +- If types cannot be converted (e.g., incompatible key types), an error is thrown + +## Usage Notes +1. The function accepts zero or more map arguments. +2. If any argument is NULL, the result is NULL. +3. Duplicate keys: If multiple maps contain the same key, the value from the last map wins + +## Examples +1. Basic usage + ```sql + select map_concat(); + ``` + ```text + +--------------+ + | map_concat() | + +--------------+ + | {} | + +--------------+ + ``` + + ```sql + select map_concat(map('single', 'argument')); + ``` + ```text + +---------------------------------------+ + | map_concat(map('single', 'argument')) | + +---------------------------------------+ + | {"single":"argument"} | + +---------------------------------------+ + ``` + + ```sql + select map_concat({'a': 'apple'}, {'b': 'banana'}, {'c': 'cherry'}); + ``` + ```text + +-----------------------------------------------------------+ + | map_concat({'a':'apple'},{'b':'banana'},{'c':'cherry'}) | + +-----------------------------------------------------------+ + | {"a":"apple", "b":"banana", "c":"cherry"} | + +-----------------------------------------------------------+ + ``` + +2. NULL parameters + ```sql + select map_concat({'a': 'apple'}, NULL); + ``` + ```text + +---------------------------------+ + | map_concat({'a':'apple'}, NULL) | + +---------------------------------+ + | NULL | + +---------------------------------+ + ``` + + Map concatenation containing null elements: null elements will be normally retained in the concatenation result. + +3. Type conversion examples + ```sql + -- INT and DOUBLE value types + select map_concat({'a': 1, 'b': 2}, {'c': 3.5, 'd': 4.7}); + ``` + ```text + +----------------------------------------------------+ + | map_concat({'a': 1, 'b': 2}, {'c': 3.5, 'd': 4.7}) | + +----------------------------------------------------+ + | {"a":1.0, "b":2.0, "c":3.5, "d":4.7} | + +----------------------------------------------------+ + ``` + INT values are converted to DOUBLE to match the common type. + + ```sql + -- INT and VARCHAR key types + select map_concat({1: 'one', 2: 'two'}, {'a': 'apple', 'b': 'banana'}); + ``` + ```text + +-----------------------------------------------------------------+ + | map_concat({1: 'one', 2: 'two'}, {'a': 'apple', 'b': 'banana'}) | + +-----------------------------------------------------------------+ + | {"1":"one", "2":"two", "a":"apple", "b":"banana"} | + +-----------------------------------------------------------------+ + ``` + INT keys are converted to VARCHAR to match the common type. + + ```sql + -- INT and BIGINT value types + select map_concat({'small': 100}, {'large': 10000000000}); + ``` + ```text + +----------------------------------------------------+ + | map_concat({'small': 100}, {'large': 10000000000}) | + +----------------------------------------------------+ + | {"small":100, "large":10000000000} | + +----------------------------------------------------+ + ``` + INT values are converted to BIGINT to match the common type. + + ```sql + -- INT and VARCHAR value types + select map_concat({'a': 1}, {'b': '2'}); + ``` + ```text + +----------------------------------+ + | map_concat({'a': 1}, {'b': '2'}) | + +----------------------------------+ + | {"a":"1", "b":"2"} | + +----------------------------------+ + ``` + INT values are converted to VARCHAR to match the common type. + + ```sql + -- Complex types with nested arrays + select map_concat({'a':[1,2,3]},{1:['1','2']}); + ``` + ```text + +-----------------------------------------+ + | map_concat({'a':[1,2,3]},{1:['1','2']}) | + +-----------------------------------------+ + | {"a":["1", "2", "3"], "1":["1", "2"]} | + +-----------------------------------------+ + ``` + For complex types (like ARRAY), type conversion is performed recursively. + + ```sql + -- Error example: cannot find common type + select map_concat({'a':[1,2,3]},{1:3}); + ``` + ```text + ERROR 1105 (HY000): errCode = 2, detailMessage = mapconcat cannot find the common value type of map_concat(map('a', [1, 2, 3]), map(1, 3)) + ``` + When a common type cannot be found (e.g., ARRAY and INT), an error is thrown. From f046b3b28d6acec85acc98b53155ae30bd9d711b Mon Sep 17 00:00:00 2001 From: nagisa-kun <1434936049@qq.com> Date: Sat, 31 Jan 2026 18:05:37 +0800 Subject: [PATCH 07/11] fix: doc --- .../scalar-functions/map-functions/map-concat.md | 4 ---- versioned_sidebars/version-4.x-sidebars.json | 4 ++-- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/docs/sql-manual/sql-functions/scalar-functions/map-functions/map-concat.md b/docs/sql-manual/sql-functions/scalar-functions/map-functions/map-concat.md index e5c44e93669ec..0fd59d5e768c5 100644 --- a/docs/sql-manual/sql-functions/scalar-functions/map-functions/map-concat.md +++ b/docs/sql-manual/sql-functions/scalar-functions/map-functions/map-concat.md @@ -9,10 +9,6 @@ Concatenates multiple maps into a single map. When concatenating maps with different key or value types, the function finds common types for keys and values. -:::info Note -Supported since Apache Doris 4.0.4. -::: - ## Syntax ```sql diff --git a/versioned_sidebars/version-4.x-sidebars.json b/versioned_sidebars/version-4.x-sidebars.json index 425825d47636a..cebcfc7b0d8f0 100644 --- a/versioned_sidebars/version-4.x-sidebars.json +++ b/versioned_sidebars/version-4.x-sidebars.json @@ -1624,6 +1624,7 @@ "label": "MAP Functions", "items": [ "sql-manual/sql-functions/scalar-functions/map-functions/map", + "sql-manual/sql-functions/scalar-functions/map-functions/map-concat", "sql-manual/sql-functions/scalar-functions/map-functions/map-contains-entry", "sql-manual/sql-functions/scalar-functions/map-functions/map-contains-key", "sql-manual/sql-functions/scalar-functions/map-functions/map-contains-value", @@ -1631,8 +1632,7 @@ "sql-manual/sql-functions/scalar-functions/map-functions/map-keys", "sql-manual/sql-functions/scalar-functions/map-functions/map-size", "sql-manual/sql-functions/scalar-functions/map-functions/map-values", - "sql-manual/sql-functions/scalar-functions/map-functions/str-to-map", - "sql-manual/sql-functions/scalar-functions/map-functions/map-concat" + "sql-manual/sql-functions/scalar-functions/map-functions/str-to-map" ] }, { From 5a8a51c4ac327cd2758bab53ee79e2ab31149280 Mon Sep 17 00:00:00 2001 From: nagisa-kun <1434936049@qq.com> Date: Fri, 6 Feb 2026 02:17:22 +0800 Subject: [PATCH 08/11] fix: chinese --- .../sql-functions/scalar-functions/map-functions/map-concat.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/version-4.x/sql-manual/sql-functions/scalar-functions/map-functions/map-concat.md b/i18n/zh-CN/docusaurus-plugin-content-docs/version-4.x/sql-manual/sql-functions/scalar-functions/map-functions/map-concat.md index 4e3bc6209024d..609aecfc5c513 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/version-4.x/sql-manual/sql-functions/scalar-functions/map-functions/map-concat.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/version-4.x/sql-manual/sql-functions/scalar-functions/map-functions/map-concat.md @@ -10,7 +10,7 @@ 将多个 map 合并为一个 map。当合并具有不同键或值类型的 map 时,该函数会找到键和值的公共类型。 :::info Note -Supported since Apache Doris 4.0.4. +自 Apache Doris 4.0.4 版本起支持。 ::: ## 语法 From 7a3fcdff93ea1b82733cb7ae52a2b464c4c2833a Mon Sep 17 00:00:00 2001 From: nagisa-kun <1434936049@qq.com> Date: Fri, 6 Feb 2026 02:29:38 +0800 Subject: [PATCH 09/11] fix: doc --- .../scalar-functions/map-functions/map-concat.md | 4 ++-- .../scalar-functions/map-functions/map-concat.md | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/map-functions/map-concat.md b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/map-functions/map-concat.md index 4e3bc6209024d..86652ac2ca584 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/map-functions/map-concat.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/map-functions/map-concat.md @@ -10,7 +10,7 @@ 将多个 map 合并为一个 map。当合并具有不同键或值类型的 map 时,该函数会找到键和值的公共类型。 :::info Note -Supported since Apache Doris 4.0.4. +自 Apache Doris 4.0.4 版本起支持。 ::: ## 语法 @@ -90,7 +90,7 @@ MAP_CONCAT( [, [, ... ]]) +---------------------------------+ ``` - 包含 null 元素的 map 合并:null 元素通常会在合并结果中保留。 + 如果任何参数为 NULL,则结果为 NULL。 3. 类型转换示例 ```sql diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/version-4.x/sql-manual/sql-functions/scalar-functions/map-functions/map-concat.md b/i18n/zh-CN/docusaurus-plugin-content-docs/version-4.x/sql-manual/sql-functions/scalar-functions/map-functions/map-concat.md index 609aecfc5c513..86652ac2ca584 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/version-4.x/sql-manual/sql-functions/scalar-functions/map-functions/map-concat.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/version-4.x/sql-manual/sql-functions/scalar-functions/map-functions/map-concat.md @@ -90,7 +90,7 @@ MAP_CONCAT( [, [, ... ]]) +---------------------------------+ ``` - 包含 null 元素的 map 合并:null 元素通常会在合并结果中保留。 + 如果任何参数为 NULL,则结果为 NULL。 3. 类型转换示例 ```sql From 2c695e62da7b17edce06cf246cd0c490b666647c Mon Sep 17 00:00:00 2001 From: nagisa-kun <1434936049@qq.com> Date: Mon, 9 Feb 2026 03:01:30 +0800 Subject: [PATCH 10/11] fix: doc --- .../sql-functions/scalar-functions/map-functions/map-concat.md | 2 +- .../sql-functions/scalar-functions/map-functions/map-concat.md | 2 +- .../sql-functions/scalar-functions/map-functions/map-concat.md | 2 +- .../sql-functions/scalar-functions/map-functions/map-concat.md | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/sql-manual/sql-functions/scalar-functions/map-functions/map-concat.md b/docs/sql-manual/sql-functions/scalar-functions/map-functions/map-concat.md index 0fd59d5e768c5..6a627d3a5b9ae 100644 --- a/docs/sql-manual/sql-functions/scalar-functions/map-functions/map-concat.md +++ b/docs/sql-manual/sql-functions/scalar-functions/map-functions/map-concat.md @@ -27,7 +27,7 @@ MAP_CONCAT( [, [, ... ]]) - When concatenating maps with different value types, the function finds a common value type ## Return Value -Returns a concatenated `MAP` containing all key-value pairs from the input maps. +Returns a concatenated `MAP` that merges all key-value pairs from the input maps from left to right. For duplicate keys, the value from the last map wins (and the key's position in the result is determined by its last occurrence). **Behavior:** - The resulting map's key type is the common type of all input map key types diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/map-functions/map-concat.md b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/map-functions/map-concat.md index 86652ac2ca584..e61e422ab946c 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/map-functions/map-concat.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/map-functions/map-concat.md @@ -31,7 +31,7 @@ MAP_CONCAT( [, [, ... ]]) - 当合并具有不同值类型的 map 时,函数会找到公共值类型 ## 返回值 -返回一个合并后的 `MAP`,包含所有输入 map 中的键值对。 +返回一个合并后的 `MAP`,按参数从左到右合并所有输入 map 中的键值对;若存在重复键,以最后一个 map 的值为准(该键在结果中的位置以最后一次出现为准)。 **行为:** - 结果 map 的键类型是所有输入 map 键类型的公共类型 diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/version-4.x/sql-manual/sql-functions/scalar-functions/map-functions/map-concat.md b/i18n/zh-CN/docusaurus-plugin-content-docs/version-4.x/sql-manual/sql-functions/scalar-functions/map-functions/map-concat.md index 86652ac2ca584..e61e422ab946c 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/version-4.x/sql-manual/sql-functions/scalar-functions/map-functions/map-concat.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/version-4.x/sql-manual/sql-functions/scalar-functions/map-functions/map-concat.md @@ -31,7 +31,7 @@ MAP_CONCAT( [, [, ... ]]) - 当合并具有不同值类型的 map 时,函数会找到公共值类型 ## 返回值 -返回一个合并后的 `MAP`,包含所有输入 map 中的键值对。 +返回一个合并后的 `MAP`,按参数从左到右合并所有输入 map 中的键值对;若存在重复键,以最后一个 map 的值为准(该键在结果中的位置以最后一次出现为准)。 **行为:** - 结果 map 的键类型是所有输入 map 键类型的公共类型 diff --git a/versioned_docs/version-4.x/sql-manual/sql-functions/scalar-functions/map-functions/map-concat.md b/versioned_docs/version-4.x/sql-manual/sql-functions/scalar-functions/map-functions/map-concat.md index e5c44e93669ec..e1139ffd79882 100644 --- a/versioned_docs/version-4.x/sql-manual/sql-functions/scalar-functions/map-functions/map-concat.md +++ b/versioned_docs/version-4.x/sql-manual/sql-functions/scalar-functions/map-functions/map-concat.md @@ -31,7 +31,7 @@ MAP_CONCAT( [, [, ... ]]) - When concatenating maps with different value types, the function finds a common value type ## Return Value -Returns a concatenated `MAP` containing all key-value pairs from the input maps. +Returns a concatenated `MAP` that merges all key-value pairs from the input maps from left to right. For duplicate keys, the value from the last map wins (and the key's position in the result is determined by its last occurrence). **Behavior:** - The resulting map's key type is the common type of all input map key types From bc11456b9f76605c9578234e374a53ff88105e74 Mon Sep 17 00:00:00 2001 From: nagisa-kun <1434936049@qq.com> Date: Tue, 10 Feb 2026 22:04:59 +0800 Subject: [PATCH 11/11] remove: map-concat of current version --- .../map-functions/map-concat.md | 168 ------------------ 1 file changed, 168 deletions(-) delete mode 100644 i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/map-functions/map-concat.md diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/map-functions/map-concat.md b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/map-functions/map-concat.md deleted file mode 100644 index e61e422ab946c..0000000000000 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/map-functions/map-concat.md +++ /dev/null @@ -1,168 +0,0 @@ ---- -{ - "title": "MAP_CONCAT", - "language": "zh-CN" -} ---- - -## 描述 - -将多个 map 合并为一个 map。当合并具有不同键或值类型的 map 时,该函数会找到键和值的公共类型。 - -:::info Note -自 Apache Doris 4.0.4 版本起支持。 -::: - -## 语法 - -```sql -MAP_CONCAT( [, [, ... ]]) -``` - -## 参数 -- ``, ``, ``, ...: [`MAP`](../../../basic-element/sql-data-types/semi-structured/MAP.md) 类型,需要合并的输入 map。 - -**支持的键和值类型:** -- **键类型**:所有支持比较的基本类型(数值、字符串、日期/时间、布尔值、IP) -- **值类型**:所有基本类型加上复杂类型(ARRAY、MAP、STRUCT) - -**类型兼容性说明:** -- 当合并具有不同键类型的 map 时,函数会找到公共键类型 -- 当合并具有不同值类型的 map 时,函数会找到公共值类型 - -## 返回值 -返回一个合并后的 `MAP`,按参数从左到右合并所有输入 map 中的键值对;若存在重复键,以最后一个 map 的值为准(该键在结果中的位置以最后一次出现为准)。 - -**行为:** -- 结果 map 的键类型是所有输入 map 键类型的公共类型 -- 结果 map 的值类型是所有输入 map 值类型的公共类型 -- 如果类型无法转换(例如,不兼容的键类型),则抛出错误 - -## 使用说明 -1. 该函数接受零个或多个 map 参数。 -2. 如果任何参数为 NULL,则结果为 NULL。 -3. 重复键:如果多个 map 包含相同的键,则最后一个 map 的值生效 - -## 示例 -1. 基本用法 - ```sql - select map_concat(); - ``` - ```text - +--------------+ - | map_concat() | - +--------------+ - | {} | - +--------------+ - ``` - - ```sql - select map_concat(map('single', 'argument')); - ``` - ```text - +---------------------------------------+ - | map_concat(map('single', 'argument')) | - +---------------------------------------+ - | {"single":"argument"} | - +---------------------------------------+ - ``` - - ```sql - select map_concat({'a': 'apple'}, {'b': 'banana'}, {'c': 'cherry'}); - ``` - ```text - +-----------------------------------------------------------+ - | map_concat({'a':'apple'},{'b':'banana'},{'c':'cherry'}) | - +-----------------------------------------------------------+ - | {"a":"apple", "b":"banana", "c":"cherry"} | - +-----------------------------------------------------------+ - ``` - -2. NULL 参数 - ```sql - select map_concat({'a': 'apple'}, NULL); - ``` - ```text - +---------------------------------+ - | map_concat({'a':'apple'}, NULL) | - +---------------------------------+ - | NULL | - +---------------------------------+ - ``` - - 如果任何参数为 NULL,则结果为 NULL。 - -3. 类型转换示例 - ```sql - -- INT 和 DOUBLE 值类型 - select map_concat({'a': 1, 'b': 2}, {'c': 3.5, 'd': 4.7}); - ``` - ```text - +----------------------------------------------------+ - | map_concat({'a': 1, 'b': 2}, {'c': 3.5, 'd': 4.7}) | - +----------------------------------------------------+ - | {"a":1.0, "b":2.0, "c":3.5, "d":4.7} | - +----------------------------------------------------+ - ``` - INT 值被转换为 DOUBLE 以匹配公共类型。 - - ```sql - -- INT 和 VARCHAR 键类型 - select map_concat({1: 'one', 2: 'two'}, {'a': 'apple', 'b': 'banana'}); - ``` - ```text - +-----------------------------------------------------------------+ - | map_concat({1: 'one', 2: 'two'}, {'a': 'apple', 'b': 'banana'}) | - +-----------------------------------------------------------------+ - | {"1":"one", "2":"two", "a":"apple", "b":"banana"} | - +-----------------------------------------------------------------+ - ``` - INT 键被转换为 VARCHAR 以匹配公共类型。 - - ```sql - -- INT 和 BIGINT 值类型 - select map_concat({'small': 100}, {'large': 10000000000}); - ``` - ```text - +----------------------------------------------------+ - | map_concat({'small': 100}, {'large': 10000000000}) | - +----------------------------------------------------+ - | {"small":100, "large":10000000000} | - +----------------------------------------------------+ - ``` - INT 值被转换为 BIGINT 以匹配公共类型。 - - ```sql - -- INT 和 VARCHAR 值类型 - select map_concat({'a': 1}, {'b': '2'}); - ``` - ```text - +----------------------------------+ - | map_concat({'a': 1}, {'b': '2'}) | - +----------------------------------+ - | {"a":"1", "b":"2"} | - +----------------------------------+ - ``` - INT 值被转换为 VARCHAR 以匹配公共类型。 - - ```sql - -- 包含嵌套数组的复杂类型 - select map_concat({'a':[1,2,3]},{1:['1','2']}); - ``` - ```text - +-----------------------------------------+ - | map_concat({'a':[1,2,3]},{1:['1','2']}) | - +-----------------------------------------+ - | {"a":["1", "2", "3"], "1":["1", "2"]} | - +-----------------------------------------+ - ``` - 对于复杂类型(如 ARRAY),会递归执行类型转换。 - - ```sql - -- 错误示例:找不到公共类型 - select map_concat({'a':[1,2,3]},{1:3}); - ``` - ```text - ERROR 1105 (HY000): errCode = 2, detailMessage = mapconcat cannot find the common value type of map_concat(map('a', [1, 2, 3]), map(1, 3)) - ``` - 当找不到公共类型时(例如 ARRAY 和 INT),会抛出错误。