Skip to content

Commit 7ad273a

Browse files
committed
implement ne_op
1 parent 6f83b54 commit 7ad273a

File tree

3 files changed

+77
-0
lines changed

3 files changed

+77
-0
lines changed

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,17 @@ def _(op, left: TypedExpr, right: TypedExpr) -> sge.Expression:
149149
return result
150150

151151

152+
@BINARY_OP_REGISTRATION.register(ops.ne_op)
153+
def _(op, left: TypedExpr, right: TypedExpr) -> sge.Expression:
154+
left_expr = left.expr
155+
if left.dtype == dtypes.BOOL_DTYPE:
156+
left_expr = sge.Cast(this=left_expr, to="INT64")
157+
right_expr = right.expr
158+
if right.dtype == dtypes.BOOL_DTYPE:
159+
right_expr = sge.Cast(this=right_expr, to="INT64")
160+
return sge.NEQ(this=left_expr, expression=right_expr)
161+
162+
152163
@BINARY_OP_REGISTRATION.register(ops.sub_op)
153164
def _(op, left: TypedExpr, right: TypedExpr) -> sge.Expression:
154165
if dtypes.is_numeric(left.dtype) and dtypes.is_numeric(right.dtype):
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
WITH `bfcte_0` AS (
2+
SELECT
3+
`bool_col` AS `bfcol_0`,
4+
`int64_col` AS `bfcol_1`,
5+
`rowindex` AS `bfcol_2`
6+
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types`
7+
), `bfcte_1` AS (
8+
SELECT
9+
*,
10+
`bfcol_2` AS `bfcol_6`,
11+
`bfcol_1` AS `bfcol_7`,
12+
`bfcol_0` AS `bfcol_8`,
13+
`bfcol_1` <> `bfcol_1` AS `bfcol_9`
14+
FROM `bfcte_0`
15+
), `bfcte_2` AS (
16+
SELECT
17+
*,
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+
`bfcol_7` <> 1 AS `bfcol_18`
23+
FROM `bfcte_1`
24+
), `bfcte_3` AS (
25+
SELECT
26+
*,
27+
`bfcol_14` AS `bfcol_24`,
28+
`bfcol_15` AS `bfcol_25`,
29+
`bfcol_16` AS `bfcol_26`,
30+
`bfcol_17` AS `bfcol_27`,
31+
`bfcol_18` AS `bfcol_28`,
32+
`bfcol_15` <> CAST(`bfcol_16` AS INT64) AS `bfcol_29`
33+
FROM `bfcte_2`
34+
), `bfcte_4` AS (
35+
SELECT
36+
*,
37+
`bfcol_24` AS `bfcol_36`,
38+
`bfcol_25` AS `bfcol_37`,
39+
`bfcol_26` AS `bfcol_38`,
40+
`bfcol_27` AS `bfcol_39`,
41+
`bfcol_28` AS `bfcol_40`,
42+
`bfcol_29` AS `bfcol_41`,
43+
CAST(`bfcol_26` AS INT64) <> `bfcol_25` AS `bfcol_42`
44+
FROM `bfcte_3`
45+
)
46+
SELECT
47+
`bfcol_36` AS `rowindex`,
48+
`bfcol_37` AS `int64_col`,
49+
`bfcol_38` AS `bool_col`,
50+
`bfcol_39` AS `int_ne_int`,
51+
`bfcol_40` AS `int_ne_1`,
52+
`bfcol_41` AS `int_ne_bool`,
53+
`bfcol_42` AS `bool_ne_int`
54+
FROM `bfcte_4`

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,3 +175,15 @@ def test_mul_timedelta(scalar_types_df: bpd.DataFrame, snapshot):
175175
def test_obj_make_ref(scalar_types_df: bpd.DataFrame, snapshot):
176176
blob_df = scalar_types_df["string_col"].str.to_blob()
177177
snapshot.assert_match(blob_df.to_frame().sql, "out.sql")
178+
179+
180+
def test_ne_numeric(scalar_types_df: bpd.DataFrame, snapshot):
181+
bf_df = scalar_types_df[["int64_col", "bool_col"]]
182+
183+
bf_df["int_ne_int"] = bf_df["int64_col"] != bf_df["int64_col"]
184+
bf_df["int_ne_1"] = bf_df["int64_col"] != 1
185+
186+
bf_df["int_ne_bool"] = bf_df["int64_col"] != bf_df["bool_col"]
187+
bf_df["bool_ne_int"] = bf_df["bool_col"] != bf_df["int64_col"]
188+
189+
snapshot.assert_match(bf_df.sql, "out.sql")

0 commit comments

Comments
 (0)