- The amount of raw data is large and directly loading these data into the database for computing will cause tremendous pressure on clusters. The desired solution is generating Bitmap data in Hive and then loading Bitmap into the database.
- Export the Bitmap data generated in the database to Hive for other systems to use.
- v3.1 and later support loading and unloading data of these types: String, Base64, and Binary.
- v2.5 and v3.0 only support loading and unloading of String and Base64 data.
Hive Bitmap UDFs that can be generated
- com.starrocks.hive.udf.UDAFBitmapAgg Combines multiple rows of non-null values in a column into one row of Bitmap values, which is equivalent to the database’ built-in aggregate function bitmap_agg.
- com.starrocks.hive.udf.UDAFBitmapUnion Calculates the union of a set of bitmaps, which is equivalent to the database’ built-in aggregate function bitmap_union.
- com.starrocks.hive.udf.UDFBase64ToBitmap Converts a base64-encoded string into a bitmap, which is equivalent to the database’ built-in function base64_to_bitmap.
- com.starrocks.hive.udf.UDFBitmapAnd Calculates the intersection of two bitmaps, which is equivalent to the database’ built-in function bitmap_and.
- com.starrocks.hive.udf.UDFBitmapCount Counts the number of values in the bitmap, which is equivalent to the database’ built-in function bitmap_count.
- com.starrocks.hive.udf.UDFBitmapFromString Converts a comma-separated string to a bitmap, equivalent to the database’ built-in function bitmap_from_string.
- com.starrocks.hive.udf.UDFBitmapOr Calculates the union of two bitmaps, equivalent to the database’ built-in function bitmap_or.
- com.starrocks.hive.udf.UDFBitmapToBase64 Converts Bitmap to Base64 string, equivalent to the database’ built-in function bitmap_to_base64.
- com.starrocks.hive.udf.UDFBitmapToString Converts a bitmap to a comma-separated string, equivalent to the database’ built-in function bitmap_to_string.
- com.starrocks.hive.udf.UDFBitmapXor Calculates the set of unique elements in two Bitmaps, which is equivalent to the database’ built-in function bitmap_xor.
How to use
-
Compile and generate Hive UDF on the FE.
A JAR package
hive-udf-*.jarwill be generated in thefe/hive-udf/directory. -
Upload the JAR package to HDFS.
-
Load the JAR package to Hive.
-
Load UDF functions.
Usage examples
Generate Bitmap in Hive and load it into the database in Binary format
-
Create a Hive source table.
-
Create a Hive bitmap table.
Hive generates bitmap through UDFBitmapAgg and writes it into the bitmap table.
-
Create a database Bitmap table.
-
Load Bitmap data into the database in different ways.
- Load data via the files function.
- Load data via Hive Catalog.
-
View the results.
Export Bitmap from the database to Hive
-
Create a Bitmap table in the database and write data into this table.
-
Create a Bitmap table in Hive.
-
Export data in different ways.
- Export data via INSERT INTO FILES (Binary format).
- Export data via Hive Catalog (Binary format).
-
View results in Hive.