Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
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
from pyspark.databricks.sql import functions as dbf
dbf.getbit(col=<col>, pos=<pos>)
Parameters
| Parameter | Type | Description |
|---|---|---|
col |
pyspark.sql.Column or str |
target column to compute on. |
pos |
pyspark.sql.Column or str |
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
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()