-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Added support for setting policy tags for columns in BigQuery #2589
Merged
beckjake
merged 8 commits into
dbt-labs:dev/marian-anderson
from
azhard:dbt-2586-bigquery-policy-tags
Jul 30, 2020
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
8782714
Added support for setting policy tags for columns in BigQuery
azhard e3193c6
Updated pull request #
azhard 1423318
Changed update_column to update_columns
azhard b964f6d
Rebased
azhard 0a64708
Linting fix
azhard 8ec93d9
bigquery integration test fix
azhard 007cb45
Addressed PR comments
azhard d2c5783
Addressed PR commments
azhard File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -100,6 +100,7 @@ def add( | |
data_type=data_type, | ||
meta=meta, | ||
tags=tags, | ||
_extra=column.extra | ||
) | ||
|
||
@classmethod | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
test/integration/022_bigquery_test/test_bigquery_update_columns.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import os | ||
|
||
from test.integration.base import DBTIntegrationTest, use_profile | ||
|
||
|
||
class TestBigqueryUpdateColumnPolicyTag(DBTIntegrationTest): | ||
|
||
@property | ||
def schema(self): | ||
return "bigquery_test_022" | ||
|
||
@property | ||
def models(self): | ||
return "update-column-policy-tag" | ||
|
||
@property | ||
def project_config(self): | ||
return { | ||
'config-version': 2, | ||
'vars': { | ||
'policy_tag': self.policy_tag | ||
} | ||
} | ||
|
||
@property | ||
def policy_tag(self): | ||
return os.environ.get('BIGQUERY_POLICY_TAG') | ||
|
||
@use_profile('bigquery') | ||
def test__bigquery_update_column_policy_tag(self): | ||
if self.policy_tag: | ||
results = self.run_dbt(['run', '--models', 'policy_tag_table']) | ||
self.assertEqual(len(results), 1) | ||
|
||
with self.get_connection() as conn: | ||
client = conn.handle | ||
|
||
table = client.get_table( | ||
self.adapter.connections.get_bq_table( | ||
self.default_database, self.unique_schema(), 'policy_tag_table') | ||
) | ||
|
||
for schema_field in table.schema: | ||
self.assertEquals(schema_field.policy_tags.names, | ||
(self.policy_tag,)) | ||
|
||
|
||
class TestBigqueryUpdateColumnDescription(DBTIntegrationTest): | ||
|
||
@property | ||
def schema(self): | ||
return "bigquery_test_022" | ||
|
||
@property | ||
def models(self): | ||
return "update-column-description" | ||
|
||
@property | ||
def project_config(self): | ||
return { | ||
'config-version': 2, | ||
'vars': { | ||
'field_description': self.field_description | ||
} | ||
} | ||
|
||
@property | ||
def field_description(self): | ||
return 'this is a field' | ||
|
||
@use_profile('bigquery') | ||
def test__bigquery_update_column_description(self): | ||
results = self.run_dbt(['run', '--models', 'description_table']) | ||
self.assertEqual(len(results), 1) | ||
|
||
with self.get_connection() as conn: | ||
client = conn.handle | ||
|
||
table = client.get_table( | ||
self.adapter.connections.get_bq_table( | ||
self.default_database, self.unique_schema(), 'description_table') | ||
) | ||
|
||
for schema_field in table.schema: | ||
self.assertEquals(schema_field.description, self.field_description) |
9 changes: 9 additions & 0 deletions
9
test/integration/022_bigquery_test/update-column-description/description_table.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{{ | ||
config( | ||
materialized='table', | ||
persist_docs={ 'columns': true } | ||
) | ||
}} | ||
|
||
select | ||
1 field |
7 changes: 7 additions & 0 deletions
7
test/integration/022_bigquery_test/update-column-description/description_table.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
version: 2 | ||
|
||
models: | ||
- name: description_table | ||
columns: | ||
- name: field | ||
description: '{{ var("field_description") }}' |
9 changes: 9 additions & 0 deletions
9
test/integration/022_bigquery_test/update-column-policy-tag/policy_tag_table.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{{ | ||
config( | ||
materialized='table', | ||
persist_docs={ 'columns': true } | ||
) | ||
}} | ||
|
||
select | ||
1 field |
8 changes: 8 additions & 0 deletions
8
test/integration/022_bigquery_test/update-column-policy-tag/policy_tag_table.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
version: 2 | ||
|
||
models: | ||
- name: policy_tag_table | ||
columns: | ||
- name: field | ||
policy_tags: | ||
- '{{ var("policy_tag") }}' |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
does 1.25 specifically add support for policy tags? We had some issues with recent releases of a couple of Google libraries, so I just wanted to double check that bumping this version number is required for this change
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.
Hey @drewbanin, support for policy tags was added in 1.25.0 which is why I updated the version
https://googleapis.dev/python/bigquery/latest/changelog.html