Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Speedup catalog string comparison by using ilike before equals #982

Merged
merged 7 commits into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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: ' '
aranke marked this conversation as resolved.
Show resolved Hide resolved
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
Loading