跳到主要内容
版本: 最新版本-3.5

unnest_bitmap

unnest_bitmap 是一个表函数,它接受一个 bitmap 并将该 bitmap 中的元素转换为表的多个行。

StarRocks 的 Lateral Join 可以与 unnest_bitmap 函数结合使用,以实现常见的列转行逻辑。

此函数可用于替换 unnest(bitmap_to_array(bitmap))。它具有更好的性能,占用更少的内存资源,并且不受数组长度的限制。

此函数从 v3.1 开始支持。

语法

unnest_bitmap(bitmap)

参数

bitmap:要转换的 bitmap。

返回值

返回从 bitmap 转换的多个行。返回值类型为 BIGINT。

示例

c2 是表 t1 中的一个 bitmap 列。

-- Use the bitmap_to_string function to convert values in the c2 column into a string.
mysql> select c1, bitmap_to_string(c2) from t1;
+------+----------------------+
| c1 | bitmap_to_string(c2) |
+------+----------------------+
| 1 | 1,2,3,4,5,6,7,8,9,10 |
+------+----------------------+

-- Use the unnest_bitmap function to expand the bitmap column into multiple rows.
mysql> select c1, unnest_bitmap from t1, unnest_bitmap(c2);
+------+---------------+
| c1 | unnest_bitmap |
+------+---------------+
| 1 | 1 |
| 1 | 2 |
| 1 | 3 |
| 1 | 4 |
| 1 | 5 |
| 1 | 6 |
| 1 | 7 |
| 1 | 8 |
| 1 | 9 |
| 1 | 10 |
+------+---------------+