Skip to content

Commit f485d26

Browse files
committed
implement lt_op
1 parent 68a77eb commit f485d26

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
@@ -141,6 +141,17 @@ def _(op, left: TypedExpr, right: TypedExpr) -> sge.Expression:
141141
return sge.func("JSON_SET", left.expr, sge.convert(op.json_path), right.expr)
142142

143143

144+
@BINARY_OP_REGISTRATION.register(ops.lt_op)
145+
def _(op, left: TypedExpr, right: TypedExpr) -> sge.Expression:
146+
left_expr = left.expr
147+
if left.dtype == dtypes.BOOL_DTYPE:
148+
left_expr = sge.Cast(this=left_expr, to="INT64")
149+
right_expr = right.expr
150+
if right.dtype == dtypes.BOOL_DTYPE:
151+
right_expr = sge.Cast(this=right_expr, to="INT64")
152+
return sge.LT(this=left_expr, expression=right_expr)
153+
154+
144155
@BINARY_OP_REGISTRATION.register(ops.mul_op)
145156
def _(op, left: TypedExpr, right: TypedExpr) -> sge.Expression:
146157
left_expr = left.expr
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_lt_int`,
51+
`bfcol_40` AS `int_lt_1`,
52+
`bfcol_41` AS `int_lt_bool`,
53+
`bfcol_42` AS `bool_lt_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
@@ -129,6 +129,18 @@ def test_json_set(json_types_df: bpd.DataFrame, snapshot):
129129
snapshot.assert_match(sql, "out.sql")
130130

131131

132+
def test_lt_numeric(scalar_types_df: bpd.DataFrame, snapshot):
133+
bf_df = scalar_types_df[["int64_col", "bool_col"]]
134+
135+
bf_df["int_lt_int"] = bf_df["int64_col"] < bf_df["int64_col"]
136+
bf_df["int_lt_1"] = bf_df["int64_col"] < 1
137+
138+
bf_df["int_lt_bool"] = bf_df["int64_col"] < bf_df["bool_col"]
139+
bf_df["bool_lt_int"] = bf_df["bool_col"] < bf_df["int64_col"]
140+
141+
snapshot.assert_match(bf_df.sql, "out.sql")
142+
143+
132144
def test_sub_numeric(scalar_types_df: bpd.DataFrame, snapshot):
133145
bf_df = scalar_types_df[["int64_col", "bool_col"]]
134146

0 commit comments

Comments
 (0)