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

Add query id to SQLQueryStatus #329

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
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
4 changes: 3 additions & 1 deletion dbt/adapters/contracts/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
dbtClassMixin,
)


# TODO: this is a very bad dependency - shared global state
from dbt_common.events.contextvars import get_node_info
from dbt_common.events.functions import fire_event
Expand All @@ -41,6 +42,7 @@ class AdapterResponse(dbtClassMixin):
_message: str
code: Optional[str] = None
rows_affected: Optional[int] = None
query_id: Optional[str] = None

def __str__(self):
return self._message
Expand Down Expand Up @@ -225,4 +227,4 @@ class AdapterRequiredConfig(HasCredentials, Protocol):
query_comment: QueryComment
cli_vars: Dict[str, Any]
target_path: str
log_cache_events: bool
log_cache_events: bool
2 changes: 1 addition & 1 deletion dbt/adapters/events/adapter_types.proto
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ message SQLQueryStatus {
AdapterNodeInfo node_info = 1;
string status = 2;
float elapsed = 3;
string query_id = 4;
}

message SQLQueryStatusMsg {
Expand Down Expand Up @@ -329,7 +330,6 @@ message CacheActionMsg {
AdapterCommonEventInfo info = 1;
CacheAction data = 2;
}

// Skipping E023, E024, E025, E026, E027, E028, E029, E0230

// E031
Expand Down
205 changes: 103 additions & 102 deletions dbt/adapters/events/adapter_types_pb2.py

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions dbt/adapters/sql/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,13 @@ def add_query(

cursor = connection.handle.cursor()
cursor.execute(sql, bindings)

query_result = self.get_response(cursor)
fire_event(
SQLQueryStatus(
status=str(self.get_response(cursor)),
status=str(query_result),
elapsed=time.perf_counter() - pre,
node_info=get_node_info(),
query_id=query_result.query_id,
)
)

Expand Down
Loading