Skip to content

Commit cabbf85

Browse files
authored
chore: Migrate strconcat_op operator to SQLGlot (#2166)
* chore: Migrate strconcat_op operator to SQLGlot Migrated the `strconcat_op` operator from the Ibis compiler to the new SQLGlot compiler. This includes the implementation of the compiler logic and a corresponding unit test with a snapshot. * fix
1 parent 1a01ab9 commit cabbf85

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import bigframes.core.compile.sqlglot.scalar_compiler as scalar_compiler
2424

2525
register_unary_op = scalar_compiler.scalar_op_compiler.register_unary_op
26+
register_binary_op = scalar_compiler.scalar_op_compiler.register_binary_op
2627

2728

2829
@register_unary_op(ops.capitalize_op)
@@ -276,6 +277,11 @@ def _(expr: TypedExpr) -> sge.Expression:
276277
return sge.Upper(this=expr.expr)
277278

278279

280+
@register_binary_op(ops.strconcat_op)
281+
def _(left: TypedExpr, right: TypedExpr) -> sge.Expression:
282+
return sge.Concat(expressions=[left.expr, right.expr])
283+
284+
279285
@register_unary_op(ops.ZfillOp, pass_op=True)
280286
def _(expr: TypedExpr, op: ops.ZfillOp) -> sge.Expression:
281287
return sge.Case(
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
WITH `bfcte_0` AS (
2+
SELECT
3+
`string_col` AS `bfcol_0`
4+
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types`
5+
), `bfcte_1` AS (
6+
SELECT
7+
*,
8+
CONCAT(`bfcol_0`, 'a') AS `bfcol_1`
9+
FROM `bfcte_0`
10+
)
11+
SELECT
12+
`bfcol_1` AS `string_col`
13+
FROM `bfcte_1`

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,3 +311,10 @@ def test_add_string(scalar_types_df: bpd.DataFrame, snapshot):
311311
sql = utils._apply_binary_op(bf_df, ops.add_op, "string_col", ex.const("a"))
312312

313313
snapshot.assert_match(sql, "out.sql")
314+
315+
316+
def test_strconcat(scalar_types_df: bpd.DataFrame, snapshot):
317+
bf_df = scalar_types_df[["string_col"]]
318+
sql = utils._apply_binary_op(bf_df, ops.strconcat_op, "string_col", ex.const("a"))
319+
320+
snapshot.assert_match(sql, "out.sql")

0 commit comments

Comments
 (0)