operators.nulls_last_op: " NULLS LAST",
# bitwise
operators.bitwise_xor_op: " ^ ",
+ operators.bitwise_or_op: " | ",
+ operators.bitwise_and_op: " & ",
}
FUNCTIONS: Dict[Type[Function[Any]], str] = {
"div": (_binary_operate, util.EMPTY_DICT),
"mod": (_binary_operate, util.EMPTY_DICT),
"bitwise_xor_op": (_binary_operate, util.EMPTY_DICT),
+ "bitwise_or_op": (_binary_operate, util.EMPTY_DICT),
+ "bitwise_and_op": (_binary_operate, util.EMPTY_DICT),
"truediv": (_binary_operate, util.EMPTY_DICT),
"floordiv": (_binary_operate, util.EMPTY_DICT),
"custom_op": (_custom_op_operate, util.EMPTY_DICT),
return self.operate(bitwise_xor_op, other)
+ def bitwise_or(self, other):
+ """Return bitwise OR operation"""
+
+ return self.operate(bitwise_or_op, other)
+
+ def bitwise_and(self, other):
+ """Return bitwise AND operation"""
+
+ return self.operate(bitwise_and_op, other)
+
def in_(self, other: Any) -> ColumnOperators:
"""Implement the ``in`` operator.
return a.bitwise_xor(b)
+@_operator_fn
+def bitwise_or_op(a: Any, b: Any) -> Any:
+ return a.bitwise_or(b)
+
+
+@_operator_fn
+def bitwise_and_op(a: Any, b: Any) -> Any:
+ return a.bitwise_and(b)
+
+
def is_comparison(op: OperatorType) -> bool:
return op in _comparison or isinstance(op, custom_op) and op.is_comparison
neg: 8,
add: 7,
sub: 7,
+ bitwise_xor_op: 7,
+ bitwise_or_op: 7,
+ bitwise_and_op: 7,
concat_op: 6,
filter_op: 6,
match_op: 5,
is_false: 5,
and_: 3,
or_: 2,
- bitwise_xor_op: 1, # just guessing
comma_op: -1,
desc_op: 3,
asc_op: 3,
"WHERE usages.date <@ %(date_1)s::DATERANGE",
)
- def test_dedicated_bit_xor(self):
+ def test_bitwise_xor(self):
c1 = column("c1", Integer)
c2 = column("c2", Integer)
self.assert_compile(
self.assert_compile(op2, "mytable.myid hoho :myid_1 lala :param_1")
self.assert_compile(op3, "(mytable.myid hoho :myid_1) lala :param_1")
+ def test_bitwise_xor_precedence(self):
+ op1 = self.table1.c.myid.bitwise_xor
+ op2 = op1(5).op("lala", precedence=6)(4)
+ op3 = op1(5).op("lala", precedence=8)(4)
+
+ self.assert_compile(op2, "mytable.myid ^ :myid_1 lala :param_1")
+ self.assert_compile(op3, "(mytable.myid ^ :myid_1) lala :param_1")
+
def test_is_eq_precedence_flat(self):
self.assert_compile(
(self.table1.c.name == null())
class BitOpTest(fixtures.TestBase, testing.AssertsCompiledSQL):
- def test_generic_bit_xor(self):
+ def test_bitwise_xor(self):
c1 = column("c1", Integer)
c2 = column("c2", Integer)
self.assert_compile(
- select(c1.op("^")(c2)),
+ select(c1.bitwise_xor(c2)),
"SELECT c1 ^ c2 AS anon_1",
)
- def test_dedicated_bit_xor(self):
+ def test_bitwise_or(self):
c1 = column("c1", Integer)
c2 = column("c2", Integer)
self.assert_compile(
- select(c1.bitwise_xor(c2)),
- "SELECT c1 ^ c2 AS anon_1",
+ select(c1.bitwise_or(c2)),
+ "SELECT c1 | c2 AS anon_1",
+ )
+
+ def test_bitwise_and(self):
+ c1 = column("c1", Integer)
+ c2 = column("c2", Integer)
+ self.assert_compile(
+ select(c1.bitwise_and(c2)),
+ "SELECT c1 & c2 AS anon_1",
)