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

fix for bq quoting #565

Merged
merged 1 commit into from
Oct 16, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion dbt/context/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ def generate(model, project, flat_graph, provider=None):
"sql_now": adapter.date_function(),
"fromjson": fromjson(model),
"target": target,
"this": dbt.utils.Relation(adapter, model, use_temp=True)
"this": dbt.utils.Relation(profile, adapter, model, use_temp=True)
})

context = _add_tracking(context)
Expand Down
2 changes: 1 addition & 1 deletion dbt/context/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def ref(*args):
dbt.exceptions.ref_invalid_args(model, args)

adapter = get_adapter(profile)
return dbt.utils.Relation(adapter, model)
return dbt.utils.Relation(profile, adapter, model)

return ref

Expand Down
2 changes: 1 addition & 1 deletion dbt/context/runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def do_ref(*args):
model['extra_ctes'][target_model_id] = None

adapter = get_adapter(profile)
return dbt.utils.Relation(adapter, target_model)
return dbt.utils.Relation(profile, adapter, target_model)

return do_ref

Expand Down
27 changes: 18 additions & 9 deletions dbt/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ class ExitCodes(object):


class Relation(object):
def __init__(self, adapter, node, use_temp=False):
self._adapter = adapter

def __init__(self, profile, adapter, node, use_temp=False):
self.node = node
self.schema = node.get('schema')
self.name = node.get('name')
Expand All @@ -48,6 +46,21 @@ def __init__(self, adapter, node, use_temp=False):
self.materialized = get_materialization(node)
self.sql = node.get('injected_sql')

self.do_quote = self._get_quote_function(profile, adapter)

def _get_quote_function(self, profile, adapter):

# make a closure so we don't need to store the profile
# on the `Relation` object. That shouldn't be accessible in user-land
def quote(schema, table):
return adapter.quote_schema_and_table(
profile=profile,
schema=schema,
table=table
)

return quote

def _get_table_name(self, node):
return model_immediate_name(node, dbt.flags.NON_DESTRUCTIVE)

Expand All @@ -56,17 +69,13 @@ def final_name(self):
msg = "final_name() was called on an ephemeral model"
dbt.exceptions.raise_compiler_error(msg, self.node)
else:
return self._adapter.quote_schema_and_table(profile=None,
schema=self.schema,
table=self.name)
return self.do_quote(self.schema, self.name)

def __repr__(self):
if self.materialized == 'ephemeral':
return '__dbt__CTE__{}'.format(self.name)
else:
return self._adapter.quote_schema_and_table(profile=None,
schema=self.schema,
table=self.table)
return self.do_quote(self.schema, self.table)


def coalesce(*args):
Expand Down