From f295aad450204d0abe86b23778783bb41ce63a28 Mon Sep 17 00:00:00 2001 From: thomas-orvain-al <36629157+thomas-orvain-al@users.noreply.github.com> Date: Thu, 2 Oct 2025 14:55:23 +0200 Subject: [PATCH] Update macro regexp_instr.sql for Athena support Add athena support to the regex macro 'expect_column_values_to_match_regex' --- macros/regex/regexp_instr.sql | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/macros/regex/regexp_instr.sql b/macros/regex/regexp_instr.sql index a0c4c40..433cdb1 100644 --- a/macros/regex/regexp_instr.sql +++ b/macros/regex/regexp_instr.sql @@ -79,6 +79,21 @@ length(regexp_extract({{ source_value }}, '{{ regexp }}', 0)) if({{ regexp_query}} = -1, 0, {{ regexp_query}}) {% endmacro %} +{% macro athena__regexp_instr(source_value, regexp, position, occurrence, is_raw, flags) %} +{% if is_raw or flags %} + {{ exceptions.warn( + "is_raw and flags options are not supported for Athena adapter " + ~ "and are being ignored." + ) }} +{% endif %} +{# Athena doesn't have regexp_instr, so we simulate it using regexp_like #} +{# Return 1 if match found (like position), 0 if not found #} +case + when regexp_like({{ source_value }}, '{{ regexp }}') then 1 + else 0 +end +{% endmacro %} + {% macro _validate_flags(flags, alphabet) %} {% for flag in flags %} {% if flag not in alphabet %}