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

Fix include_policy vs. quote_policy bug in BigQueryRelation (#2188) #2325

Merged
merged 1 commit into from
Apr 15, 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 @@ -19,6 +19,7 @@
- Made file names lookups case-insensitve (.sql, .SQL, .yml, .YML) and if .yaml files are found, raise a warning indicating dbt will parse these files in future releases. ([#1681](https://github.com/fishtown-analytics/dbt/issues/1681), [#2263](https://github.com/fishtown-analytics/dbt/pull/2263))
- Return error message when profile is empty in profiles.yml. ([#2292](https://github.com/fishtown-analytics/dbt/issues/2292), [#2297](https://github.com/fishtown-analytics/dbt/pull/2297))
- Fix skipped node count in stdout at the end of a run ([#2095](https://github.com/fishtown-analytics/dbt/issues/2095), [#2310](https://github.com/fishtown-analytics/dbt/pull/2310))
- Fix an issue where BigQuery incorrectly used a relation's quote policy as the basis for the information schema's include policy, instead of the relation's include policy. ([#2188](https://github.com/fishtown-analytics/dbt/issues/2188), [#2325](https://github.com/fishtown-analytics/dbt/pull/2325))

Contributors:
- [@raalsky](https://github.com/Raalsky) ([#2224](https://github.com/fishtown-analytics/dbt/pull/2224), [#2228](https://github.com/fishtown-analytics/dbt/pull/2228))
Expand Down
2 changes: 1 addition & 1 deletion plugins/bigquery/dbt/adapters/bigquery/relation.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def get_include_policy(cls, relation, information_schema_view):
if information_schema_view == '__TABLES__':
identifier = False

return relation.quote_policy.replace(
return relation.include_policy.replace(
schema=schema,
identifier=identifier,
)
Expand Down
55 changes: 55 additions & 0 deletions test/unit/test_bigquery_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from dbt.adapters.bigquery import BigQueryCredentials
from dbt.adapters.bigquery import BigQueryAdapter
from dbt.adapters.bigquery import BigQueryRelation
from dbt.adapters.bigquery.relation import BigQueryInformationSchema
from dbt.adapters.bigquery.connections import BigQueryConnectionManager
from dbt.adapters.base.query_headers import MacroQueryStringSetter
from dbt.clients import agate_helper
Expand Down Expand Up @@ -314,6 +315,60 @@ def test_invalid_relation(self):
BigQueryRelation.from_dict(kwargs)


class TestBigQueryInformationSchema(unittest.TestCase):
def setUp(self):
flags.STRICT_MODE = True

def test_replace(self):

kwargs = {
'type': None,
'path': {
'database': 'test-project',
'schema': 'test_schema',
'identifier': 'my_view'
},
# test for #2188
'quote_policy': {
'database': False
},
'include_policy': {
'database': True,
'schema': True,
'identifier': True,
}
}
relation = BigQueryRelation.from_dict(kwargs)
info_schema = relation.information_schema()

tables_schema = info_schema.replace(information_schema_view='__TABLES__')
assert tables_schema.information_schema_view == '__TABLES__'
assert tables_schema.include_policy.schema is True
assert tables_schema.include_policy.identifier is False
assert tables_schema.include_policy.database is True
assert tables_schema.quote_policy.schema is True
assert tables_schema.quote_policy.identifier is False
assert tables_schema.quote_policy.database is False

schemata_schema = info_schema.replace(information_schema_view='SCHEMATA')
assert schemata_schema.information_schema_view == 'SCHEMATA'
assert schemata_schema.include_policy.schema is False
assert schemata_schema.include_policy.identifier is True
assert schemata_schema.include_policy.database is True
assert schemata_schema.quote_policy.schema is True
assert schemata_schema.quote_policy.identifier is False
assert schemata_schema.quote_policy.database is False

other_schema = info_schema.replace(information_schema_view='SOMETHING_ELSE')
assert other_schema.information_schema_view == 'SOMETHING_ELSE'
assert other_schema.include_policy.schema is True
assert other_schema.include_policy.identifier is True
assert other_schema.include_policy.database is True
assert other_schema.quote_policy.schema is True
assert other_schema.quote_policy.identifier is False
assert other_schema.quote_policy.database is False


class TestBigQueryConnectionManager(unittest.TestCase):

def setUp(self):
Expand Down