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 of last executed statement to Adapter Response #891

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
18 changes: 17 additions & 1 deletion dbt/adapters/redshift/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ class RedshiftSSLMode(StrEnum):
}


@dataclass
class RedshiftAdapterResponse(AdapterResponse):
query_id: int = -1


@dataclass
class RedshiftSSLConfig(dbtClassMixin, Replaceable): # type: ignore
ssl: bool = True
Expand Down Expand Up @@ -314,13 +319,24 @@ def _get_backend_pid(cls, connection):
res = c.execute(sql).fetchone()
return res[0]

@classmethod
def _get_last_query_id(cls, cursor):
sql = "select pg_last_query_id();"
res = cursor.execute(sql).fetchone()
return res[0]

@classmethod
def get_response(cls, cursor: redshift_connector.Cursor) -> AdapterResponse:
# redshift_connector.Cursor doesn't have a status message attribute but
# this function is only used for successful run, so we can just return a dummy
rows = cursor.rowcount
message = "SUCCESS"
return AdapterResponse(_message=message, rows_affected=rows)
query_id = cls._get_last_query_id(cursor)
return RedshiftAdapterResponse(
_message=message,
rows_affected=rows,
query_id=query_id,
)

@contextmanager
def exception_handler(self, sql):
Expand Down