getbit
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.
For the corresponding Databricks SQL function, see getbit function.
Syntax
Python
from pyspark.databricks.sql import functions as dbf
dbf.getbit(col=<col>, pos=<pos>)
Parameters
Parameter | Type | Description |
|---|---|---|
|
| target column to compute on. |
|
| The positions are numbered from right to left, starting at zero. |
Returns
pyspark.sql.Column: the value of the bit (0 or 1) at the specified position.
Examples
Python
from pyspark.databricks.sql import functions as dbf
spark.createDataFrame(
[[1], [2], [3], [None]], ["value"]
).select("*", dbf.getbit("value", dbf.lit(1))).show()
df = spark.createDataFrame([[1,2],[2,1],[3,None],[None,1]], ["value", "pos"])
df.select("*", dbf.getbit(df.value, "pos")).show()