Skip to content

Commit 2459aa4

Browse files
jialuooshuoweil
authored andcommitted
chore: Migrate minimum_op operator to SQLGlot (#2205)
1 parent 907cf2c commit 2459aa4

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,11 @@ def _(left: TypedExpr, right: TypedExpr) -> sge.Expression:
109109
return sge.LTE(this=left_expr, expression=right_expr)
110110

111111

112+
@register_binary_op(ops.minimum_op)
113+
def _(left: TypedExpr, right: TypedExpr) -> sge.Expression:
114+
return sge.Least(this=left.expr, expressions=right.expr)
115+
116+
112117
@register_binary_op(ops.ne_op)
113118
def _(left: TypedExpr, right: TypedExpr) -> sge.Expression:
114119
left_expr = _coerce_bool_to_int(left)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
WITH `bfcte_0` AS (
2+
SELECT
3+
`int64_col` AS `bfcol_0`,
4+
`float64_col` AS `bfcol_1`
5+
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types`
6+
), `bfcte_1` AS (
7+
SELECT
8+
*,
9+
LEAST(`bfcol_0`, `bfcol_1`) AS `bfcol_2`
10+
FROM `bfcte_0`
11+
)
12+
SELECT
13+
`bfcol_2` AS `int64_col`
14+
FROM `bfcte_1`

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,13 @@ def test_le_numeric(scalar_types_df: bpd.DataFrame, snapshot):
110110
snapshot.assert_match(bf_df.sql, "out.sql")
111111

112112

113+
def test_minimum_op(scalar_types_df: bpd.DataFrame, snapshot):
114+
bf_df = scalar_types_df[["int64_col", "float64_col"]]
115+
sql = utils._apply_binary_op(bf_df, ops.minimum_op, "int64_col", "float64_col")
116+
117+
snapshot.assert_match(sql, "out.sql")
118+
119+
113120
def test_ne_numeric(scalar_types_df: bpd.DataFrame, snapshot):
114121
bf_df = scalar_types_df[["int64_col", "bool_col"]]
115122

0 commit comments

Comments
 (0)