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

merged and updated PR for #1031 #1532

Merged
merged 22 commits into from
Jun 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
f4c233a
#1031 Add macro to add table description from schema.yml for BQ
darrenhaken Feb 10, 2019
562d47f
Make changes as per review from @drewbanin
darrenhaken Feb 12, 2019
1131917
Add description for BQ tables and view relations.
darrenhaken Feb 16, 2019
5661855
Merge remote-tracking branch 'upstream/dev/stephen-girard' into dev/s…
darrenhaken Feb 16, 2019
e672042
Merge remote-tracking branch 'upstream/dev/stephen-girard' into dev/s…
darrenhaken Feb 19, 2019
25d5fb1
Add `persist_docs` to project level settings.
darrenhaken Feb 19, 2019
101fd13
Add try catch for the updating config value.
darrenhaken Feb 19, 2019
a1b5375
Add AttributionError to except block
darrenhaken Feb 19, 2019
28fa237
Add tests for the BQ description in the relations
darrenhaken Feb 28, 2019
12bfeaa
Merge remote-tracking branch 'upstream/dev/stephen-girard' into dev/s…
darrenhaken Mar 2, 2019
1e3bdc9
Fix unit tests by adding `persist_docs: {}`
darrenhaken Mar 2, 2019
804a495
Fix BQ integration tests by adding `persist_docs: {}`
darrenhaken Mar 5, 2019
a30cc5e
Add persist_docs to dbt's contract
darrenhaken Mar 5, 2019
9771e63
Merge branch 'dev/stephen-girard' into dev/stephen-girard
drewbanin Mar 19, 2019
6d53e67
Update parsed.py
drewbanin Mar 19, 2019
d59a130
Merge remote-tracking branch 'upstream/dev/stephen-girard' into dev/s…
darrenhaken Apr 1, 2019
8270ef7
Merge branch 'dev/wilt-chamberlain' of github.com:fishtown-analytics/…
darrenhaken Apr 1, 2019
8a8f7a9
Merge branch 'dev/wilt-chamberlain' into build/pr-fixup-1285
drewbanin May 30, 2019
478b17a
fixups
drewbanin May 30, 2019
8ecdab8
fix for pg tests
drewbanin May 30, 2019
ffb38a2
redshift tests
Jun 12, 2019
2d84dd4
Merge branch 'dev/wilt-chamberlain' into build/pr-fixup-1285
Jun 12, 2019
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
8 changes: 6 additions & 2 deletions core/dbt/contracts/graph/parsed.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@
'materialized': {
'type': 'string',
},
'persist_docs': {
'type': 'object',
'additionalProperties': True,
},
'post-hook': {
'type': 'array',
'items': HOOK_CONTRACT,
Expand Down Expand Up @@ -86,8 +90,8 @@
},
'required': [
'enabled', 'materialized', 'post-hook', 'pre-hook', 'vars',
'quoting', 'column_types', 'tags'
],
'quoting', 'column_types', 'tags', 'persist_docs'
]
}


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{% macro table_options() %}
{%- set raw_persist_docs = config.get('persist_docs', {}) -%}

{%- endmacro -%}

{% macro get_relation_comment(persist_docs, model) %}

{%- if persist_docs is not mapping -%}
{{ exceptions.raise_compiler_error("Invalid value provided for 'persist_docs'. Expected dict but got value: " ~ raw_persist_docs) }}
{% endif %}

{% if persist_docs.get('relation', false) %}
{{ return((model.description | tojson)[1:-1]) }}
{%- else -%}
{{ return(none) }}
{% endif %}

{% endmacro %}
7 changes: 4 additions & 3 deletions core/dbt/parser/source_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

class SourceConfig(object):
AppendListFields = {'pre-hook', 'post-hook', 'tags'}
ExtendDictFields = {'vars', 'column_types', 'quoting'}
ExtendDictFields = {'vars', 'column_types', 'quoting', 'persist_docs'}
ClobberFields = {
'alias',
'schema',
Expand Down Expand Up @@ -100,11 +100,12 @@ def update_in_model_config(self, config):
self.in_model_config[key] = current
elif key in self.ExtendDictFields:
current = self.in_model_config.get(key, {})
if not isinstance(current, dict):
try:
current.update(value)
except (ValueError, TypeError, AttributeError):
dbt.exceptions.raise_compiler_error(
'Invalid config field: "{}" must be a dict'.format(key)
)
current.update(value)
self.in_model_config[key] = current
else: # key in self.ClobberFields or self.AdapterSpecificConfigs
self.in_model_config[key] = value
Expand Down
28 changes: 22 additions & 6 deletions plugins/bigquery/dbt/include/bigquery/macros/adapters.sql
Original file line number Diff line number Diff line change
Expand Up @@ -26,27 +26,43 @@

{%- endmacro -%}

{% macro bigquery_table_options(persist_docs, temporary) %}
{% set opts = {} %}

{% set description = get_relation_comment(persist_docs, model) %}
{%- if description is not none -%}
{% do opts.update({'description': "'" ~ description ~ "'"}) %}
{% endif %}
{% if temporary %}
{% do opts.update({'expiration_timestamp': 'TIMESTAMP_ADD(CURRENT_TIMESTAMP(), INTERVAL 12 hour)'}) %}
{% endif %}

OPTIONS({% for opt_key, opt_val in opts.items() %}
{{ 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', {}) -%}

create or replace table {{ relation }}
{{ partition_by(raw_partition_by) }}
{{ cluster_by(raw_cluster_by) }}
{% if temporary %}
OPTIONS(
expiration_timestamp=TIMESTAMP_ADD(CURRENT_TIMESTAMP(), INTERVAL 12 hour)
)
{% endif %}
{{ bigquery_table_options(persist_docs=raw_persist_docs, temporary=temporary) }}
as (
{{ sql }}
);
{% endmacro %}


{% macro bigquery__create_view_as(relation, sql) -%}
create or replace view {{ relation }} as (
{%- set raw_persist_docs = config.get('persist_docs', {}) -%}

create or replace view {{ relation }}
{{ bigquery_table_options(persist_docs=raw_persist_docs, temporary=false) }}
as (
{{ sql }}
);
{% endmacro %}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{{
config(
materialized = "incremental",
unique_key = "id"
unique_key = "id",
persist_docs = {"relation": true}
)
}}

Expand Down
14 changes: 14 additions & 0 deletions test/integration/022_bigquery_test/models/schema.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
version: 2
models:
- name: view_model
description: |
View model description "with double quotes"
and with 'single quotes' as welll as other;
'''abc123'''
reserved -- characters
--
/* comment */
columns:
- name: dupe
tests:
Expand All @@ -17,6 +24,13 @@ models:
name: view_model
type: view
- name: table_model
description: |
View model description "with double quotes"
and with 'single quotes' as welll as other;
'''abc123'''
reserved -- characters
--
/* comment */
columns:
- name: id
tests:
Expand Down
8 changes: 6 additions & 2 deletions test/integration/022_bigquery_test/models/table_model.sql
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@

{{ config(materialized = "table") }}
{{
config(
materialized = "table",
persist_docs={ "relation": true, "columns": true, "schema": true }
)
}}

select * from {{ ref('view_model') }}
3 changes: 2 additions & 1 deletion test/integration/022_bigquery_test/models/view_model.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{{
config(
materialized = "view"
materialized = "view",
persist_docs={ "relation": true, "columns": true, "schema": true }
)
}}

Expand Down
Loading