> ## Documentation Index
> Fetch the complete documentation index at: /documents/llms.txt
> Use this file to discover all available pages before exploring further.

# map_from_arrays

> 将两个 Array 数组组合成一个 Map，分别作为 Key 和 Value。

将两个 ARRAY 数组作为 Key 和 Value 组合成一个 MAP 对象。

该命令从 3.0 版本开始支持。

## 语法

```Haskell theme={null}
MAP map_from_arrays(ARRAY keys, ARRAY values)
```

## 参数说明

* `keys`: 用于生成 MAP 中的 Key 值。`keys` 中的元素必须唯一，且不能是 BITMAP、HLL 或 PERCENTILE 类型，也不能包含这些类型。
* `values`: 用于生成 MAP 中的 Value 值.

## 返回值说明

返回一个 MAP 值，Map 中的 Key 为 `keys` 中的元素，Map 中的 Value 为 `values` 中的元素。

返回规则如下：

* `keys` 和 `values` 长度（元素个数）必须相同，否则返回报错。

* 如果 `keys` 或者 `values` 为 NULL, 则返回 NULL。

## 示例

```Plaintext theme={null}
select map_from_arrays([1, 2], ['Star', 'Rocks']);
+--------------------------------------------+
| map_from_arrays([1, 2], ['Star', 'Rocks']) |
+--------------------------------------------+
| {1:"Star",2:"Rocks"}                       |
+--------------------------------------------+
```

```Plaintext theme={null}
select map_from_arrays([1, 2], NULL);
+-------------------------------+
| map_from_arrays([1, 2], NULL) |
+-------------------------------+
| NULL                          |
+-------------------------------+
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.