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

Add a configuration option kms_key_name to dbt_project.yml for BigQ… #1851

Merged
merged 6 commits into from
Nov 8, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 2 additions & 1 deletion plugins/bigquery/dbt/adapters/bigquery/impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,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
Expand Down
17 changes: 9 additions & 8 deletions plugins/bigquery/dbt/include/bigquery/macros/adapters.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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) %}
Expand All @@ -36,24 +36,25 @@
{% 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 ~ "'"}) %}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is a lot we can do to make these settings less onerous to manage, especially if we intend to add more of them in the future. For now though, this is a-ok with me

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't say they're too bad to mess with at present, but maybe a pointer to how one might go about it would help.

{% endif %}

{% set options -%}
OPTIONS({% for opt_key, opt_val in opts.items() %}
{{ opt_key }}={{ opt_val }}{{ "," if not loop.last }}
{% endfor %})
{%- endset %}
{% do return(options) %}
OPTIONS({% for opt_key, opt_val in opts.items() %}
kconvey marked this conversation as resolved.
Show resolved Hide resolved
{{ opt_key }}={{ opt_val }}
{% endfor %})
{%- endmacro -%}

{% macro bigquery__create_table_as(temporary, relation, sql) -%}
{%- 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 }}
);
Expand Down