-
Notifications
You must be signed in to change notification settings - Fork 377
Expand file tree
/
Copy pathconsole.py
More file actions
4349 lines (3675 loc) · 167 KB
/
console.py
File metadata and controls
4349 lines (3675 loc) · 167 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
from __future__ import annotations
import abc
import datetime
import typing as t
import unittest
import uuid
import logging
import textwrap
from humanize import metric, naturalsize
from itertools import zip_longest
from pathlib import Path
from hyperscript import h
from rich.console import Console as RichConsole
from rich.live import Live
from rich.progress import (
BarColumn,
Progress,
SpinnerColumn,
TaskID,
TextColumn,
TimeElapsedColumn,
)
from rich.prompt import Confirm, Prompt
from rich.status import Status
from rich.syntax import Syntax
from rich.table import Table
from rich.tree import Tree
from sqlglot import exp
from sqlmesh.core.schema_diff import TableAlterOperation
from sqlmesh.core.test.result import ModelTextTestResult
from sqlmesh.core.environment import EnvironmentNamingInfo, EnvironmentSummary
from sqlmesh.core.linter.rule import RuleViolation
from sqlmesh.core.model import Model
from sqlmesh.core.snapshot import (
Snapshot,
SnapshotChangeCategory,
SnapshotId,
SnapshotInfoLike,
)
from sqlmesh.core.snapshot.definition import Interval, Intervals, SnapshotTableInfo
from sqlmesh.core.snapshot.execution_tracker import QueryExecutionStats
from sqlmesh.core.test import ModelTest
from sqlmesh.utils import rich as srich
from sqlmesh.utils import Verbosity
from sqlmesh.utils.concurrency import NodeExecutionFailedError
from sqlmesh.utils.date import time_like_to_str, to_date, yesterday_ds, to_ds, make_inclusive
from sqlmesh.utils.errors import (
PythonModelEvalError,
NodeAuditsErrors,
format_destructive_change_msg,
format_additive_change_msg,
)
from sqlmesh.utils.rich import strip_ansi_codes
if t.TYPE_CHECKING:
import ipywidgets as widgets
from sqlglot import exp
from sqlglot.dialects.dialect import DialectType
from sqlmesh.core.context_diff import ContextDiff
from sqlmesh.core.plan import Plan, EvaluatablePlan, PlanBuilder, SnapshotIntervals
from sqlmesh.core.table_diff import TableDiff, RowDiff, SchemaDiff
from sqlmesh.core.config.connection import ConnectionConfig
from sqlmesh.core.state_sync import Versions
LayoutWidget = t.TypeVar("LayoutWidget", bound=t.Union[widgets.VBox, widgets.HBox])
logger = logging.getLogger(__name__)
SNAPSHOT_CHANGE_CATEGORY_STR = {
None: "Unknown",
SnapshotChangeCategory.BREAKING: "Breaking",
SnapshotChangeCategory.NON_BREAKING: "Non-breaking",
SnapshotChangeCategory.FORWARD_ONLY: "Forward-only",
SnapshotChangeCategory.INDIRECT_BREAKING: "Indirect Breaking",
SnapshotChangeCategory.INDIRECT_NON_BREAKING: "Indirect Non-breaking",
SnapshotChangeCategory.METADATA: "Metadata",
}
PROGRESS_BAR_WIDTH = 40
LINE_WRAP_WIDTH = 100
class LinterConsole(abc.ABC):
"""Console for displaying linter violations"""
@abc.abstractmethod
def show_linter_violations(
self, violations: t.List[RuleViolation], model: Model, is_error: bool = False
) -> None:
"""Prints all linter violations depending on their severity"""
class StateExporterConsole(abc.ABC):
"""Console for describing a state export"""
@abc.abstractmethod
def start_state_export(
self,
output_file: Path,
gateway: t.Optional[str] = None,
state_connection_config: t.Optional[ConnectionConfig] = None,
environment_names: t.Optional[t.List[str]] = None,
local_only: bool = False,
confirm: bool = True,
) -> bool:
"""State a state export"""
@abc.abstractmethod
def update_state_export_progress(
self,
version_count: t.Optional[int] = None,
versions_complete: bool = False,
snapshot_count: t.Optional[int] = None,
snapshots_complete: bool = False,
environment_count: t.Optional[int] = None,
environments_complete: bool = False,
) -> None:
"""Update the state export progress"""
@abc.abstractmethod
def stop_state_export(self, success: bool, output_file: Path) -> None:
"""Finish a state export"""
class StateImporterConsole(abc.ABC):
"""Console for describing a state import"""
@abc.abstractmethod
def start_state_import(
self,
input_file: Path,
gateway: str,
state_connection_config: ConnectionConfig,
clear: bool = False,
confirm: bool = True,
) -> bool:
"""Start a state import"""
@abc.abstractmethod
def update_state_import_progress(
self,
timestamp: t.Optional[str] = None,
state_file_version: t.Optional[int] = None,
versions: t.Optional[Versions] = None,
snapshot_count: t.Optional[int] = None,
snapshots_complete: bool = False,
environment_count: t.Optional[int] = None,
environments_complete: bool = False,
) -> None:
"""Update the state import process"""
@abc.abstractmethod
def stop_state_import(self, success: bool, input_file: Path) -> None:
"""Finish a state import"""
class JanitorConsole(abc.ABC):
"""Console for describing a janitor / snapshot cleanup run"""
@abc.abstractmethod
def start_cleanup(self, ignore_ttl: bool) -> bool:
"""Start a janitor / snapshot cleanup run.
Args:
ignore_ttl: Indicates that the user wants to ignore the snapshot TTL and clean up everything not promoted to an environment
Returns:
Whether or not the cleanup run should proceed
"""
@abc.abstractmethod
def update_cleanup_progress(self, object_name: str) -> None:
"""Update the snapshot cleanup progress."""
@abc.abstractmethod
def stop_cleanup(self, success: bool = True) -> None:
"""Indicates the janitor / snapshot cleanup run has ended
Args:
success: Whether or not the cleanup completed successfully
"""
class DestroyConsole(abc.ABC):
"""Console for describing a destroy operation"""
@abc.abstractmethod
def start_destroy(
self,
schemas_to_delete: t.Optional[t.Set[str]] = None,
views_to_delete: t.Optional[t.Set[str]] = None,
tables_to_delete: t.Optional[t.Set[str]] = None,
) -> bool:
"""Start a destroy operation.
Args:
schemas_to_delete: Set of schemas that will be deleted
views_to_delete: Set of views that will be deleted
tables_to_delete: Set of tables that will be deleted
Returns:
Whether or not the destroy operation should proceed
"""
@abc.abstractmethod
def stop_destroy(self, success: bool = True) -> None:
"""Indicates the destroy operation has ended
Args:
success: Whether or not the cleanup completed successfully
"""
class EnvironmentsConsole(abc.ABC):
"""Console for displaying environments"""
@abc.abstractmethod
def print_environments(self, environments_summary: t.List[EnvironmentSummary]) -> None:
"""Prints all environment names along with expiry datetime."""
@abc.abstractmethod
def show_intervals(self, snapshot_intervals: t.Dict[Snapshot, SnapshotIntervals]) -> None:
"""Show ready intervals"""
class DifferenceConsole(abc.ABC):
"""Console for displaying environment differences"""
@abc.abstractmethod
def show_environment_difference_summary(
self,
context_diff: ContextDiff,
no_diff: bool = True,
) -> None:
"""Displays a summary of differences for the environment."""
@abc.abstractmethod
def show_model_difference_summary(
self,
context_diff: ContextDiff,
environment_naming_info: EnvironmentNamingInfo,
default_catalog: t.Optional[str],
no_diff: bool = True,
) -> None:
"""Displays a summary of differences for the given models."""
class TableDiffConsole(abc.ABC):
"""Console for displaying table differences"""
@abc.abstractmethod
def show_table_diff(
self,
table_diffs: t.List[TableDiff],
show_sample: bool = True,
skip_grain_check: bool = False,
temp_schema: t.Optional[str] = None,
) -> None:
"""Display the table diff between two or multiple tables."""
@abc.abstractmethod
def update_table_diff_progress(self, model: str) -> None:
"""Update table diff progress bar"""
@abc.abstractmethod
def start_table_diff_progress(self, models_to_diff: int) -> None:
"""Start table diff progress bar"""
@abc.abstractmethod
def start_table_diff_model_progress(self, model: str) -> None:
"""Start table diff model progress"""
@abc.abstractmethod
def stop_table_diff_progress(self, success: bool) -> None:
"""Stop table diff progress bar"""
@abc.abstractmethod
def show_table_diff_details(
self,
models_to_diff: t.List[str],
) -> None:
"""Display information about which tables are going to be diffed"""
@abc.abstractmethod
def show_table_diff_summary(self, table_diff: TableDiff) -> None:
"""Display information about the tables being diffed and how they are being joined"""
@abc.abstractmethod
def show_schema_diff(self, schema_diff: SchemaDiff) -> None:
"""Show table schema diff."""
@abc.abstractmethod
def show_row_diff(
self, row_diff: RowDiff, show_sample: bool = True, skip_grain_check: bool = False
) -> None:
"""Show table summary diff."""
class BaseConsole(abc.ABC):
@abc.abstractmethod
def log_error(self, message: str, *args: t.Any, **kwargs: t.Any) -> None:
"""Display error info to the user."""
@abc.abstractmethod
def log_warning(
self,
short_message: str,
long_message: t.Optional[str] = None,
*args: t.Any,
**kwargs: t.Any,
) -> None:
"""Display warning info to the user.
Args:
short_message: The warning message to print to console.
long_message: The warning message to log to file. If not provided, `short_message` is used.
"""
@abc.abstractmethod
def log_success(self, message: str) -> None:
"""Display a general successful message to the user."""
class PlanBuilderConsole(BaseConsole, abc.ABC):
@abc.abstractmethod
def log_destructive_change(
self,
snapshot_name: str,
alter_operations: t.List[TableAlterOperation],
dialect: str,
error: bool = True,
) -> None:
"""Display a destructive change error or warning to the user."""
@abc.abstractmethod
def log_additive_change(
self,
snapshot_name: str,
alter_operations: t.List[TableAlterOperation],
dialect: str,
error: bool = True,
) -> None:
"""Display an additive change error or warning to the user."""
class UnitTestConsole(abc.ABC):
@abc.abstractmethod
def log_test_results(self, result: ModelTextTestResult, target_dialect: str) -> None:
"""Display the test result and output.
Args:
result: The unittest test result that contains metrics like num success, fails, ect.
target_dialect: The dialect that tests were run against. Assumes all tests run against the same dialect.
"""
class SignalConsole(abc.ABC):
@abc.abstractmethod
def start_signal_progress(
self,
snapshot: Snapshot,
default_catalog: t.Optional[str],
environment_naming_info: EnvironmentNamingInfo,
) -> None:
"""Indicates that signal checking has begun for a snapshot."""
@abc.abstractmethod
def update_signal_progress(
self,
snapshot: Snapshot,
signal_name: str,
signal_idx: int,
total_signals: int,
ready_intervals: Intervals,
check_intervals: Intervals,
duration: float,
) -> None:
"""Updates the signal checking progress."""
@abc.abstractmethod
def stop_signal_progress(self) -> None:
"""Indicates that signal checking has completed for a snapshot."""
class Console(
SignalConsole,
PlanBuilderConsole,
LinterConsole,
StateExporterConsole,
StateImporterConsole,
JanitorConsole,
DestroyConsole,
EnvironmentsConsole,
DifferenceConsole,
TableDiffConsole,
BaseConsole,
UnitTestConsole,
abc.ABC,
):
"""Abstract base class for defining classes used for displaying information to the user and also interact
with them when their input is needed."""
INDIRECTLY_MODIFIED_DISPLAY_THRESHOLD = 10
@abc.abstractmethod
def start_plan_evaluation(self, plan: EvaluatablePlan) -> None:
"""Indicates that a new evaluation has begun."""
@abc.abstractmethod
def stop_plan_evaluation(self) -> None:
"""Indicates that the evaluation has ended."""
@abc.abstractmethod
def start_evaluation_progress(
self,
batched_intervals: t.Dict[Snapshot, Intervals],
environment_naming_info: EnvironmentNamingInfo,
default_catalog: t.Optional[str],
audit_only: bool = False,
) -> None:
"""Indicates that a new snapshot evaluation/auditing progress has begun."""
@abc.abstractmethod
def start_snapshot_evaluation_progress(
self, snapshot: Snapshot, audit_only: bool = False
) -> None:
"""Starts the snapshot evaluation progress."""
@abc.abstractmethod
def update_snapshot_evaluation_progress(
self,
snapshot: Snapshot,
interval: Interval,
batch_idx: int,
duration_ms: t.Optional[int],
num_audits_passed: int,
num_audits_failed: int,
audit_only: bool = False,
execution_stats: t.Optional[QueryExecutionStats] = None,
auto_restatement_triggers: t.Optional[t.List[SnapshotId]] = None,
) -> None:
"""Updates the snapshot evaluation progress."""
@abc.abstractmethod
def stop_evaluation_progress(self, success: bool = True) -> None:
"""Stops the snapshot evaluation progress."""
@abc.abstractmethod
def start_creation_progress(
self,
snapshots: t.List[Snapshot],
environment_naming_info: EnvironmentNamingInfo,
default_catalog: t.Optional[str],
) -> None:
"""Indicates that a new snapshot creation progress has begun."""
@abc.abstractmethod
def update_creation_progress(self, snapshot: SnapshotInfoLike) -> None:
"""Update the snapshot creation progress."""
@abc.abstractmethod
def stop_creation_progress(self, success: bool = True) -> None:
"""Stop the snapshot creation progress."""
@abc.abstractmethod
def start_promotion_progress(
self,
snapshots: t.List[SnapshotTableInfo],
environment_naming_info: EnvironmentNamingInfo,
default_catalog: t.Optional[str],
) -> None:
"""Indicates that a new snapshot promotion progress has begun."""
@abc.abstractmethod
def update_promotion_progress(self, snapshot: SnapshotInfoLike, promoted: bool) -> None:
"""Update the snapshot promotion progress."""
@abc.abstractmethod
def stop_promotion_progress(self, success: bool = True) -> None:
"""Stop the snapshot promotion progress."""
@abc.abstractmethod
def start_snapshot_migration_progress(self, total_tasks: int) -> None:
"""Indicates that a new snapshot migration progress has begun."""
@abc.abstractmethod
def update_snapshot_migration_progress(self, num_tasks: int) -> None:
"""Update the snapshot migration progress."""
@abc.abstractmethod
def log_migration_status(self, success: bool = True) -> None:
"""Log the finished migration status."""
@abc.abstractmethod
def stop_snapshot_migration_progress(self, success: bool = True) -> None:
"""Stop the snapshot migration progress."""
@abc.abstractmethod
def start_env_migration_progress(self, total_tasks: int) -> None:
"""Indicates that a new environment migration progress has begun."""
@abc.abstractmethod
def update_env_migration_progress(self, num_tasks: int) -> None:
"""Update the environment migration progress."""
@abc.abstractmethod
def stop_env_migration_progress(self, success: bool = True) -> None:
"""Stop the environment migration progress."""
@abc.abstractmethod
def plan(
self,
plan_builder: PlanBuilder,
auto_apply: bool,
default_catalog: t.Optional[str],
no_diff: bool = False,
no_prompts: bool = False,
) -> None:
"""The main plan flow.
The console should present the user with choices on how to backfill and version the snapshots
of a plan.
Args:
plan: The plan to make choices for.
auto_apply: Whether to automatically apply the plan after all choices have been made.
no_diff: Hide text differences for changed models.
no_prompts: Whether to disable interactive prompts for the backfill time range. Please note that
if this flag is set to true and there are uncategorized changes the plan creation will
fail. Default: False
"""
@abc.abstractmethod
def show_sql(self, sql: str) -> None:
"""Display to the user SQL."""
@abc.abstractmethod
def log_status_update(self, message: str) -> None:
"""Display general status update to the user."""
@abc.abstractmethod
def log_skipped_models(self, snapshot_names: t.Set[str]) -> None:
"""Display list of models skipped during evaluation to the user."""
@abc.abstractmethod
def log_failed_models(self, errors: t.List[NodeExecutionFailedError]) -> None:
"""Display list of models that failed during evaluation to the user."""
@abc.abstractmethod
def log_models_updated_during_restatement(
self,
snapshots: t.List[t.Tuple[SnapshotTableInfo, SnapshotTableInfo]],
environment_naming_info: EnvironmentNamingInfo,
default_catalog: t.Optional[str],
) -> None:
"""Display a list of models where new versions got deployed to the specified :environment while we were restating data the old versions
Args:
snapshots: a list of (snapshot_we_restated, snapshot_it_got_replaced_with_during_restatement) tuples
environment: which environment got updated while we were restating models
environment_naming_info: how snapshots are named in that :environment (for display name purposes)
default_catalog: the configured default catalog (for display name purposes)
"""
@abc.abstractmethod
def loading_start(self, message: t.Optional[str] = None) -> uuid.UUID:
"""Starts loading and returns a unique ID that can be used to stop the loading. Optionally can display a message."""
@abc.abstractmethod
def loading_stop(self, id: uuid.UUID) -> None:
"""Stop loading for the given id."""
class NoopConsole(Console):
def start_plan_evaluation(self, plan: EvaluatablePlan) -> None:
pass
def stop_plan_evaluation(self) -> None:
pass
def start_evaluation_progress(
self,
batched_intervals: t.Dict[Snapshot, Intervals],
environment_naming_info: EnvironmentNamingInfo,
default_catalog: t.Optional[str],
audit_only: bool = False,
) -> None:
pass
def start_snapshot_evaluation_progress(
self, snapshot: Snapshot, audit_only: bool = False
) -> None:
pass
def update_snapshot_evaluation_progress(
self,
snapshot: Snapshot,
interval: Interval,
batch_idx: int,
duration_ms: t.Optional[int],
num_audits_passed: int,
num_audits_failed: int,
audit_only: bool = False,
execution_stats: t.Optional[QueryExecutionStats] = None,
auto_restatement_triggers: t.Optional[t.List[SnapshotId]] = None,
) -> None:
pass
def stop_evaluation_progress(self, success: bool = True) -> None:
pass
def start_signal_progress(
self,
snapshot: Snapshot,
default_catalog: t.Optional[str],
environment_naming_info: EnvironmentNamingInfo,
) -> None:
pass
def update_signal_progress(
self,
snapshot: Snapshot,
signal_name: str,
signal_idx: int,
total_signals: int,
ready_intervals: Intervals,
check_intervals: Intervals,
duration: float,
) -> None:
pass
def stop_signal_progress(self) -> None:
pass
def start_creation_progress(
self,
snapshots: t.List[Snapshot],
environment_naming_info: EnvironmentNamingInfo,
default_catalog: t.Optional[str],
) -> None:
pass
def update_creation_progress(self, snapshot: SnapshotInfoLike) -> None:
pass
def stop_creation_progress(self, success: bool = True) -> None:
pass
def start_cleanup(self, ignore_ttl: bool) -> bool:
return True
def update_cleanup_progress(self, object_name: str) -> None:
pass
def stop_cleanup(self, success: bool = True) -> None:
pass
def start_promotion_progress(
self,
snapshots: t.List[SnapshotTableInfo],
environment_naming_info: EnvironmentNamingInfo,
default_catalog: t.Optional[str],
) -> None:
pass
def update_promotion_progress(self, snapshot: SnapshotInfoLike, promoted: bool) -> None:
pass
def stop_promotion_progress(self, success: bool = True) -> None:
pass
def start_snapshot_migration_progress(self, total_tasks: int) -> None:
pass
def update_snapshot_migration_progress(self, num_tasks: int) -> None:
pass
def log_migration_status(self, success: bool = True) -> None:
pass
def stop_snapshot_migration_progress(self, success: bool = True) -> None:
pass
def start_env_migration_progress(self, total_tasks: int) -> None:
pass
def update_env_migration_progress(self, num_tasks: int) -> None:
pass
def stop_env_migration_progress(self, success: bool = True) -> None:
pass
def start_state_export(
self,
output_file: Path,
gateway: t.Optional[str] = None,
state_connection_config: t.Optional[ConnectionConfig] = None,
environment_names: t.Optional[t.List[str]] = None,
local_only: bool = False,
confirm: bool = True,
) -> bool:
return confirm
def update_state_export_progress(
self,
version_count: t.Optional[int] = None,
versions_complete: bool = False,
snapshot_count: t.Optional[int] = None,
snapshots_complete: bool = False,
environment_count: t.Optional[int] = None,
environments_complete: bool = False,
) -> None:
pass
def stop_state_export(self, success: bool, output_file: Path) -> None:
pass
def start_state_import(
self,
input_file: Path,
gateway: str,
state_connection_config: ConnectionConfig,
clear: bool = False,
confirm: bool = True,
) -> bool:
return confirm
def update_state_import_progress(
self,
timestamp: t.Optional[str] = None,
state_file_version: t.Optional[int] = None,
versions: t.Optional[Versions] = None,
snapshot_count: t.Optional[int] = None,
snapshots_complete: bool = False,
environment_count: t.Optional[int] = None,
environments_complete: bool = False,
) -> None:
pass
def stop_state_import(self, success: bool, input_file: Path) -> None:
pass
def show_environment_difference_summary(
self,
context_diff: ContextDiff,
no_diff: bool = True,
) -> None:
pass
def show_model_difference_summary(
self,
context_diff: ContextDiff,
environment_naming_info: EnvironmentNamingInfo,
default_catalog: t.Optional[str],
no_diff: bool = True,
) -> None:
pass
def plan(
self,
plan_builder: PlanBuilder,
auto_apply: bool,
default_catalog: t.Optional[str],
no_diff: bool = False,
no_prompts: bool = False,
) -> None:
if auto_apply:
plan_builder.apply()
def log_test_results(self, result: ModelTextTestResult, target_dialect: str) -> None:
pass
def show_sql(self, sql: str) -> None:
pass
def log_status_update(self, message: str) -> None:
pass
def log_skipped_models(self, snapshot_names: t.Set[str]) -> None:
pass
def log_failed_models(self, errors: t.List[NodeExecutionFailedError]) -> None:
pass
def log_models_updated_during_restatement(
self,
snapshots: t.List[t.Tuple[SnapshotTableInfo, SnapshotTableInfo]],
environment_naming_info: EnvironmentNamingInfo,
default_catalog: t.Optional[str],
) -> None:
pass
def log_destructive_change(
self,
snapshot_name: str,
alter_operations: t.List[TableAlterOperation],
dialect: str,
error: bool = True,
) -> None:
pass
def log_additive_change(
self,
snapshot_name: str,
alter_operations: t.List[TableAlterOperation],
dialect: str,
error: bool = True,
) -> None:
pass
def log_error(self, message: str) -> None:
pass
def log_warning(self, short_message: str, long_message: t.Optional[str] = None) -> None:
logger.warning(long_message or short_message)
def log_success(self, message: str) -> None:
pass
def loading_start(self, message: t.Optional[str] = None) -> uuid.UUID:
return uuid.uuid4()
def loading_stop(self, id: uuid.UUID) -> None:
pass
def show_table_diff(
self,
table_diffs: t.List[TableDiff],
show_sample: bool = True,
skip_grain_check: bool = False,
temp_schema: t.Optional[str] = None,
) -> None:
for table_diff in table_diffs:
self.show_table_diff_summary(table_diff)
self.show_schema_diff(table_diff.schema_diff())
self.show_row_diff(
table_diff.row_diff(temp_schema=temp_schema, skip_grain_check=skip_grain_check),
show_sample=show_sample,
skip_grain_check=skip_grain_check,
)
def update_table_diff_progress(self, model: str) -> None:
pass
def start_table_diff_progress(self, models_to_diff: int) -> None:
pass
def start_table_diff_model_progress(self, model: str) -> None:
pass
def stop_table_diff_progress(self, success: bool) -> None:
pass
def show_table_diff_details(
self,
models_to_diff: t.List[str],
) -> None:
pass
def show_table_diff_summary(self, table_diff: TableDiff) -> None:
pass
def show_schema_diff(self, schema_diff: SchemaDiff) -> None:
pass
def show_row_diff(
self, row_diff: RowDiff, show_sample: bool = True, skip_grain_check: bool = False
) -> None:
pass
def print_environments(self, environments_summary: t.List[EnvironmentSummary]) -> None:
pass
def show_intervals(self, snapshot_intervals: t.Dict[Snapshot, SnapshotIntervals]) -> None:
pass
def show_linter_violations(
self, violations: t.List[RuleViolation], model: Model, is_error: bool = False
) -> None:
pass
def print_connection_config(
self, config: ConnectionConfig, title: t.Optional[str] = "Connection"
) -> None:
pass
def start_destroy(
self,
schemas_to_delete: t.Optional[t.Set[str]] = None,
views_to_delete: t.Optional[t.Set[str]] = None,
tables_to_delete: t.Optional[t.Set[str]] = None,
) -> bool:
return True
def stop_destroy(self, success: bool = True) -> None:
pass
def make_progress_bar(
message: str,
console: t.Optional[RichConsole] = None,
justify: t.Literal["default", "left", "center", "right", "full"] = "right",
) -> Progress:
return Progress(
TextColumn(f"[bold blue]{message}", justify=justify),
BarColumn(bar_width=PROGRESS_BAR_WIDTH),
"[progress.percentage]{task.percentage:>3.1f}%",
"•",
srich.BatchColumn(),
"•",
TimeElapsedColumn(),
console=console,
)
class TerminalConsole(Console):
"""A rich based implementation of the console."""
TABLE_DIFF_SOURCE_BLUE = "#0248ff"
TABLE_DIFF_TARGET_GREEN = "green"
AUDIT_PASS_MARK = "\u2714"
GREEN_AUDIT_PASS_MARK = f"[green]{AUDIT_PASS_MARK}[/green]"
AUDIT_FAIL_MARK = "\u274c"
AUDIT_PADDING = 0
CHECK_MARK = f"{AUDIT_PASS_MARK} "
def __init__(
self,
console: t.Optional[RichConsole] = None,
verbosity: Verbosity = Verbosity.DEFAULT,
dialect: DialectType = None,
ignore_warnings: bool = False,
**kwargs: t.Any,
) -> None:
self.console: RichConsole = console or srich.console
self.evaluation_progress_live: t.Optional[Live] = None
self.evaluation_total_progress: t.Optional[Progress] = None
self.evaluation_total_task: t.Optional[TaskID] = None
self.evaluation_model_progress: t.Optional[Progress] = None
self.evaluation_model_tasks: t.Dict[str, TaskID] = {}
self.evaluation_model_batch_sizes: t.Dict[Snapshot, int] = {}
self.evaluation_column_widths: t.Dict[str, int] = {}
# Put in temporary values that are replaced when evaluating
self.environment_naming_info = EnvironmentNamingInfo()
self.default_catalog: t.Optional[str] = None
self.creation_progress: t.Optional[Progress] = None
self.creation_column_widths: t.Dict[str, int] = {}
self.creation_task: t.Optional[TaskID] = None
self.promotion_progress: t.Optional[Progress] = None
self.promotion_column_widths: t.Dict[str, int] = {}
self.promotion_task: t.Optional[TaskID] = None
self.migration_progress: t.Optional[Progress] = None
self.migration_task: t.Optional[TaskID] = None
self.env_migration_progress: t.Optional[Progress] = None
self.env_migration_task: t.Optional[TaskID] = None
self.loading_status: t.Dict[uuid.UUID, Status] = {}
self.state_export_progress: t.Optional[Progress] = None
self.state_export_version_task: t.Optional[TaskID] = None
self.state_export_snapshot_task: t.Optional[TaskID] = None
self.state_export_environment_task: t.Optional[TaskID] = None
self.state_import_progress: t.Optional[Progress] = None
self.state_import_version_task: t.Optional[TaskID] = None
self.state_import_snapshot_task: t.Optional[TaskID] = None
self.state_import_environment_task: t.Optional[TaskID] = None
self.table_diff_progress: t.Optional[Progress] = None
self.table_diff_model_progress: t.Optional[Progress] = None
self.table_diff_model_tasks: t.Dict[str, TaskID] = {}
self.table_diff_progress_live: t.Optional[Live] = None
self.signal_progress_logged = False
self.signal_status_tree: t.Optional[Tree] = None
self.verbosity = verbosity
self.dialect = dialect
self.ignore_warnings = ignore_warnings
def _limit_model_names(self, tree: Tree, verbosity: Verbosity = Verbosity.DEFAULT) -> Tree:
"""Trim long indirectly modified model lists below threshold."""
modified_length = len(tree.children)
if (
verbosity < Verbosity.VERY_VERBOSE
and modified_length > self.INDIRECTLY_MODIFIED_DISPLAY_THRESHOLD
):
tree.children = [
tree.children[0],