---
title: bitmap_bucket_number function
description: Learn the syntax of the bitmap\_bucket\_number function of the SQL language in Databricks SQL and Databricks Runtime.
canonical_url: https://docs.databricks.com/aws/en/sql/language-manual/functions/bitmap_bucket_number
---

# `bitmap_bucket_number` function

**Applies to:** ![check marked yes](https://docs.databricks.com/aws/en/images/icons/check.png) Databricks SQL ![check marked yes](https://docs.databricks.com/aws/en/images/icons/check.png) 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()](https://docs.databricks.com/aws/en/sql/language-manual/functions/bitmap_count.md) function to count distinct integral numbers.

In combination with the [bitmap\_bit\_position()](https://docs.databricks.com/aws/en/sql/language-manual/functions/bitmap_bit_position.md) 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

```sql
> 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
```

## Related functions

* [`bitmap_bit_position` function](https://docs.databricks.com/aws/en/sql/language-manual/functions/bitmap_bit_position.md)
* [`bitmap_construct_agg` aggregate function](https://docs.databricks.com/aws/en/sql/language-manual/functions/bitmap_construct_agg.md)
* [`bitmap_count` function](https://docs.databricks.com/aws/en/sql/language-manual/functions/bitmap_count.md)
* [`bitmap_or_agg` aggregate function](https://docs.databricks.com/aws/en/sql/language-manual/functions/bitmap_or_agg.md)
