Skip to content

Commit f7fd43a

Browse files
committed
refactor: fix isdigit_op and isdecimal_op
1 parent 89ef3d8 commit f7fd43a

File tree

3 files changed

+10
-4
lines changed
  • bigframes/core/compile/sqlglot/expressions
  • tests/unit/core/compile/sqlglot/expressions/snapshots/test_string_ops

3 files changed

+10
-4
lines changed

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,12 +153,15 @@ def _(expr: TypedExpr) -> sge.Expression:
153153

154154
@register_unary_op(ops.isdecimal_op)
155155
def _(expr: TypedExpr) -> sge.Expression:
156-
return sge.RegexpLike(this=expr.expr, expression=sge.convert(r"^\d+$"))
156+
return sge.RegexpLike(this=expr.expr, expression=sge.convert(r"^(\p{Nd})+$"))
157157

158158

159159
@register_unary_op(ops.isdigit_op)
160160
def _(expr: TypedExpr) -> sge.Expression:
161-
return sge.RegexpLike(this=expr.expr, expression=sge.convert(r"^\p{Nd}+$"))
161+
regexp_pattern = (
162+
r"^[\p{Nd}\x{00B9}\x{00B2}\x{00B3}\x{2070}\x{2074}-\x{2079}\x{2080}-\x{2089}]+$"
163+
)
164+
return sge.RegexpLike(this=expr.expr, expression=sge.convert(regexp_pattern))
162165

163166

164167
@register_unary_op(ops.islower_op)

tests/unit/core/compile/sqlglot/expressions/snapshots/test_string_ops/test_isdecimal/out.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ WITH `bfcte_0` AS (
55
), `bfcte_1` AS (
66
SELECT
77
*,
8-
REGEXP_CONTAINS(`string_col`, '^\\d+$') AS `bfcol_1`
8+
REGEXP_CONTAINS(`string_col`, '^(\\p{Nd})+$') AS `bfcol_1`
99
FROM `bfcte_0`
1010
)
1111
SELECT

tests/unit/core/compile/sqlglot/expressions/snapshots/test_string_ops/test_isdigit/out.sql

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ WITH `bfcte_0` AS (
55
), `bfcte_1` AS (
66
SELECT
77
*,
8-
REGEXP_CONTAINS(`string_col`, '^\\p{Nd}+$') AS `bfcol_1`
8+
REGEXP_CONTAINS(
9+
`string_col`,
10+
'^[\\p{Nd}\\x{00B9}\\x{00B2}\\x{00B3}\\x{2070}\\x{2074}-\\x{2079}\\x{2080}-\\x{2089}]+$'
11+
) AS `bfcol_1`
912
FROM `bfcte_0`
1013
)
1114
SELECT

0 commit comments

Comments
 (0)