Skip to content

Commit 9e4b825

Browse files
committed
fix: Implement modulus operator
1 parent 3e80d65 commit 9e4b825

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

sqlalchemy_bigquery/base.py

+3
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,9 @@ def visit_regexp_match_op_binary(self, binary, operator, **kw):
579579
def visit_not_regexp_match_op_binary(self, binary, operator, **kw):
580580
return "NOT %s" % self.visit_regexp_match_op_binary(binary, operator, **kw)
581581

582+
def visit_mod_binary(self, binary, operator, **kw):
583+
return f"MOD({self.process(binary.left, **kw)}, {self.process(binary.right, **kw)})"
584+
582585

583586
class BigQueryTypeCompiler(GenericTypeCompiler):
584587
def visit_INTEGER(self, type_, **kw):

tests/unit/test_select.py

+13
Original file line numberDiff line numberDiff line change
@@ -486,3 +486,16 @@ def test_visit_not_regexp_match_op_binary(faux_conn):
486486
expected = "NOT REGEXP_CONTAINS(`table`.`foo`, %(foo_1:STRING)s)"
487487

488488
assert result == expected
489+
490+
491+
def test_visit_mod_binary(faux_conn):
492+
table = setup_table(
493+
faux_conn,
494+
"table",
495+
sqlalchemy.Column("foo", sqlalchemy.Integer),
496+
)
497+
sql_statement = table.c.foo % 2
498+
result = sql_statement.compile(faux_conn).string
499+
expected = "MOD(`table`.`foo`, %(foo_1:INT64)s)"
500+
501+
assert result == expected

0 commit comments

Comments
 (0)