bitmap_count 函数

适用于:check marked yesDatabricks SQL check marked yes Databricks Runtime 13.3 及更高版本

返回在表示位图的 BINARY 字符串中设置的位数。 此函数通常与 bitmap_bucket_number()bitmap_construct_agg() 函数一起用于对非重复值计数。

若要对 BIGINT 表达式中的位进行计数,请使用 bit_count 函数

语法

bitmap_count(expr)

参数

返回

属于 >=0BIGINT

示例

> SELECT bitmap_count(X'00');
 0

> SELECT bitmap_count(X'');
 0

> SELECT bitmap_count(X'7700CC');
 10

-- Count the number of distinct values
> SELECT sum(num_distinct) AS num_distinct
    FROM (SELECT bitmap_bucket_number(val),
                 bitmap_count(bitmap_construct_agg(bitmap_bit_position(val)))
            FROM VALUES(1), (2), (1), (-1), (5), (0), (5) AS t(val)
            GROUP BY ALL) AS distinct_vals_by_bucket(bucket, num_distinct)
  5