-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2589 from azhard/dbt-2586-bigquery-policy-tags
Added support for setting policy tags for columns in BigQuery
- Loading branch information
Showing
14 changed files
with
138 additions
and
7 deletions.
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") }}' |