Skip to content

Commit

Permalink
Speedup catalog string comparison by using ilike before equals (#982)
Browse files Browse the repository at this point in the history
* Speedup catalog string comparison by using ilike before equals

* Add parens

* add changie

* Update Under the Hood-20240425-144556.yaml

(cherry picked from commit 32b6d39)
  • Loading branch information
aranke authored and github-actions[bot] committed May 13, 2024
1 parent cd14403 commit 5eec68c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
6 changes: 6 additions & 0 deletions .changes/unreleased/Under the Hood-20240425-144556.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: Under the Hood
body: Speedup catalog string comparison by using ilike before equals
time: 2024-04-25T14:45:56.549787+02:00
custom:
Author: aranke
Issue: '1035'
13 changes: 9 additions & 4 deletions dbt/include/snowflake/macros/catalog.sql
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,14 @@
{%- endmacro %}


{% macro snowflake__catalog_equals(field, value) %}
"{{ field }}" ilike '{{ value }}' and upper("{{ field }}") = upper('{{ value }}')
{% endmacro %}


{% macro snowflake__get_catalog_schemas_where_clause_sql(schemas) -%}
where ({%- for schema in schemas -%}
upper("table_schema") = upper('{{ schema }}'){%- if not loop.last %} or {% endif -%}
({{ snowflake__catalog_equals('table_schema', schema) }}){%- if not loop.last %} or {% endif -%}
{%- endfor -%})
{%- endmacro %}

Expand All @@ -107,12 +112,12 @@
{%- for relation in relations -%}
{% if relation.schema and relation.identifier %}
(
upper("table_schema") = upper('{{ relation.schema }}')
and upper("table_name") = upper('{{ relation.identifier }}')
{{ snowflake__catalog_equals('table_schema', relation.schema) }}
and {{ snowflake__catalog_equals('table_name', relation.identifier) }}
)
{% elif relation.schema %}
(
upper("table_schema") = upper('{{ relation.schema }}')
{{ snowflake__catalog_equals('table_schema', relation.schema) }}
)
{% else %}
{% do exceptions.raise_compiler_error(
Expand Down

0 comments on commit 5eec68c

Please sign in to comment.