pyspark.sql.functions.getbit#

pyspark.sql.functions.getbit(col, pos)[source]#

Returns the value of the bit (0 or 1) at the specified position. The positions are numbered from right to left, starting at zero. The position argument cannot be negative.

New in version 3.5.0.

Parameters
colColumn or str

target column to compute on.

posColumn or str

The positions are numbered from right to left, starting at zero.

Returns
Column

the value of the bit (0 or 1) at the specified position.

Examples

>>> import pyspark.sql.functions as sf
>>> spark.createDataFrame(
...     [[1], [1], [2]], ["c"]
... ).select(sf.getbit("c", sf.lit(1))).show()
+------------+
|getbit(c, 1)|
+------------+
|           0|
|           0|
|           1|
+------------+