bit_and
Returns the bitwise AND of all non-null input values, or null if none.
Syntax
Python
from pyspark.sql import functions as sf
sf.bit_and(col)
Parameters
Parameter | Type | Description |
|---|---|---|
|
| Target column to compute on. |
Returns
pyspark.sql.Column: the bitwise AND of all non-null input values, or null if none.
Examples
Example 1: Bitwise AND with all non-null values
Python
from pyspark.sql import functions as sf
df = spark.createDataFrame([[1],[1],[2]], ["c"])
df.select(sf.bit_and("c")).show()
Output
+----------+
|bit_and(c)|
+----------+
| 0|
+----------+
Example 2: Bitwise AND with null values
Python
from pyspark.sql import functions as sf
df = spark.createDataFrame([[1],[None],[2]], ["c"])
df.select(sf.bit_and("c")).show()
Output
+----------+
|bit_and(c)|
+----------+
| 0|
+----------+
Example 3: Bitwise AND with all null values
Python
from pyspark.sql import functions as sf
from pyspark.sql.types import IntegerType, StructType, StructField
schema = StructType([StructField("c", IntegerType(), True)])
df = spark.createDataFrame([[None],[None],[None]], schema=schema)
df.select(sf.bit_and("c")).show()
Output
+----------+
|bit_and(c)|
+----------+
| NULL|
+----------+
Example 4: Bitwise AND with single input value
Python
from pyspark.sql import functions as sf
df = spark.createDataFrame([[5]], ["c"])
df.select(sf.bit_and("c")).show()
Output
+----------+
|bit_and(c)|
+----------+
| 5|
+----------+