diff --git a/bigframes/core/compile/sqlglot/expressions/string_ops.py b/bigframes/core/compile/sqlglot/expressions/string_ops.py index 403cf403f5..bdc4808302 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(expressions=[left.expr, 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..de5129a6a3 --- /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(`bfcol_0`, 'a') 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")