From 5ce7aa7f19701935517a894b3d5a123486bb756c Mon Sep 17 00:00:00 2001 From: Drew Banin Date: Mon, 9 Apr 2018 15:38:47 -0400 Subject: [PATCH] Implement relations api dp fix (#729) * fix bq date partitioning * fix for context vars (tmp table name) --- dbt/adapters/default/impl.py | 2 +- dbt/adapters/default/relation.py | 7 +++++-- .../macros/materializations/table/bigquery_table.sql | 4 +++- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/dbt/adapters/default/impl.py b/dbt/adapters/default/impl.py index 8178a5a68a2..39740155d8c 100644 --- a/dbt/adapters/default/impl.py +++ b/dbt/adapters/default/impl.py @@ -695,7 +695,7 @@ def drop_schema(cls, profile, schema, model_name=None): @classmethod def already_exists(cls, profile, schema, table, model_name=None): # TODO add deprecation warning - relation = cls.get_relation(schema=schema, identifier=table) + relation = cls.get_relation(profile, schema=schema, identifier=table) return relation is not None @classmethod diff --git a/dbt/adapters/default/relation.py b/dbt/adapters/default/relation.py index 831939b5f36..3f153dffc65 100644 --- a/dbt/adapters/default/relation.py +++ b/dbt/adapters/default/relation.py @@ -127,6 +127,8 @@ def render(self): if path_part is None: continue + elif k == 'identifier': + path_part = self.table parts.append( self.quote_if( @@ -156,7 +158,8 @@ def create_from_node(cls, profile, node, table_name=None, **kwargs): return cls.create( database=profile.get('dbname'), schema=node.get('schema'), - identifier=table_name or node.get('name'), + identifier=node.get('name'), + table_name=table_name, **kwargs) @classmethod @@ -205,7 +208,7 @@ def name(self): # Here for compatibility with old Relation interface @property def table(self): - return self._table_name + return self.table_name @property def is_table(self): diff --git a/dbt/include/global_project/macros/materializations/table/bigquery_table.sql b/dbt/include/global_project/macros/materializations/table/bigquery_table.sql index 2c3db882381..3c50969bbab 100644 --- a/dbt/include/global_project/macros/materializations/table/bigquery_table.sql +++ b/dbt/include/global_project/macros/materializations/table/bigquery_table.sql @@ -62,7 +62,9 @@ -- build model {% if partitions %} - {{ make_date_partitioned_table(model, target_relation, partitions, exists_not_as_table, verbose) }} + {# Create the dp-table if 1. it does not exist or 2. it existed, but we just dropped it #} + {%- set should_create = (old_relation is none or exists_not_as_table) -%} + {{ make_date_partitioned_table(model, target_relation, partitions, should_create, verbose) }} {% else %} {% call statement('main') -%} {{ create_table_as(False, target_relation, sql) }}