bitmap_bucket_number function

Applies to: check marked yes Databricks SQL check marked yes Databricks Runtime 13.3 LTS and above

Returns the bitmap bucket number for a given BIGINT number.

This function is used in combination with the bitmap_count() function to count distinct integral numbers.

In combination with the bitmap_bit_position() function it uniquely identifies any BIGINT number.

Syntax

bitmap_bucket_number(expr)

Arguments

  • expr: A BIGINT expression.

Returns

A BIGINT.

If expr is >0 the result matches: ((expr - 1) DIV 32768) + 1. If expr is <= 0 the result matches: expr DIV 32768.

Examples

> SELECT bitmap_bucket_number(1), bitmap_bit_position(1);
 1  0

> SELECT bitmap_bucket_number(32768), bitmap_bit_position(32768);
 1  32767

> SELECT bitmap_bucket_number(32769), bitmap_bit_position(32769);
 2  0

> SELECT bitmap_bucket_number(0), bitmap_bit_position(0);
 0  0

> SELECT bitmap_bucket_number(-32767), bitmap_bit_position(-32767);
 0  32767

> SELECT bitmap_bucket_number(-32768), bitmap_bit_position(-32768);
 -1  0