Skip to content

Commit

Permalink
fix: Fix grants statements on materialized views
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
AcidFlow committed Jun 25, 2024
1 parent 0627aa2 commit 5712dcf
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions dbt/include/bigquery/macros/adapters/apply_grants.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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 -%}

0 comments on commit 5712dcf

Please sign in to comment.