pyspark.sql.functions.bit_or#

pyspark.sql.functions.bit_or(col)[source]#

Aggregate function: returns the bitwise OR of all non-null input values, or null if none.

New in version 3.5.0.

Parameters
colColumn or str

target column to compute on.

Returns
Column

the bitwise OR of all non-null input values, or null if none.

Examples

Example 1: Bitwise OR with all non-null values

>>> from pyspark.sql import functions as sf
>>> df = spark.createDataFrame([[1],[1],[2]], ["c"])
>>> df.select(sf.bit_or("c")).show()
+---------+
|bit_or(c)|
+---------+
|        3|
+---------+

Example 2: Bitwise OR with some null values

>>> from pyspark.sql import functions as sf
>>> df = spark.createDataFrame([[1],[None],[2]], ["c"])
>>> df.select(sf.bit_or("c")).show()
+---------+
|bit_or(c)|
+---------+
|        3|
+---------+

Example 3: Bitwise OR with all null values

>>> 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_or("c")).show()
+---------+
|bit_or(c)|
+---------+
|     NULL|
+---------+

Example 4: Bitwise OR with single input value

>>> from pyspark.sql import functions as sf
>>> df = spark.createDataFrame([[5]], ["c"])
>>> df.select(sf.bit_or("c")).show()
+---------+
|bit_or(c)|
+---------+
|        5|
+---------+