Skip to content

Commit

Permalink
use exists_ok, not_found_ok, and delete_contents on bigquery dataset …
Browse files Browse the repository at this point in the history
…operations
  • Loading branch information
Jacob Beck committed Nov 4, 2019
1 parent d5c7b0c commit 1ea3cd7
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 19 deletions.
22 changes: 4 additions & 18 deletions plugins/bigquery/dbt/adapters/bigquery/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
2 changes: 1 addition & 1 deletion plugins/bigquery/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)

0 comments on commit 1ea3cd7

Please sign in to comment.