Skip to content

Commit 9c82179

Browse files
committed
feat(snowflake): regex extract, search and replace
1 parent 095ded6 commit 9c82179

File tree

2 files changed

+10
-14
lines changed

2 files changed

+10
-14
lines changed

ibis/backends/snowflake/registry.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,9 @@ def _map(_, op):
226226
ops.BitXor: reduction(sa.func.bitxor_agg),
227227
ops.DateFromYMD: fixed_arity(sa.func.date_from_parts, 3),
228228
ops.StringToTimestamp: fixed_arity(sa.func.to_timestamp_tz, 2),
229+
ops.RegexExtract: fixed_arity(sa.func.regexp_substr, 3),
230+
ops.RegexSearch: fixed_arity(lambda left, right: left.op('REGEXP')(right), 2),
231+
ops.RegexReplace: fixed_arity(sa.func.regexp_replace, 3),
229232
}
230233
)
231234

@@ -243,9 +246,6 @@ def _map(_, op):
243246
ops.MultiQuantile,
244247
# ibis.expr.operations.strings
245248
ops.FindInSet,
246-
ops.RegexExtract,
247-
ops.RegexReplace,
248-
ops.RegexSearch,
249249
# ibis.expr.operations.structs
250250
ops.StructField,
251251
# ibis.expr.operations.temporal

ibis/backends/tests/test_string.py

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -75,25 +75,25 @@ def test_string_col_is_unicode(alltypes, df):
7575
lambda t: t.string_col.re_search(r'\d+'),
7676
lambda t: t.string_col.str.contains(r'\d+'),
7777
id='re_search',
78-
marks=pytest.mark.notimpl(["impala", "datafusion", "snowflake", "mssql"]),
78+
marks=pytest.mark.notimpl(["impala", "datafusion", "mssql"]),
7979
),
8080
param(
8181
lambda t: t.string_col.re_search(r'[[:digit:]]+'),
8282
lambda t: t.string_col.str.contains(r'\d+'),
8383
id='re_search_posix',
84-
marks=pytest.mark.notimpl(["datafusion", "pyspark", "snowflake", "mssql"]),
84+
marks=pytest.mark.notimpl(["datafusion", "pyspark", "mssql"]),
8585
),
8686
param(
8787
lambda t: t.string_col.re_extract(r'(\d+)', 1),
8888
lambda t: t.string_col.str.extract(r'(\d+)', expand=False),
8989
id='re_extract',
90-
marks=pytest.mark.notimpl(["impala", "mysql", "snowflake", "mssql"]),
90+
marks=pytest.mark.notimpl(["impala", "mysql", "mssql"]),
9191
),
9292
param(
9393
lambda t: t.string_col.re_extract(r'([[:digit:]]+)', 1),
9494
lambda t: t.string_col.str.extract(r'(\d+)', expand=False),
9595
id='re_extract_posix',
96-
marks=pytest.mark.notimpl(["mysql", "pyspark", "snowflake", "mssql"]),
96+
marks=pytest.mark.notimpl(["mysql", "pyspark", "mssql"]),
9797
),
9898
param(
9999
lambda t: (t.string_col + "1").re_extract(r'\d(\d+)', 0),
@@ -105,17 +105,13 @@ def test_string_col_is_unicode(alltypes, df):
105105
lambda t: t.string_col.re_replace(r'[[:digit:]]+', 'a'),
106106
lambda t: t.string_col.str.replace(r'\d+', 'a', regex=True),
107107
id='re_replace_posix',
108-
marks=pytest.mark.notimpl(
109-
['datafusion', "mysql", "pyspark", "snowflake", "mssql"]
110-
),
108+
marks=pytest.mark.notimpl(['datafusion', "mysql", "pyspark", "mssql"]),
111109
),
112110
param(
113111
lambda t: t.string_col.re_replace(r'\d+', 'a'),
114112
lambda t: t.string_col.str.replace(r'\d+', 'a', regex=True),
115113
id='re_replace',
116-
marks=pytest.mark.notimpl(
117-
["impala", "datafusion", "mysql", "snowflake", "mssql"]
118-
),
114+
marks=pytest.mark.notimpl(["impala", "datafusion", "mysql", "mssql"]),
119115
),
120116
param(
121117
lambda t: t.string_col.repeat(2),
@@ -379,7 +375,7 @@ def test_string(backend, alltypes, df, result_func, expected_func):
379375
backend.assert_series_equal(result, expected)
380376

381377

382-
@pytest.mark.notimpl(["datafusion", "mysql", "snowflake", "mssql"])
378+
@pytest.mark.notimpl(["datafusion", "mysql", "mssql"])
383379
def test_re_replace_global(con):
384380
expr = ibis.literal("aba").re_replace("a", "c")
385381
result = con.execute(expr)

0 commit comments

Comments
 (0)