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

Feature/cache relations (#911) #1025

Merged
merged 31 commits into from
Oct 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
ccee039
First pass on caching
Sep 20, 2018
32765ed
add cache verification flag
Sep 24, 2018
cf77a9a
tons of logging
Sep 24, 2018
9f5040d
make jinja templates kinda debuggable by injecting ourselves into the…
Sep 24, 2018
2e4bc56
More test tweaks
Sep 24, 2018
b7b03c7
run most tests in verify mode, at least for now
Sep 24, 2018
418f4ad
pep8, skip text generation in optimized mode
Sep 24, 2018
5163529
add cache clearing
Sep 25, 2018
6e30cd8
slightly better error
Sep 25, 2018
6f43c8f
turn off verification-by-default as threading makes it hard
Sep 25, 2018
d61b28e
add exceptions, remove "kind" field, make the inner Relation referenc…
Sep 25, 2018
69cbb60
remove verify-relation-cche as it is a bad idea due to concurrent tra…
Sep 25, 2018
d359d05
make cache logging a toggle
Sep 25, 2018
fc146be
add missing import
Sep 25, 2018
9b3df57
on failure, do not clear the cache
Sep 25, 2018
4d0abe0
add --bypass-cache flag that ignores using the cache
Sep 25, 2018
2a7cebc
expose get_relation
Sep 25, 2018
f4afd49
Add _is_cached function, optimize get_relation for cache bypassing, a…
Sep 25, 2018
f8a78c3
remove "list_relations" calls in materializations
Sep 25, 2018
2cbae63
go through list_relations for get_relation again, sadly
Sep 25, 2018
a1cc37c
comment/todos/errors cleanup
Sep 25, 2018
7be9115
make jinja debugging unconditional
Sep 25, 2018
3883ad3
docstrings
Sep 26, 2018
57d814f
tests
Sep 26, 2018
780512c
PR feedback
Oct 3, 2018
a03ca11
handle a subtle iteration issue in the cache with extra locking
Oct 3, 2018
8377522
move warning filtering into compatibility module
Oct 4, 2018
ce660cb
fix __copy__/__deepcopy__
Oct 5, 2018
4c928c6
add failing external references test
Oct 9, 2018
c85cb43
if a referenced schema is not in the cache, do not try to add a link …
Oct 9, 2018
0c7ef07
Merge branch 'dev/guion-bluford' into feature/cache-relations
Oct 9, 2018
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
41 changes: 22 additions & 19 deletions dbt/adapters/bigquery/impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ class BigQueryAdapter(PostgresAdapter):
"expand_target_column_types",
"load_dataframe",
"get_missing_columns",
"cache_new_relation",

"create_schema",
"alter_table_add_columns",

# versions of adapter functions that take / return Relations
"list_relations",
"get_relation",
"drop_relation",
"rename_relation",
Expand Down Expand Up @@ -180,7 +180,10 @@ def close(cls, connection):

return connection

def list_relations(self, schema, model_name=None):
def _link_cached_relations(self, manifest, schemas):
pass

def _list_relations(self, schema, model_name=None):
connection = self.get_connection(model_name)
client = connection.handle

Expand All @@ -201,27 +204,27 @@ def list_relations(self, schema, model_name=None):
# This will 404 if the dataset does not exist. This behavior mirrors
# the implementation of list_relations for other adapters
try:
return [self.bq_table_to_relation(table) for table in all_tables]
return [self._bq_table_to_relation(table) for table in all_tables]
except google.api_core.exceptions.NotFound as e:
return []

def get_relation(self, schema=None, identifier=None,
relations_list=None, model_name=None):
if schema is None and relations_list is None:
raise dbt.exceptions.RuntimeException(
'get_relation needs either a schema to query, or a list '
'of relations to use')

if relations_list is None and identifier is not None:
table = self.get_bq_table(schema, identifier)
def get_relation(self, schema, identifier, model_name=None):
if self._schema_is_cached(schema, model_name):
# if it's in the cache, use the parent's model of going through
# the relations cache and picking out the relation
return super(BigQueryAdapter, self).get_relation(
schema=schema,
identifier=identifier,
model_name=model_name
)

return self.bq_table_to_relation(table)

return super(BigQueryAdapter, self).get_relation(
schema, identifier, relations_list,
model_name)
table = self._get_bq_table(schema, identifier)
return self._bq_table_to_relation(table)

def drop_relation(self, relation, model_name=None):
if self._schema_is_cached(relation.schema, model_name):
self.cache.drop(relation)

conn = self.get_connection(model_name)
client = conn.handle

Expand Down Expand Up @@ -515,7 +518,7 @@ def get_dataset(self, dataset_name, model_name=None):
dataset_ref = conn.handle.dataset(dataset_name)
return google.cloud.bigquery.Dataset(dataset_ref)

def bq_table_to_relation(self, bq_table):
def _bq_table_to_relation(self, bq_table):
if bq_table is None:
return None

Expand All @@ -529,7 +532,7 @@ def bq_table_to_relation(self, bq_table):
},
type=self.RELATION_TYPES.get(bq_table.table_type))

def get_bq_table(self, dataset_name, identifier, model_name=None):
def _get_bq_table(self, dataset_name, identifier, model_name=None):
conn = self.get_connection(model_name)

dataset = self.get_dataset(dataset_name, model_name)
Expand Down
Loading