"""
return self.operate(ilike_op, other, escape=escape)
- def bitwise_xor(self, other):
+ def bitwise_xor(self, other: Any) -> ColumnOperators:
"""Return bitwise XOR operation"""
return self.operate(bitwise_xor_op, other)
- def bitwise_or(self, other):
+ def bitwise_or(self, other: Any) -> ColumnOperators:
"""Return bitwise OR operation"""
return self.operate(bitwise_or_op, other)
- def bitwise_and(self, other):
+ def bitwise_and(self, other: Any) -> ColumnOperators:
"""Return bitwise AND operation"""
return self.operate(bitwise_and_op, other)
return a.bitwise_and(b)
+@_operator_fn
+def bitwise_not_op(a: Any) -> Any:
+ return a.bitwise_not()
+
+
+@_operator_fn
+def bitwise_lshift_op(a: Any, b: Any) -> Any:
+ return a.bitwise_lshift(b)
+
+
+@_operator_fn
+def bitwise_rshift_op(a: Any, b: Any) -> Any:
+ return a.bitwise_rshift(b)
+
+
def is_comparison(op: OperatorType) -> bool:
return op in _comparison or isinstance(op, custom_op) and op.is_comparison
class BitOpTest(fixtures.TestBase, testing.AssertsCompiledSQL):
- def test_bitwise_xor(self):
- c1 = column("c1", Integer)
- c2 = column("c2", Integer)
- self.assert_compile(
- select(c1.bitwise_xor(c2)),
- "SELECT c1 ^ c2 AS anon_1",
- )
-
- def test_bitwise_or(self):
- c1 = column("c1", Integer)
- c2 = column("c2", Integer)
- self.assert_compile(
- select(c1.bitwise_or(c2)),
- "SELECT c1 | c2 AS anon_1",
- )
-
- def test_bitwise_and(self):
+ @testing.combinations(
+ ("xor", operators.bitwise_xor_op, "^"),
+ ("or", operators.bitwise_or_op, "|"),
+ ("and", operators.bitwise_and_op, "&"),
+ ("not", operators.bitwise_not_op, "~"),
+ ("lshift", operators.bitwise_lshift_op, "<<"),
+ ("rshift", operators.bitwise_rshift_op, ">>"),
+ id_="iaa",
+ )
+ def test_default_compile(self, py_op, sql_op):
c1 = column("c1", Integer)
c2 = column("c2", Integer)
self.assert_compile(
- select(c1.bitwise_and(c2)),
- "SELECT c1 & c2 AS anon_1",
+ select(py_op(c1, c2)),
+ f"SELECT c1 {sql_op} c2 AS anon_1",
)