Skip to content

Commit f5fb1a2

Browse files
aholyokeLinchinchalmerlowe
authored
fix: Implement modulus operator (#1048)
Co-authored-by: Lingqing Gan <lingqing.gan@gmail.com> Co-authored-by: Chalmer Lowe <chalmerlowe@google.com>
1 parent 0577eb7 commit f5fb1a2

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

sqlalchemy_bigquery/base.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,9 @@ def visit_regexp_match_op_binary(self, binary, operator, **kw):
581581
def visit_not_regexp_match_op_binary(self, binary, operator, **kw):
582582
return "NOT %s" % self.visit_regexp_match_op_binary(binary, operator, **kw)
583583

584+
def visit_mod_binary(self, binary, operator, **kw):
585+
return f"MOD({self.process(binary.left, **kw)}, {self.process(binary.right, **kw)})"
586+
584587

585588
class BigQueryTypeCompiler(GenericTypeCompiler):
586589
def visit_INTEGER(self, type_, **kw):

tests/unit/test_select.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,3 +406,16 @@ def test_visit_not_regexp_match_op_binary(faux_conn):
406406
expected = "NOT REGEXP_CONTAINS(`table`.`foo`, %(foo_1:STRING)s)"
407407

408408
assert result == expected
409+
410+
411+
def test_visit_mod_binary(faux_conn):
412+
table = setup_table(
413+
faux_conn,
414+
"table",
415+
sqlalchemy.Column("foo", sqlalchemy.Integer),
416+
)
417+
sql_statement = table.c.foo % 2
418+
result = sql_statement.compile(faux_conn).string
419+
expected = "MOD(`table`.`foo`, %(foo_1:INT64)s)"
420+
421+
assert result == expected

0 commit comments

Comments
 (0)