Skip to content

Commit

Permalink
a slight rework of 955 to keep a seperation of concerns (#957)
Browse files Browse the repository at this point in the history
* a slight rework of 955 to keep a seperation of concerns

* move query_header back into inital if, save assignement for truthy, else return empty dict
  • Loading branch information
McKnight-42 authored Oct 6, 2023
1 parent d5b4114 commit 3e8d389
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions dbt/adapters/bigquery/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,18 @@ def get_table_from_response(cls, resp):
column_names = [field.name for field in resp.schema]
return agate_helper.table_from_data_flat(resp, column_names)

def get_labels_from_query_comment(cls):
if (
hasattr(cls.profile, "query_comment")
and cls.profile.query_comment
and cls.profile.query_comment.job_label
and cls.query_header
):
query_comment = cls.query_header.comment.query_comment
return cls._labels_from_query_comment(query_comment)

return {}

def raw_execute(
self,
sql,
Expand All @@ -447,16 +459,7 @@ def raw_execute(

fire_event(SQLQuery(conn_name=conn.name, sql=sql, node_info=get_node_info()))

if (
hasattr(self.profile, "query_comment")
and self.profile.query_comment
and self.profile.query_comment.job_label
and self.query_header
and (query_comment := self.query_header.comment.query_comment)
):
labels = self._labels_from_query_comment(query_comment)
else:
labels = {}
labels = self.get_labels_from_query_comment()

if active_user:
labels["dbt_invocation_id"] = active_user.invocation_id
Expand Down

0 comments on commit 3e8d389

Please sign in to comment.