Skip to content
This repository was archived by the owner on Mar 29, 2023. It is now read-only.

Commit a04a674

Browse files
timothydijamcoTimothy Dijamcotswast
authored
feat: Add rewrite function for ops.FloorDivide (#85)
* feat: Add floor divide rewrite function * chore: release v1.0.0 with latest fixes (#100) * chore: release v1.0.0 with latest fixes * update changelog * update pyarrow dependency * chore: add author * chore: fix classifier * restore rewrite Co-authored-by: Timothy Dijamco <timothy.dijamco@twosigma.com> Co-authored-by: Tim Swast <swast@google.com>
1 parent b35cda9 commit a04a674

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

ibis_bigquery/rewrites.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ def bigquery_day_of_week_name(e):
1111
return arg.strftime("%A")
1212

1313

14+
def bq_floor_divide(expr):
15+
left, right = expr.op().args
16+
return left.div(right).floor()
17+
18+
1419
def identical_to(expr):
1520
left, right = expr.op().args
1621
return (left.isnull() & right.isnull()) | (left == right)
@@ -46,6 +51,7 @@ def bigquery_any_all_no_op(expr):
4651
REWRITES = {
4752
**sql_compiler.ExprTranslator._rewrites,
4853
ops.DayOfWeekName: bigquery_day_of_week_name,
54+
ops.FloorDivide: bq_floor_divide,
4955
ops.IdenticalTo: identical_to,
5056
ops.Log2: log2,
5157
ops.Sum: bq_sum,

tests/system/test_compiler.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,15 @@ def test_ieee_divide(alltypes, project_id, dataset_id):
7070
assert result == expected
7171

7272

73+
def test_floor_divide(alltypes, project_id, dataset_id):
74+
expr = alltypes.double_col // 0
75+
result = expr.compile()
76+
expected = f"""\
77+
SELECT CAST(FLOOR(IEEE_DIVIDE(`double_col`, 0)) AS INT64) AS `tmp`
78+
FROM `{project_id}.{dataset_id}.functional_alltypes`"""
79+
assert result == expected
80+
81+
7382
def test_identical_to(alltypes, project_id, dataset_id):
7483
t = alltypes
7584
pred = t.string_col.identical_to("a") & t.date_string_col.identical_to("b")

0 commit comments

Comments
 (0)