diff --git a/plugins/bigquery/dbt/adapters/bigquery/impl.py b/plugins/bigquery/dbt/adapters/bigquery/impl.py index 648cf2a87e0..5f8027cd86f 100644 --- a/plugins/bigquery/dbt/adapters/bigquery/impl.py +++ b/plugins/bigquery/dbt/adapters/bigquery/impl.py @@ -48,7 +48,8 @@ class BigQueryAdapter(BaseAdapter): Column = BigQueryColumn ConnectionManager = BigQueryConnectionManager - AdapterSpecificConfigs = frozenset({"cluster_by", "partition_by"}) + AdapterSpecificConfigs = frozenset({"cluster_by", "partition_by", + "kms_key_name"}) ### # Implementations of abstract methods diff --git a/plugins/bigquery/dbt/include/bigquery/macros/adapters.sql b/plugins/bigquery/dbt/include/bigquery/macros/adapters.sql index 126e6d3cd0f..944127024f5 100644 --- a/plugins/bigquery/dbt/include/bigquery/macros/adapters.sql +++ b/plugins/bigquery/dbt/include/bigquery/macros/adapters.sql @@ -26,7 +26,7 @@ {%- endmacro -%} -{% macro bigquery_table_options(persist_docs, temporary) %} +{% macro bigquery_table_options(persist_docs, temporary, kms_key_name) %} {% set opts = {} %} {% set description = get_relation_comment(persist_docs, model) %} @@ -36,6 +36,9 @@ {% if temporary %} {% do opts.update({'expiration_timestamp': 'TIMESTAMP_ADD(CURRENT_TIMESTAMP(), INTERVAL 12 hour)'}) %} {% endif %} + {% if kms_key_name %} + {% do opts.update({'kms_key_name': "'" ~ kms_key_name ~ "'"}) %} + {% endif %} {% set options -%} OPTIONS({% for opt_key, opt_val in opts.items() %} @@ -49,11 +52,12 @@ {%- set raw_partition_by = config.get('partition_by', none) -%} {%- set raw_cluster_by = config.get('cluster_by', none) -%} {%- set raw_persist_docs = config.get('persist_docs', {}) -%} + {%- set raw_kms_key_name = config.get('kms_key_name', none) -%} create or replace table {{ relation }} {{ partition_by(raw_partition_by) }} {{ cluster_by(raw_cluster_by) }} - {{ bigquery_table_options(persist_docs=raw_persist_docs, temporary=temporary) }} + {{ bigquery_table_options(persist_docs=raw_persist_docs, temporary=temporary, kms_key_name=raw_kms_key_name) }} as ( {{ sql }} );