-
Notifications
You must be signed in to change notification settings - Fork 179
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add record/replay support. * Add group to record types. * Re-organize record/replay code to match dbt-adapters * Add changelog entry. * Update .changes/unreleased/Under the Hood-20240716-174655.yaml Co-authored-by: Colin Rogers <[email protected]> --------- Co-authored-by: Colin Rogers <[email protected]>
- Loading branch information
1 parent
6857e6b
commit d51584d
Showing
7 changed files
with
110 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
kind: Under the Hood | ||
body: Add support for experimental record/replay testing. | ||
time: 2024-07-16T17:46:55.11204-04:00 | ||
custom: | ||
Author: peterallenwebb | ||
Issue: "1106" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
from dbt.adapters.snowflake.record.cursor.cursor import SnowflakeRecordReplayCursor | ||
from dbt.adapters.snowflake.record.handle import SnowflakeRecordReplayHandle |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from dbt_common.record import record_function | ||
|
||
from dbt.adapters.record import RecordReplayCursor | ||
from dbt.adapters.snowflake.record.cursor.sfqid import CursorGetSfqidRecord | ||
from dbt.adapters.snowflake.record.cursor.sqlstate import CursorGetSqlStateRecord | ||
|
||
|
||
class SnowflakeRecordReplayCursor(RecordReplayCursor): | ||
"""A custom extension of RecordReplayCursor that adds the sqlstate | ||
and sfqid properties which are specific to snowflake-connector.""" | ||
|
||
@property | ||
@property | ||
@record_function(CursorGetSqlStateRecord, method=True, id_field_name="connection_name") | ||
def sqlstate(self): | ||
return self.native_cursor.sqlstate | ||
|
||
@property | ||
@record_function(CursorGetSfqidRecord, method=True, id_field_name="connection_name") | ||
def sfqid(self): | ||
return self.native_cursor.sfqid |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import dataclasses | ||
from typing import Optional | ||
|
||
from dbt_common.record import Record, Recorder | ||
|
||
|
||
@dataclasses.dataclass | ||
class CursorGetSfqidParams: | ||
connection_name: str | ||
|
||
|
||
@dataclasses.dataclass | ||
class CursorGetSfqidResult: | ||
msg: Optional[str] | ||
|
||
|
||
@Recorder.register_record_type | ||
class CursorGetSfqidRecord(Record): | ||
params_cls = CursorGetSfqidParams | ||
result_cls = CursorGetSfqidResult | ||
group = "Database" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import dataclasses | ||
from typing import Optional | ||
|
||
from dbt_common.record import Record, Recorder | ||
|
||
|
||
@dataclasses.dataclass | ||
class CursorGetSqlStateParams: | ||
connection_name: str | ||
|
||
|
||
@dataclasses.dataclass | ||
class CursorGetSqlStateResult: | ||
msg: Optional[str] | ||
|
||
|
||
@Recorder.register_record_type | ||
class CursorGetSqlStateRecord(Record): | ||
params_cls = CursorGetSqlStateParams | ||
result_cls = CursorGetSqlStateResult | ||
group = "Database" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from dbt.adapters.record import RecordReplayHandle | ||
|
||
from dbt.adapters.snowflake.record.cursor.cursor import SnowflakeRecordReplayCursor | ||
|
||
|
||
class SnowflakeRecordReplayHandle(RecordReplayHandle): | ||
"""A custom extension of RecordReplayHandle that returns a | ||
snowflake-connector-specific SnowflakeRecordReplayCursor object.""" | ||
|
||
def cursor(self): | ||
cursor = None if self.native_handle is None else self.native_handle.cursor() | ||
return SnowflakeRecordReplayCursor(cursor, self.connection) |