BITMAP

description

Syntax

TO_BITMAP(expr) : Convert TINYINT,SMALLINT,INT type column to Bitmap.

BITMAP_UNION(expr) : Calculate the union of Bitmap, return the serialized Bitmap value.

BITMAP_COUNT(expr) : Calculate the distinct value number of a Bitmap.

BITMAP_UNION_INT(expr) : Calculate the distinct value number of TINYINT,SMALLINT and INT type column. Same as COUNT(DISTINCT expr)

Notice:

  1. 1. TO_BITMAP function only receives TINYINT,SMALLINT,INT.
  2. 2. BITMAP_UNION only receives following types of parameter:
  3. - Column with BITMAP_UNION aggregate type in AGGREGATE KEY mode.
  4. - TO_BITMAP function.

example

  1. CREATE TABLE `bitmap_udaf` (
  2. `id` int(11) NULL COMMENT "",
  3. `id2` int(11)
  4. ) ENGINE=OLAP
  5. DUPLICATE KEY(`id`)
  6. DISTRIBUTED BY HASH(`id`) BUCKETS 10;
  7. mysql> select bitmap_count(bitmap_union(to_bitmap(id2))) from bitmap_udaf;
  8. +----------------------------------------------+
  9. | bitmap_count(bitmap_union(to_bitmap(`id2`))) |
  10. +----------------------------------------------+
  11. | 6 |
  12. +----------------------------------------------+
  13. mysql> select bitmap_union_int (id2) from bitmap_udaf;
  14. +-------------------------+
  15. | bitmap_union_int(`id2`) |
  16. +-------------------------+
  17. | 6 |
  18. +-------------------------+
  19. CREATE TABLE `bitmap_test` (
  20. `id` int(11) NULL COMMENT "",
  21. `id2` varchar(0) bitmap_union NULL // NOTICE: bitmap_union's varchar length must be 0.
  22. ) ENGINE=OLAP
  23. AGGREGATE KEY(`id`)
  24. DISTRIBUTED BY HASH(`id`) BUCKETS 10;
  25. mysql> select bitmap_count(bitmap_union(id2)) from bitmap_test;
  26. +-----------------------------------+
  27. | bitmap_count(bitmap_union(`id2`)) |
  28. +-----------------------------------+
  29. | 8 |
  30. +-----------------------------------+

keyword

  1. BITMAP,BITMAP_COUNT,BITMAP_UNION,BITMAP_UNION_INT,TO_BITMAP