From 5712dcf07cd85e61895e3480ffe1b876916fc2da Mon Sep 17 00:00:00 2001 From: Paul Laturaze Date: Tue, 25 Jun 2024 14:40:15 +0200 Subject: [PATCH] fix: Fix grants statements on materialized views Granting privileges on materialized views was failing because the generated SQL statement used the relation type `materialized_view` as part of the query instead of `materialized view` (with a space). This commit defines an override for this specific materialization in the and grant/revoke macros. --- .../bigquery/macros/adapters/apply_grants.sql | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/dbt/include/bigquery/macros/adapters/apply_grants.sql b/dbt/include/bigquery/macros/adapters/apply_grants.sql index e344862ae..84fd64f4a 100644 --- a/dbt/include/bigquery/macros/adapters/apply_grants.sql +++ b/dbt/include/bigquery/macros/adapters/apply_grants.sql @@ -12,9 +12,19 @@ {%- macro bigquery__get_grant_sql(relation, privilege, grantee) -%} - grant `{{ privilege }}` on {{ relation.type }} {{ relation }} to {{ '\"' + grantee|join('\", \"') + '\"' }} + {% set relation_type_overrides = { + "materialized_view": "materialized view" + } + %} + {% set relation_type = relation_type_overrides.get(relation.type, relation.type) %} + grant `{{ privilege }}` on {{ relation_type }} {{ relation }} to {{ '\"' + grantee|join('\", \"') + '\"' }} {%- endmacro -%} {%- macro bigquery__get_revoke_sql(relation, privilege, grantee) -%} - revoke `{{ privilege }}` on {{ relation.type }} {{ relation }} from {{ '\"' + grantee|join('\", \"') + '\"' }} + {% set relation_type_overrides = { + "materialized_view": "materialized view" + } + %} + {% set relation_type = relation_type_overrides.get(relation.type, relation.type) %} + revoke `{{ privilege }}` on {{ relation_type }} {{ relation }} from {{ '\"' + grantee|join('\", \"') + '\"' }} {%- endmacro -%}