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
16 changes: 12 additions & 4 deletions python/pyspark/sql/classic/column.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,25 +309,33 @@ def eqNullSafe(
def __and__(
self, other: Union[ParentColumn, "LiteralType", "DecimalLiteral", "DateTimeLiteral"]
) -> ParentColumn:
return _bin_op("and", self, other)
from pyspark.sql.functions import lit

return _bin_op("and", self, lit(other))

def __or__(
self, other: Union[ParentColumn, "LiteralType", "DecimalLiteral", "DateTimeLiteral"]
) -> ParentColumn:
return _bin_op("or", self, other)
from pyspark.sql.functions import lit

return _bin_op("or", self, lit(other))

def __invert__(self) -> ParentColumn:
return _func_op("not", self)

def __rand__(
self, other: Union[ParentColumn, "LiteralType", "DecimalLiteral", "DateTimeLiteral"]
) -> ParentColumn:
return _bin_op("and", self, other)
from pyspark.sql.functions import lit

return _bin_op("and", self, lit(other))

def __ror__(
self, other: Union[ParentColumn, "LiteralType", "DecimalLiteral", "DateTimeLiteral"]
) -> ParentColumn:
return _bin_op("or", self, other)
from pyspark.sql.functions import lit

return _bin_op("or", self, lit(other))

# container operators
def __contains__(self, item: Any) -> None:
Expand Down
8 changes: 8 additions & 0 deletions python/pyspark/sql/tests/test_column.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,14 @@ def test_column_operators(self):
cs.startswith("a"),
cs.endswith("a"),
ci.eqNullSafe(cs),
sf.col("b") & sf.lit(True),
sf.col("b") & True,
sf.lit(True) & sf.col("b"),
True & sf.col("b"),
sf.col("b") | sf.lit(True),
sf.col("b") | True,
sf.lit(True) | sf.col("b"),
True | sf.col("b"),
)
self.assertTrue(all(isinstance(c, Column) for c in css))
self.assertTrue(isinstance(ci.cast(LongType()), Column))
Expand Down