Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1251,6 +1251,30 @@ object functions {
*/
def bool_or(e: Column): Column = Column.fn("bool_or", e)

/**
* Aggregate function: returns the bitwise AND of all non-null input values, or null if none.
*
* @group agg_funcs
* @since 3.5.0
*/
def bit_and(e: Column): Column = Column.fn("bit_and", e)

/**
* Aggregate function: returns the bitwise OR of all non-null input values, or null if none.
*
* @group agg_funcs
* @since 3.5.0
*/
def bit_or(e: Column): Column = Column.fn("bit_or", e)

/**
* Aggregate function: returns the bitwise XOR of all non-null input values, or null if none.
*
* @group agg_funcs
* @since 3.5.0
*/
def bit_xor(e: Column): Column = Column.fn("bit_xor", e)

//////////////////////////////////////////////////////////////////////////////////////////////
// Window functions
//////////////////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -1851,6 +1875,33 @@ object functions {
*/
def bitwise_not(e: Column): Column = Column.fn("~", e)

/**
* Returns the number of bits that are set in the argument expr as an unsigned 64-bit integer,
* or NULL if the argument is NULL.
*
* @group bitwise_funcs
* @since 3.5.0
*/
def bit_count(e: Column): Column = Column.fn("bit_count", e)

/**
* 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.
*
* @group bitwise_funcs
* @since 3.5.0
*/
def bit_get(e: Column, pos: Column): Column = Column.fn("bit_get", e, pos)

/**
* 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.
*
* @group bitwise_funcs
* @since 3.5.0
*/
def getbit(e: Column, pos: Column): Column = Column.fn("getbit", e, pos)

/**
* Parses the expression string into the column that it represents, similar to
* [[Dataset#selectExpr]].
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1009,6 +1009,18 @@ class PlanGenerationTestSuite
fn.histogram_numeric(fn.col("a"), lit(10))
}

functionTest("bit_and") {
fn.bit_and(fn.col("a"))
}

functionTest("bit_or") {
fn.bit_or(fn.col("a"))
}

functionTest("bit_xor") {
fn.bit_xor(fn.col("a"))
}

functionTest("mode") {
fn.mode(fn.col("a"))
}
Expand Down Expand Up @@ -1209,6 +1221,18 @@ class PlanGenerationTestSuite
fn.bitwise_not(fn.col("a"))
}

functionTest("bit_count") {
fn.bit_count(fn.col("a"))
}

functionTest("bit_get") {
fn.bit_get(fn.col("a"), lit(0))
}

functionTest("getbit") {
fn.getbit(fn.col("a"), lit(0))
}

functionTest("expr") {
fn.expr("a + 1")
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Aggregate [bit_and(a#0) AS bit_and(a)#0]
+- LocalRelation <empty>, [id#0L, a#0, b#0, d#0, e#0, f#0, g#0]
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Project [bit_count(a#0) AS bit_count(a)#0]
+- LocalRelation <empty>, [id#0L, a#0, b#0, d#0, e#0, f#0, g#0]
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Project [bit_get(a#0, 0) AS bit_get(a, 0)#0]
+- LocalRelation <empty>, [id#0L, a#0, b#0, d#0, e#0, f#0, g#0]
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Aggregate [bit_or(a#0) AS bit_or(a)#0]
+- LocalRelation <empty>, [id#0L, a#0, b#0, d#0, e#0, f#0, g#0]
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Aggregate [bit_xor(a#0) AS bit_xor(a)#0]
+- LocalRelation <empty>, [id#0L, a#0, b#0, d#0, e#0, f#0, g#0]
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Project [getbit(a#0, 0) AS getbit(a, 0)#0]
+- LocalRelation <empty>, [id#0L, a#0, b#0, d#0, e#0, f#0, g#0]
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"common": {
"planId": "1"
},
"project": {
"input": {
"common": {
"planId": "0"
},
"localRelation": {
"schema": "struct\u003cid:bigint,a:int,b:double,d:struct\u003cid:bigint,a:int,b:double\u003e,e:array\u003cint\u003e,f:map\u003cstring,struct\u003cid:bigint,a:int,b:double\u003e\u003e,g:string\u003e"
}
},
"expressions": [{
"unresolvedFunction": {
"functionName": "bit_and",
"arguments": [{
"unresolvedAttribute": {
"unparsedIdentifier": "a"
}
}]
}
}]
}
}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"common": {
"planId": "1"
},
"project": {
"input": {
"common": {
"planId": "0"
},
"localRelation": {
"schema": "struct\u003cid:bigint,a:int,b:double,d:struct\u003cid:bigint,a:int,b:double\u003e,e:array\u003cint\u003e,f:map\u003cstring,struct\u003cid:bigint,a:int,b:double\u003e\u003e,g:string\u003e"
}
},
"expressions": [{
"unresolvedFunction": {
"functionName": "bit_count",
"arguments": [{
"unresolvedAttribute": {
"unparsedIdentifier": "a"
}
}]
}
}]
}
}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"common": {
"planId": "1"
},
"project": {
"input": {
"common": {
"planId": "0"
},
"localRelation": {
"schema": "struct\u003cid:bigint,a:int,b:double,d:struct\u003cid:bigint,a:int,b:double\u003e,e:array\u003cint\u003e,f:map\u003cstring,struct\u003cid:bigint,a:int,b:double\u003e\u003e,g:string\u003e"
}
},
"expressions": [{
"unresolvedFunction": {
"functionName": "bit_get",
"arguments": [{
"unresolvedAttribute": {
"unparsedIdentifier": "a"
}
}, {
"literal": {
"integer": 0
}
}]
}
}]
}
}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"common": {
"planId": "1"
},
"project": {
"input": {
"common": {
"planId": "0"
},
"localRelation": {
"schema": "struct\u003cid:bigint,a:int,b:double,d:struct\u003cid:bigint,a:int,b:double\u003e,e:array\u003cint\u003e,f:map\u003cstring,struct\u003cid:bigint,a:int,b:double\u003e\u003e,g:string\u003e"
}
},
"expressions": [{
"unresolvedFunction": {
"functionName": "bit_or",
"arguments": [{
"unresolvedAttribute": {
"unparsedIdentifier": "a"
}
}]
}
}]
}
}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"common": {
"planId": "1"
},
"project": {
"input": {
"common": {
"planId": "0"
},
"localRelation": {
"schema": "struct\u003cid:bigint,a:int,b:double,d:struct\u003cid:bigint,a:int,b:double\u003e,e:array\u003cint\u003e,f:map\u003cstring,struct\u003cid:bigint,a:int,b:double\u003e\u003e,g:string\u003e"
}
},
"expressions": [{
"unresolvedFunction": {
"functionName": "bit_xor",
"arguments": [{
"unresolvedAttribute": {
"unparsedIdentifier": "a"
}
}]
}
}]
}
}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"common": {
"planId": "1"
},
"project": {
"input": {
"common": {
"planId": "0"
},
"localRelation": {
"schema": "struct\u003cid:bigint,a:int,b:double,d:struct\u003cid:bigint,a:int,b:double\u003e,e:array\u003cint\u003e,f:map\u003cstring,struct\u003cid:bigint,a:int,b:double\u003e\u003e,g:string\u003e"
}
},
"expressions": [{
"unresolvedFunction": {
"functionName": "getbit",
"arguments": [{
"unresolvedAttribute": {
"unparsedIdentifier": "a"
}
}, {
"literal": {
"integer": 0
}
}]
}
}]
}
}
Binary file not shown.
13 changes: 13 additions & 0 deletions python/docs/source/reference/pyspark.sql/functions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,9 @@ Aggregate Functions
approx_count_distinct
approx_percentile
avg
bit_and
bit_or
bit_xor
bool_and
bool_or
collect_list
Expand Down Expand Up @@ -392,6 +395,16 @@ String Functions
upper


Bitwise Functions
-----------------
.. autosummary::
:toctree: api/

bit_count
bit_get
getbit


UDF
---
.. autosummary::
Expand Down
42 changes: 42 additions & 0 deletions python/pyspark/sql/connect/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,27 @@ def bitwise_not(col: "ColumnOrName") -> Column:
bitwise_not.__doc__ = pysparkfuncs.bitwise_not.__doc__


def bit_count(col: "ColumnOrName") -> Column:
return _invoke_function_over_columns("bit_count", col)


bit_count.__doc__ = pysparkfuncs.bit_count.__doc__


def bit_get(col: "ColumnOrName", pos: "ColumnOrName") -> Column:
return _invoke_function_over_columns("bit_get", col, pos)


bit_get.__doc__ = pysparkfuncs.bit_get.__doc__


def getbit(col: "ColumnOrName", pos: "ColumnOrName") -> Column:
return _invoke_function_over_columns("getbit", col, pos)


getbit.__doc__ = pysparkfuncs.getbit.__doc__


def broadcast(df: "DataFrame") -> "DataFrame":
from pyspark.sql.connect.dataframe import DataFrame

Expand Down Expand Up @@ -1270,6 +1291,27 @@ def bool_or(col: "ColumnOrName") -> Column:
bool_or.__doc__ = pysparkfuncs.bool_or.__doc__


def bit_and(col: "ColumnOrName") -> Column:
return _invoke_function_over_columns("bit_and", col)


bit_and.__doc__ = pysparkfuncs.bit_and.__doc__


def bit_or(col: "ColumnOrName") -> Column:
return _invoke_function_over_columns("bit_or", col)


bit_or.__doc__ = pysparkfuncs.bit_or.__doc__


def bit_xor(col: "ColumnOrName") -> Column:
return _invoke_function_over_columns("bit_xor", col)


bit_xor.__doc__ = pysparkfuncs.bit_xor.__doc__


# Window Functions


Expand Down
Loading