Skip to content

Commit

Permalink
Fix materialized_views filters when listing relations
Browse files Browse the repository at this point in the history
Before the change, the `list_relations_without_caching` macro queried
`system.metadata.materialized_views` with no effective filter on the
catalog and schema name. In theory the Trino optimizer could figure out
the effective predicate on the `system.metadata.materialized_views`
table, but in practice it was not happening, and all materialized views
from all catalogs where being pulled.
  • Loading branch information
findepi committed Sep 28, 2023
1 parent ff99ddc commit a0be1c4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
7 changes: 7 additions & 0 deletions .changes/unreleased/Fixes-20230927-124454.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
kind: Fixes
body: Fix materialized_views filters when listing relations
time: 2023-09-27T12:44:54.858517+02:00
custom:
Author: findepi
Issue: ""
PR: "353"
7 changes: 4 additions & 3 deletions dbt/include/trino/macros/adapters.sql
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,12 @@
else t.table_type
end as table_type
from {{ relation.information_schema() }}.tables t
left join system.metadata.materialized_views mv
left join (
select * from system.metadata.materialized_views
where catalog_name = '{{ relation.database | lower }}'
and schema_name = '{{ relation.schema | lower }}') mv
on mv.catalog_name = t.table_catalog and mv.schema_name = t.table_schema and mv.name = t.table_name
where t.table_schema = '{{ relation.schema | lower }}'
and (mv.catalog_name is null or mv.catalog_name = '{{ relation.database | lower }}')
and (mv.schema_name is null or mv.schema_name = '{{ relation.schema | lower }}')
{% endcall %}
{{ return(load_result('list_relations_without_caching').table) }}
{% endmacro %}
Expand Down

0 comments on commit a0be1c4

Please sign in to comment.