From 524a2fa9e283b8678fc3e04aa72a7d5429162389 Mon Sep 17 00:00:00 2001 From: Phillip Cloud <417981+cpcloud@users.noreply.github.com> Date: Wed, 7 Aug 2024 06:13:28 -0400 Subject: [PATCH] feat(snowflake): add `userinfo` URL parsing --- ibis/backends/sql/compilers/snowflake.py | 6 ++++++ ibis/backends/tests/test_string.py | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/ibis/backends/sql/compilers/snowflake.py b/ibis/backends/sql/compilers/snowflake.py index c6ab7451ddbd..52cffb0a3697 100644 --- a/ibis/backends/sql/compilers/snowflake.py +++ b/ibis/backends/sql/compilers/snowflake.py @@ -559,6 +559,12 @@ def visit_ExtractFragment(self, op, *, arg): self.f.as_varchar(self.f.get(self.f.parse_url(arg, 1), "fragment")), "" ) + def visit_ExtractUserInfo(self, op, *, arg): + host = self.f.get(self.f.parse_url(arg), "host") + return self.if_( + host.like(sge.convert("%@%")), self.f.split_part(host, "@", 1), NULL + ) + def visit_Unnest(self, op, *, arg): sep = sge.convert(util.guid()) split = self.f.split( diff --git a/ibis/backends/tests/test_string.py b/ibis/backends/tests/test_string.py index 7df32ed50b41..e4ffabbbc58b 100644 --- a/ibis/backends/tests/test_string.py +++ b/ibis/backends/tests/test_string.py @@ -729,7 +729,7 @@ def test_substr_with_null_values(backend, alltypes, df): "user:pass", marks=[ pytest.mark.notyet( - ["bigquery", "clickhouse", "snowflake", "trino"], + ["bigquery", "clickhouse", "trino"], raises=com.OperationNotDefinedError, reason="doesn't support `USERINFO`", )