-
Notifications
You must be signed in to change notification settings - Fork 159
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
fix: alter table description without full_refresh #1139
base: main
Are you sure you want to change the base?
fix: alter table description without full_refresh #1139
Conversation
Thanks for your pull request, and welcome to our community! We require contributors to sign our Contributor License Agreement and we don't seem to have your signature on file. Check out this article for more information on why we have a CLA. In order for us to review and merge your code, please submit the Individual Contributor License Agreement form attached above above. If you have questions about the CLA, or if you believe you've received this message in error, please reach out through a comment on this PR. CLA has not been signed by users: @kiwamizamurai |
@cla-bot |
@colin-rogers-dbt |
Changelog file might be required? |
see #1138 (comment) |
Could you review my PR? |
@@ -99,6 +99,7 @@ | |||
{% macro bigquery__persist_docs(relation, model, for_relation, for_columns) -%} | |||
{% if for_columns and config.persist_column_docs() and model.columns %} | |||
{% do alter_column_comment(relation, model.columns) %} | |||
{% do adapter.update_table_description(relation, model.description) %} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
currently this is within the if
that has to do with column
comments.
perhaps there needs to be a new if
that is something like the below. that said, I'm very confused about the purpose of for_relation
and for_columns
{% do adapter.update_table_description(relation, model.description) %} | |
{% if for_relation and config.persist_relation_docs() and model.description %} | |
{% do adapter.update_table_description(relation, model.description) %} | |
{% endif %} |
Actually it looks like the seed
materialization is already doing something very similar.
dbt-bigquery/dbt/include/bigquery/macros/materializations/seed.sql
Lines 20 to 23 in 978a1ae
{% if config.persist_relation_docs() and 'description' in model %} | |
{{ adapter.update_table_description(model['database'], model['schema'], model['alias'], model['description']) }} | |
{% endif %} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dataders
let me remind you
In my local environment, I checked that the code works fine.
However, I'm not sure how to write the test, could you please help me?
import pytest
from dbt.tests.util import relation_from_name, get_connection, run_dbt
from dbt.adapters.bigquery import BigQueryRelation
_TABLE_DESCRIPTION_MODEL = """{{
config(
materialized='incremental',
persist_docs={ 'relation': true }
)
}}
select 1 as first_col
from unnest([struct(1 as dual)]) as dual
{% if is_incremental() %}
where 1=1
{% endif %}
"""
_TABLE_DESCRIPTION_MODEL_NAME = "table_description_model"
_TABLE_DESCRIPTION = "this is not a field"
_TABLE_DESCRIPTION_MODEL_YML = """
version: 2
models:
- name: table_description_model
description: '{{ var("table_description") }}'
"""
class TestBigqueryUpdateTableDescription:
@pytest.fixture(scope="class")
def project_config_update(self):
return {"config-version": 2, "vars": {"table_description": _TABLE_DESCRIPTION}}
@pytest.fixture(scope="class")
def models(self):
return {
f"{_TABLE_DESCRIPTION_MODEL_NAME}.sql": _TABLE_DESCRIPTION_MODEL,
"schema.yml": _TABLE_DESCRIPTION_MODEL_YML,
}
def test_bigquery_update_table_description(self, project):
results = run_dbt(["run"])
assert len(results) == 1
# TODO update docs
results = run_dbt(["run"])
assert len(results) == 1
relation: BigQueryRelation = relation_from_name(
project.adapter, _TABLE_DESCRIPTION_MODEL_NAME
)
adapter = project.adapter
with get_connection(project.adapter) as conn:
table = conn.handle.get_table(
adapter.connections.get_bq_table(
relation.database, relation.schema, relation.table
)
)
assert table.description == _TABLE_DESCRIPTION
Co-authored-by: Colin Rogers <[email protected]>
Hi @kiwamizamurai any updates on this PR? |
@colin-rogers-dbt |
resolves #1138
docs dbt-labs/docs.getdbt.com/#
Problem
when materialization is incremental, table description does not be updated.
Solution
I implemented the method that alters the table description without table recreation.
Checklist