pyspark.sql.functions.bit_xor#

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

Aggregate function: returns the bitwise XOR 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 XOR of all non-null input values, or null if none.

Examples

Example 1: Bitwise XOR with all non-null values

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

Example 2: Bitwise XOR with some null values

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

Example 3: Bitwise XOR 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_xor("c")).show()
+----------+
|bit_xor(c)|
+----------+
|      NULL|
+----------+

Example 4: Bitwise XOR with single input value

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