From d5ee487025b1d5c505dd8b53ab3be11e0491665f Mon Sep 17 00:00:00 2001 From: jialuo Date: Tue, 14 Oct 2025 00:31:14 +0000 Subject: [PATCH 1/2] 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. --- .../core/compile/sqlglot/expressions/string_ops.py | 6 ++++++ .../test_string_ops/test_strconcat/out.sql | 13 +++++++++++++ .../compile/sqlglot/expressions/test_string_ops.py | 7 +++++++ 3 files changed, 26 insertions(+) create mode 100644 tests/unit/core/compile/sqlglot/expressions/snapshots/test_string_ops/test_strconcat/out.sql diff --git a/bigframes/core/compile/sqlglot/expressions/string_ops.py b/bigframes/core/compile/sqlglot/expressions/string_ops.py index 403cf403f5..5a342756c2 100644 --- a/bigframes/core/compile/sqlglot/expressions/string_ops.py +++ b/bigframes/core/compile/sqlglot/expressions/string_ops.py @@ -23,6 +23,7 @@ import bigframes.core.compile.sqlglot.scalar_compiler as scalar_compiler register_unary_op = scalar_compiler.scalar_op_compiler.register_unary_op +register_binary_op = scalar_compiler.scalar_op_compiler.register_binary_op @register_unary_op(ops.capitalize_op) @@ -276,6 +277,11 @@ def _(expr: TypedExpr) -> sge.Expression: return sge.Upper(this=expr.expr) +@register_binary_op(ops.strconcat_op) +def _(left: TypedExpr, right: TypedExpr) -> sge.Expression: + return sge.Concat(this=left.expr, expression=right.expr) + + @register_unary_op(ops.ZfillOp, pass_op=True) def _(expr: TypedExpr, op: ops.ZfillOp) -> sge.Expression: return sge.Case( diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_string_ops/test_strconcat/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_string_ops/test_strconcat/out.sql new file mode 100644 index 0000000000..71de04b922 --- /dev/null +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_string_ops/test_strconcat/out.sql @@ -0,0 +1,13 @@ +WITH `bfcte_0` AS ( + SELECT + `string_col` AS `bfcol_0` + FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` +), `bfcte_1` AS ( + SELECT + *, + CONCAT() AS `bfcol_1` + FROM `bfcte_0` +) +SELECT + `bfcol_1` AS `string_col` +FROM `bfcte_1` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/test_string_ops.py b/tests/unit/core/compile/sqlglot/expressions/test_string_ops.py index 9121334811..99dbce9410 100644 --- a/tests/unit/core/compile/sqlglot/expressions/test_string_ops.py +++ b/tests/unit/core/compile/sqlglot/expressions/test_string_ops.py @@ -311,3 +311,10 @@ def test_add_string(scalar_types_df: bpd.DataFrame, snapshot): sql = utils._apply_binary_op(bf_df, ops.add_op, "string_col", ex.const("a")) snapshot.assert_match(sql, "out.sql") + + +def test_strconcat(scalar_types_df: bpd.DataFrame, snapshot): + bf_df = scalar_types_df[["string_col"]] + sql = utils._apply_binary_op(bf_df, ops.strconcat_op, "string_col", ex.const("a")) + + snapshot.assert_match(sql, "out.sql") From f0ae48363bf117dd0845a54ddf2d257f217e54b0 Mon Sep 17 00:00:00 2001 From: jialuo Date: Thu, 16 Oct 2025 19:10:05 +0000 Subject: [PATCH 2/2] fix --- bigframes/core/compile/sqlglot/expressions/string_ops.py | 2 +- .../snapshots/test_string_ops/test_strconcat/out.sql | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bigframes/core/compile/sqlglot/expressions/string_ops.py b/bigframes/core/compile/sqlglot/expressions/string_ops.py index 5a342756c2..bdc4808302 100644 --- a/bigframes/core/compile/sqlglot/expressions/string_ops.py +++ b/bigframes/core/compile/sqlglot/expressions/string_ops.py @@ -279,7 +279,7 @@ def _(expr: TypedExpr) -> sge.Expression: @register_binary_op(ops.strconcat_op) def _(left: TypedExpr, right: TypedExpr) -> sge.Expression: - return sge.Concat(this=left.expr, expression=right.expr) + return sge.Concat(expressions=[left.expr, right.expr]) @register_unary_op(ops.ZfillOp, pass_op=True) diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_string_ops/test_strconcat/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_string_ops/test_strconcat/out.sql index 71de04b922..de5129a6a3 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_string_ops/test_strconcat/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_string_ops/test_strconcat/out.sql @@ -5,7 +5,7 @@ WITH `bfcte_0` AS ( ), `bfcte_1` AS ( SELECT *, - CONCAT() AS `bfcol_1` + CONCAT(`bfcol_0`, 'a') AS `bfcol_1` FROM `bfcte_0` ) SELECT