Hive Bitmap UDF
Hive Bitmap UDF 提供了可以直接在 Hive 里使用的 UDF,可用于生成 Bitmap 和执行 Bitmap 运算。
UDF 定义的 Bitmap 格式与 StarRocks 里格式一致,可直接用于导入导出。
适用场景:
- 原始数据量比较大,直接导入 StarRocks 计算会对 StarRocks 集群产生较大压力。所以希望在 Hive 里计算完生成 Bitmap 后,再导入 StarRocks。
- 将 StarRocks 里生成的 Bitmap,导出到 Hive,方便其它系统使用。
导入导出格式:
- 3.1 及以上版本支持 String,Base64,和 Binary 三种格式导入导出。
- 2.5 和 3.0 版本只支持 String 和 Base64 两种格式导入导出。
支持生成的 Hive Bitmap UDF 函数
-
com.starrocks.hive.udf.UDAFBitmapAgg
将一列中的多行非 NULL 数值合并成一行 BITMAP 值,等同于 StarRocks 的内置聚合函数 bitmap_agg。
-
com.starrocks.hive.udf.UDAFBitmapUnion
输入一组 Bitmap 值,求这一组 Bitmap 值的并集,等同于 StarRocks 的内置聚合函数 bitmap_union。
-
com.starrocks.hive.udf.UDFBase64ToBitmap
将 Base64 编码的字符串转化为 Bitmap,等同于 StarRocks 的内置函数 base64_to_bitmap。
-
com.starrocks.hive.udf.UDFBitmapAnd
计算两个 Bitmap 的交集,等同于 StarRocks 的内置函数 bitmap_and。
-
com.starrocks.hive.udf.UDFBitmapCount
统计 Bitmap 中值的个数,等同于 StarRocks 的内置函数 bitmap_count。
-
com.starrocks.hive.udf.UDFBitmapFromString
将一个逗号分隔的字符串转化为一个 Bitmap,等同于 StarRocks 的内置函数 bitmap_from_string。
-
com.starrocks.hive.udf.UDFBitmapOr
计算两个 Bitmap 的并集,等同于 StarRocks 的内置函数 bitmap_or。
-
com.starrocks.hive.udf.UDFBitmapToBase64
将 Bitmap 转换为 Base64 字符串,等同于 StarRocks 的内置函数 bitmap_to_base64。
-
com.starrocks.hive.udf.UDFBitmapToString
将 Bitmap 转换为逗号分隔的字符串,等同于 StarRocks 的内置函数 bitmap_to_string。
-
com.starrocks.hive.udf.UDFBitmapXor
计算两个 Bitmap 中不重复元素所构成的集合,等同于 StarRocks 的内置函数 bitmap_xor。
使用方法
-
在 FE 上编译生成 Hive UDF。
./build.sh --hive-udf
会在
fe/hive-udf/
目录下生成一个 JAR 包hive-udf-1.0.0.jar
。 -
将 JAR 包上传到 HDFS。
hadoop fs -put -f ./hive-udf-1.0.0.jar hdfs://<hdfs_ip>:<hdfs_port>/hive-udf-1.0.0.jar
-
Hive 里加载 JAR 包。
hive> add jar hdfs://<hdfs_ip>:<hdfs_port>/hive-udf-1.0.0.jar;
-
加载 UDF 函数。
hive> create temporary function bitmap_agg as 'com.starrocks.hive.udf.UDAFBitmapAgg';
hive> create temporary function bitmap_union as 'com.starrocks.hive.udf.UDAFBitmapUnion';
hive> create temporary function base64_to_bitmap as 'com.starrocks.hive.udf.UDFBase64ToBitmap';
hive> create temporary function bitmap_and as 'com.starrocks.hive.udf.UDFBitmapAnd';
hive> create temporary function bitmap_count as 'com.starrocks.hive.udf.UDFBitmapCount';
hive> create temporary function bitmap_from_string as 'com.starrocks.hive.udf.UDFBitmapFromString';
hive> create temporary function bitmap_or as 'com.starrocks.hive.udf.UDFBitmapOr';
hive> create temporary function bitmap_to_base64 as 'com.starrocks.hive.udf.UDFBitmapToBase64';
hive> create temporary function bitmap_to_string as 'com.starrocks.hive.udf.UDFBitmapToString';
hive> create temporary function bitmap_xor as 'com.starrocks.hive.udf.UDFBitmapXor';