Skip to content

Commit

Permalink
Fix #2188
Browse files Browse the repository at this point in the history
The BigQuery information schema previously used its quote policy as the basis
for a new include policy, rather than its include policy.
  • Loading branch information
Jacob Beck committed Apr 14, 2020
1 parent 79db880 commit 126fb47
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 1 deletion.
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:/fishtown-analytics/dbt/issues/1681), [#2263](https:/fishtown-analytics/dbt/pull/2263))
- Return error message when profile is empty in profiles.yml. ([#2292](https:/fishtown-analytics/dbt/issues/2292), [#2297](https:/fishtown-analytics/dbt/pull/2297))
- Fix skipped node count in stdout at the end of a run ([#2095](https:/fishtown-analytics/dbt/issues/2095), [#2310](https:/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:/fishtown-analytics/dbt/issues/2188), [#2325](https:/fishtown-analytics/dbt/pull/2325))

Contributors:
- [@raalsky](https:/Raalsky) ([#2224](https:/fishtown-analytics/dbt/pull/2224), [#2228](https:/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 tables_schema.quote_policy.schema is True
assert tables_schema.quote_policy.identifier is False
assert tables_schema.quote_policy.database is False

other_schema = info_schema.replace(information_schema_view='SOMETHING_ELSE')
assert other_schema.information_schema_view == 'SCHEMATA'
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 tables_schema.quote_policy.schema is True
assert tables_schema.quote_policy.identifier is False
assert tables_schema.quote_policy.database is False


class TestBigQueryConnectionManager(unittest.TestCase):

def setUp(self):
Expand Down

0 comments on commit 126fb47

Please sign in to comment.