Skip to content

Commit dc13447

Browse files
committed
address comments
1 parent 5933fc3 commit dc13447

File tree

4 files changed

+31
-22
lines changed

4 files changed

+31
-22
lines changed

bigframes/core/compile/sqlglot/expressions/binary_compiler.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def _(op, left: TypedExpr, right: TypedExpr) -> sge.Expression:
8383
right_expr = sge.Cast(this=right_expr, to="INT64")
8484

8585
result = sge.func("IEEE_DIVIDE", left_expr, right_expr)
86-
if dtypes.is_numeric(right.dtype) and left.dtype == dtypes.TIMEDELTA_DTYPE:
86+
if left.dtype == dtypes.TIMEDELTA_DTYPE and dtypes.is_numeric(right.dtype):
8787
return sge.Cast(this=sge.Floor(this=result), to="INT64")
8888
else:
8989
return result
@@ -111,7 +111,7 @@ def _(op, left: TypedExpr, right: TypedExpr) -> sge.Expression:
111111
result = sge.Mul(this=left_expr, expression=right_expr)
112112

113113
if (dtypes.is_numeric(left.dtype) and right.dtype == dtypes.TIMEDELTA_DTYPE) or (
114-
dtypes.is_numeric(right.dtype) and left.dtype == dtypes.TIMEDELTA_DTYPE
114+
left.dtype == dtypes.TIMEDELTA_DTYPE and dtypes.is_numeric(right.dtype)
115115
):
116116
return sge.Cast(this=sge.Floor(this=result), to="INT64")
117117
else:
Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
11
WITH `bfcte_0` AS (
22
SELECT
3-
`date_col` AS `bfcol_0`,
3+
`int64_col` AS `bfcol_0`,
44
`rowindex` AS `bfcol_1`,
55
`timestamp_col` AS `bfcol_2`
66
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types`
77
), `bfcte_1` AS (
88
SELECT
99
*,
10-
43200000000 AS `bfcol_6`
10+
`bfcol_1` AS `bfcol_6`,
11+
`bfcol_2` AS `bfcol_7`,
12+
`bfcol_0` AS `bfcol_8`,
13+
CAST(FLOOR(IEEE_DIVIDE(86400000000, `bfcol_0`)) AS INT64) AS `bfcol_9`
1114
FROM `bfcte_0`
1215
)
1316
SELECT
14-
`bfcol_1` AS `rowindex`,
15-
`bfcol_2` AS `timestamp_col`,
16-
`bfcol_0` AS `date_col`,
17-
`bfcol_6` AS `timedelta_div_numeric`
17+
`bfcol_6` AS `rowindex`,
18+
`bfcol_7` AS `timestamp_col`,
19+
`bfcol_8` AS `int64_col`,
20+
`bfcol_9` AS `timedelta_div_numeric`
1821
FROM `bfcte_1`
Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,31 @@
11
WITH `bfcte_0` AS (
22
SELECT
3-
`date_col` AS `bfcol_0`,
3+
`int64_col` AS `bfcol_0`,
44
`rowindex` AS `bfcol_1`,
55
`timestamp_col` AS `bfcol_2`
66
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types`
77
), `bfcte_1` AS (
88
SELECT
99
*,
10-
172800000000 AS `bfcol_6`
10+
`bfcol_1` AS `bfcol_6`,
11+
`bfcol_2` AS `bfcol_7`,
12+
`bfcol_0` AS `bfcol_8`,
13+
CAST(FLOOR(86400000000 * `bfcol_0`) AS INT64) AS `bfcol_9`
1114
FROM `bfcte_0`
1215
), `bfcte_2` AS (
1316
SELECT
1417
*,
15-
172800000000 AS `bfcol_7`
18+
`bfcol_6` AS `bfcol_14`,
19+
`bfcol_7` AS `bfcol_15`,
20+
`bfcol_8` AS `bfcol_16`,
21+
`bfcol_9` AS `bfcol_17`,
22+
CAST(FLOOR(`bfcol_8` * 86400000000) AS INT64) AS `bfcol_18`
1623
FROM `bfcte_1`
1724
)
1825
SELECT
19-
`bfcol_1` AS `rowindex`,
20-
`bfcol_2` AS `timestamp_col`,
21-
`bfcol_0` AS `date_col`,
22-
`bfcol_6` AS `timedelta_mul_numeric`,
23-
`bfcol_7` AS `numeric_mul_timedelta`
26+
`bfcol_14` AS `rowindex`,
27+
`bfcol_15` AS `timestamp_col`,
28+
`bfcol_16` AS `int64_col`,
29+
`bfcol_17` AS `timedelta_mul_numeric`,
30+
`bfcol_18` AS `numeric_mul_timedelta`
2431
FROM `bfcte_2`

tests/unit/core/compile/sqlglot/expressions/test_binary_compiler.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,9 @@ def test_div_numeric(scalar_types_df: bpd.DataFrame, snapshot):
9595

9696

9797
def test_div_timedelta(scalar_types_df: bpd.DataFrame, snapshot):
98-
bf_df = scalar_types_df[["timestamp_col", "date_col"]]
98+
bf_df = scalar_types_df[["timestamp_col", "int64_col"]]
9999
timedelta = pd.Timedelta(1, unit="d")
100-
101-
bf_df["timedelta_div_numeric"] = timedelta / 2
100+
bf_df["timedelta_div_numeric"] = timedelta / bf_df["int64_col"]
102101

103102
snapshot.assert_match(bf_df.sql, "out.sql")
104103

@@ -158,10 +157,10 @@ def test_mul_numeric(scalar_types_df: bpd.DataFrame, snapshot):
158157

159158

160159
def test_mul_timedelta(scalar_types_df: bpd.DataFrame, snapshot):
161-
bf_df = scalar_types_df[["timestamp_col", "date_col"]]
160+
bf_df = scalar_types_df[["timestamp_col", "int64_col"]]
162161
timedelta = pd.Timedelta(1, unit="d")
163162

164-
bf_df["timedelta_mul_numeric"] = timedelta * 2
165-
bf_df["numeric_mul_timedelta"] = 2 * timedelta
163+
bf_df["timedelta_mul_numeric"] = timedelta * bf_df["int64_col"]
164+
bf_df["numeric_mul_timedelta"] = bf_df["int64_col"] * timedelta
166165

167166
snapshot.assert_match(bf_df.sql, "out.sql")

0 commit comments

Comments
 (0)