Skip to main content
Here is a simple example to illustrate the usage of several aggregate functions in Bitmap. For detailed function definitions or more Bitmap functions, see bitmap-functions.

Create table

The aggregation model is needed when creating table. The data type is bitmap and the aggregation function is bitmap_union.
Note: With an amount of data, you’d better create a rollup table corresponding to high-frequent bitmap_union.

Data Load

TO_BITMAP (expr): Convert 0 ~ 18446744073709551615 unsigned bigint to bitmap BITMAP_EMPTY (): Generate empty bitmap columns, used for the default value to be filled in when inserting or inputting BITMAP_HASH (expr): Convert columns of any type to a bitmap by 32-bit hashing BITMAP_HASH64 (expr): Convert columns of any type to a bitmap by 64-bit hashing

Stream Load

When inputting data using Stream Load, you can convert the data to a BItmap field as follows:

Insert Into

When inputting data using Insert Into, you need to select the corresponding mode based on the type of columns in the source table.
  • id2’s column type in source table is bitmap
  • id2’s column type in target table is bitmap
  • id2’s column type in source table is bitmap, and is the result of aggregation using bit_map_union().
  • id2’s column type in source table is INT, and the bitmap type is generated by to_bitmap().
  • id2’s column type in source table is STRING, and the bitmap type is generated by bitmap_hash().
  • id2’s column type in source table is STRING, and the bitmap type is generated by bitmap_hash64().

Data Query

Syntax

“BITMAP_UNION (expr)`: Calculate the union of the input Bitmaps, and returns the new Bitmap. BITMAP_UNION_COUNT (expr): Calculate the union of the input Bitmaps, and returns its cardinality, equivalent to BITMAP_COUNT (BITMAP_UNION (expr)). It is recommended to use the BITMAP_UNION_COUNT function first, for its performance is better than BITMAP_COUNT (BITMAP_UNION (expr)). BITMAP_UNION_INT (expr): Calculate the number of different values in columns of type TINYINT, SMALLINT and INT, return the value same as COUNT (DISTINCT expr). INTERSECT_COUNT (bitmap_column_to_count, filter_column, filter_values ...): Calculate the cardinality of the intersection of multiple bitmaps that satisfy filter_column condition. bitmap_column_to_count is a column of type bitmap, filter_column is a column of varying dimensions, and filter_values is a list of dimension values. BITMAP_INTERSECT(expr): Calculate the intersection of this group of bitmap values and returns a new bitmap.

Example

The following SQL uses the pv_bitmap table above as an example: Calculate the deduplicated value for user_id:
Calculate the deduplicated value of id:
Calculate the retention of user_id:

keyword

BITMAP,BITMAP_COUNT,BITMAP_EMPTY,BITMAP_UNION,BITMAP_UNION_INT,TO_BITMAP,BITMAP_UNION_COUNT,INTERSECT_COUNT,BITMAP_INTERSECT