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

On bigquery, persist docs for seeds as well as tables/views #2601

Merged
merged 3 commits into from
Jun 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
### Fixes
- dbt native rendering now avoids turning quoted strings into unquoted strings ([#2597](https://github.com/fishtown-analytics/dbt/issues/2597), [#2599](https://github.com/fishtown-analytics/dbt/pull/2599))
- Hash name of local packages ([#2600](https://github.com/fishtown-analytics/dbt/pull/2600))
- On bigquery, also persist docs for seeds ([#2598](https://github.com/fishtown-analytics/dbt/issues/2598), [#2601](https://github.com/fishtown-analytics/dbt/pull/2601))
- Swallow all file-writing related errors on Windows, regardless of path length or exception type. ([#2603](https://github.com/fishtown-analytics/dbt/pull/2603))


Expand Down
17 changes: 17 additions & 0 deletions plugins/bigquery/dbt/adapters/bigquery/impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,23 @@ def update_column_descriptions(self, relation, columns):
new_table = google.cloud.bigquery.Table(table_ref, schema=new_schema)
conn.handle.update_table(new_table, ['schema'])

@available.parse_none
def update_table_description(
self, database: str, schema: str, identifier: str, description: str
):
conn = self.connections.get_thread_connection()
client = conn.handle

table_ref = self.connections.table_ref(
database,
schema,
identifier,
conn
)
table = client.get_table(table_ref)
table.description = description
client.update_table(table, ['description'])

@available.parse_none
def alter_table_add_columns(self, relation, columns):

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,8 @@
{%- set column_override = model['config'].get('column_types', {}) -%}
{{ adapter.load_dataframe(model['database'], model['schema'], model['alias'],
agate_table, column_override) }}
{% if config.persist_relation_docs() and 'description' in model %}

{{ adapter.update_table_description(model['database'], model['schema'], model['alias'], model['description']) }}
{% endif %}
{% endmacro %}
3 changes: 3 additions & 0 deletions test/integration/060_persist_docs_tests/data/seed.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
id,name
1,Alice
2,Bob
25 changes: 25 additions & 0 deletions test/integration/060_persist_docs_tests/models/schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,28 @@ models:
--
/* comment */
Some $lbl$ labeled $lbl$ and $$ unlabeled $$ dollar-quoting

seeds:
- name: seed
description: |
Seed model description "with double quotes"
and with 'single quotes' as welll as other;
'''abc123'''
reserved -- characters
--
/* comment */
Some $lbl$ labeled $lbl$ and $$ unlabeled $$ dollar-quoting
columns:
- name: id
description: |
id Column description "with double quotes"
and with 'single quotes' as welll as other;
'''abc123'''
reserved -- characters
--
/* comment */
Some $lbl$ labeled $lbl$ and $$ unlabeled $$ dollar-quoting
- name: name
description: |
Some stuff here and then a call to
{{ doc('my_fun_doc')}}
37 changes: 35 additions & 2 deletions test/integration/060_persist_docs_tests/test_persist_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,15 @@ def project_config(self):
"columns": True,
},
}
}
},
'seeds': {
'test': {
'+persist_docs': {
"relation": True,
"columns": True,
},
}
},
}

@use_profile('snowflake')
Expand All @@ -157,7 +165,31 @@ def test_snowflake_persist_docs(self):

@use_profile('bigquery')
def test_bigquery_persist_docs(self):
self.run_dbt(['seed'])
self.run_dbt()
desc_map = {
'seed': 'Seed model description',
'table_model': 'Table model description',
'view_model': 'View model description',
}
for node_id in ['seed', 'table_model', 'view_model']:
with self.adapter.connection_named('_test'):
client = self.adapter.connections \
.get_thread_connection().handle

table_id = "{}.{}.{}".format(
self.default_database,
self.unique_schema(),
node_id
)
bq_table = client.get_table(table_id)

bq_schema = bq_table.schema

assert bq_table.description.startswith(desc_map[node_id])
assert bq_schema[0].description.startswith('id Column description ')
if not node_id.startswith('view'):
assert bq_schema[1].description.startswith('Some stuff here and then a call to')


class TestPersistDocsNested(BasePersistDocsTest):
Expand Down Expand Up @@ -187,13 +219,14 @@ def test_bigquery_persist_docs(self):

Next, generate the catalog and check if the comments are also included.
"""
self.run_dbt(['seed'])
self.run_dbt()

self.run_dbt(['docs', 'generate'])
with open('target/catalog.json') as fp:
catalog_data = json.load(fp)
assert 'nodes' in catalog_data
assert len(catalog_data['nodes']) == 2 # table and view model
assert len(catalog_data['nodes']) == 3 # seed, table, and view model

for node_id in ['table_model_nested', 'view_model_nested']:
# check the descriptions using the api
Expand Down