Kopīgot, izmantojot


bit_get

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 bit_get function.

Syntax

from pyspark.databricks.sql import functions as dbf

dbf.bit_get(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
df = spark.createDataFrame([[1],[2],[3],[None]], ["value"])
df.select("*", dbf.bit_get("value", dbf.lit(1))).show()
df = spark.createDataFrame([[1,2],[2,1],[3,None],[None,1]], ["value", "pos"])
df.select("*", dbf.bit_get(df.value, "pos")).show()