bitmap_count
Returns the number of set bits in the input bitmap.
Syntax
Python
from pyspark.sql import functions as sf
sf.bitmap_count(col)
Parameters
Parameter | Type | Description |
|---|---|---|
|
| The input bitmap. |
Examples
Example 1: Count set bits in a bitmap
Python
from pyspark.sql import functions as sf
df = spark.createDataFrame([("FFFF",)], ["a"])
df.select(sf.bitmap_count(sf.to_binary(df.a, sf.lit("hex")))).show()
Output
+-------------------------------+
|bitmap_count(to_binary(a, hex))|
+-------------------------------+
| 16|
+-------------------------------+