bitmap_bit_position function

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

Returns the 0-based bit position of a given BIGINT number within a bucket.

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

Syntax

bitmap_bit_position(expr)

Arguments

  • expr: A BIGINT expression.

Returns

A BIGINT between 0 and 32767.

If expr is >0 the result matches: (expr - 1) % 32768. If expr is <= 0 the result matches: abs(expr) % 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