Skip to content

Commit

Permalink
Support DIFF as a recording mode (#10263)
Browse files Browse the repository at this point in the history
* add diffing

* WIP

* change file name

* Update core/dbt/cli/requires.py
  • Loading branch information
emmyoop authored Jun 20, 2024
1 parent d389ff1 commit 51ff85b
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions core/dbt/cli/requires.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
Recorder,
RecorderMode,
get_record_mode_from_env,
get_record_types_from_dict,
get_record_types_from_env,
)
from dbt_common.utils import cast_dict_to_dict_of_strings
Expand Down Expand Up @@ -110,8 +111,17 @@ def setup_record_replay():

recorder: Optional[Recorder] = None
if rec_mode == RecorderMode.REPLAY:
recording_path = os.environ.get("DBT_RECORDER_FILE_PATH")
recorder = Recorder(RecorderMode.REPLAY, types=rec_types, recording_path=recording_path)
previous_recording_path = os.environ.get("DBT_RECORDER_FILE_PATH")
recorder = Recorder(
RecorderMode.REPLAY, types=rec_types, previous_recording_path=previous_recording_path
)
elif rec_mode == RecorderMode.DIFF:
previous_recording_path = os.environ.get("DBT_RECORDER_FILE_PATH")
# ensure types match the previous recording
types = get_record_types_from_dict(previous_recording_path)
recorder = Recorder(
RecorderMode.DIFF, types=types, previous_recording_path=previous_recording_path
)
elif rec_mode == RecorderMode.RECORD:
recorder = Recorder(RecorderMode.RECORD, types=rec_types)

Expand All @@ -122,7 +132,10 @@ def tear_down_record_replay():
recorder = get_invocation_context().recorder
if recorder is not None:
if recorder.mode == RecorderMode.RECORD:
recorder.write("recording.json")
recorder.write()
if recorder.mode == RecorderMode.DIFF:
recorder.write()
recorder.write_diffs(diff_file_name="recording_diffs.json")
elif recorder.mode == RecorderMode.REPLAY:
recorder.write_diffs("replay_diffs.json")

Expand Down

0 comments on commit 51ff85b

Please sign in to comment.