From 2c1a726ba46dd23f2fd2c94ead32e95c0f19799c Mon Sep 17 00:00:00 2001 From: Phillip Cloud <417981+cpcloud@users.noreply.github.com> Date: Tue, 19 Dec 2023 05:35:34 -0500 Subject: [PATCH] feat(snowflake): implement `RegexSplit` --- ibis/backends/snowflake/__init__.py | 7 ++++++- ibis/backends/snowflake/registry.py | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/ibis/backends/snowflake/__init__.py b/ibis/backends/snowflake/__init__.py index a9bab59fb878..f1b97eea0adb 100644 --- a/ibis/backends/snowflake/__init__.py +++ b/ibis/backends/snowflake/__init__.py @@ -49,7 +49,7 @@ message="You have an incompatible version of 'pyarrow' installed", category=UserWarning, ) - from snowflake.sqlalchemy import ARRAY, DOUBLE, OBJECT, URL + from snowflake.sqlalchemy import ARRAY, DOUBLE, OBJECT, URL, VARCHAR from ibis.backends.snowflake.converter import SnowflakePandasData from ibis.backends.snowflake.datatypes import SnowflakeType @@ -113,6 +113,11 @@ class SnowflakeCompiler(AlchemyCompiler): "returns": ARRAY, "source": """return Array(count).fill(value).flat();""", }, + "ibis_udfs.public.regexp_split": { + "inputs": {"value": VARCHAR, "pattern": VARCHAR}, + "returns": ARRAY, + "source": """return value.split(new RegExp(pattern, "g"));""", + }, } diff --git a/ibis/backends/snowflake/registry.py b/ibis/backends/snowflake/registry.py index e31466ad64c1..3b8b2926c7b1 100644 --- a/ibis/backends/snowflake/registry.py +++ b/ibis/backends/snowflake/registry.py @@ -564,6 +564,7 @@ def _timestamp_range(t, op): 3, ), ops.TimestampRange: _timestamp_range, + ops.RegexSplit: fixed_arity(sa.func.ibis_udfs.public.regexp_split, 2), } )