Skip to main content
Hive Bitmap UDF provides UDFs that can be directly used in Hive. They can be used to generate Bitmap data and perform Bitmap-related calculations. The Bitmap format defined by Hive Bitmap UDF is consistent with the format in the database and can be directly used for loading Bitmap data into the database and unloading Bitmap data from the database to Hive. Applicable scenarios:
  • 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.
Supported source and target data types:
  • 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

  1. Compile and generate Hive UDF on the FE.
    A JAR package hive-udf-*.jar will be generated in the fe/hive-udf/ directory.
  2. Upload the JAR package to HDFS.
  3. Load the JAR package to Hive.
  4. Load UDF functions.

Usage examples

Generate Bitmap in Hive and load it into the database in Binary format

  1. Create a Hive source table.
  2. Create a Hive bitmap table.
    Hive generates bitmap through UDFBitmapAgg and writes it into the bitmap table.
  3. Create a database Bitmap table.
  4. Load Bitmap data into the database in different ways.
    • Load data via the files function.
  5. View the results.

Export Bitmap from the database to Hive

  1. Create a Bitmap table in the database and write data into this table.
  2. Create a Bitmap table in Hive.
  3. Export data in different ways.
    • Export data via INSERT INTO FILES (Binary format).
  4. View results in Hive.