Skip to content

Commit 64ad238

Browse files
committed
stringSplit
1 parent b779c73 commit 64ad238

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -681,6 +681,11 @@ def _(op: ops.base_ops.UnaryOp, expr: TypedExpr) -> sge.Expression:
681681
)
682682

683683

684+
@UNARY_OP_REGISTRATION.register(ops.StringSplitOp)
685+
def _(op: ops.StringSplitOp, expr: TypedExpr) -> sge.Expression:
686+
return sge.Split(this=expr.expr, expression=sge.convert(op.pat))
687+
688+
684689
@UNARY_OP_REGISTRATION.register(ops.StrGetOp)
685690
def _(op: ops.StrGetOp, expr: TypedExpr) -> sge.Expression:
686691
return sge.Substring(
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+
SPLIT(`bfcol_0`, ',') 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_unary_compiler.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -674,6 +674,12 @@ def test_sinh(scalar_types_df: bpd.DataFrame, snapshot):
674674
snapshot.assert_match(sql, "out.sql")
675675

676676

677+
def test_string_split(scalar_types_df: bpd.DataFrame, snapshot):
678+
bf_df = scalar_types_df[["string_col"]]
679+
sql = _apply_unary_op(bf_df, ops.StringSplitOp(pat=","), "string_col")
680+
snapshot.assert_match(sql, "out.sql")
681+
682+
677683
def test_tan(scalar_types_df: bpd.DataFrame, snapshot):
678684
bf_df = scalar_types_df[["float64_col"]]
679685
sql = _apply_unary_op(bf_df, ops.tan_op, "float64_col")

0 commit comments

Comments
 (0)