diff --git a/plugins/bigquery/dbt/adapters/bigquery/connections.py b/plugins/bigquery/dbt/adapters/bigquery/connections.py index 5b3c600c452..50b14702c6f 100644 --- a/plugins/bigquery/dbt/adapters/bigquery/connections.py +++ b/plugins/bigquery/dbt/adapters/bigquery/connections.py @@ -294,28 +294,14 @@ def drop_dataset(self, database, schema): client = conn.handle with self.exception_handler('drop dataset'): - try: - tables = list(client.list_tables(dataset)) - except google.api_core.exceptions.NotFound: - # the dataset doesn't exist. return here to match - # 'drop schema if exists' behavior. If anything 404s after this - # then there are real problems that should cause us to raise. - return - for table in tables: - client.delete_table(table.reference) - client.delete_dataset(dataset) + client.delete_dataset( + dataset, delete_contents=True, not_found_ok=True + ) def create_dataset(self, database, schema): conn = self.get_thread_connection() client = conn.handle dataset = self.dataset(database, schema, conn) - # Emulate 'create schema if not exists ...' - try: - client.get_dataset(dataset) - return - except google.api_core.exceptions.NotFound: - pass - with self.exception_handler('create dataset'): - client.create_dataset(dataset) + client.create_dataset(dataset, exists_ok=True) diff --git a/plugins/bigquery/setup.py b/plugins/bigquery/setup.py index 83ccb3550cf..d58743529d2 100644 --- a/plugins/bigquery/setup.py +++ b/plugins/bigquery/setup.py @@ -30,7 +30,7 @@ }, install_requires=[ 'dbt-core=={}'.format(package_version), - 'google-cloud-bigquery>=1.0.0,<2', + 'google-cloud-bigquery>=1.15.0,<2', ], zip_safe=False, )