|
13 | 13 | from sqlmesh.utils.pydantic import PydanticModel |
14 | 14 |
|
15 | 15 |
|
16 | | -# TODO: switch to autoname when sqlglot is typed |
17 | | -class ModelKindName(str, Enum): |
18 | | - """The kind of model, determining how this data is computed and stored in the warehouse.""" |
19 | | - |
20 | | - INCREMENTAL_BY_TIME_RANGE = "INCREMENTAL_BY_TIME_RANGE" |
21 | | - INCREMENTAL_BY_UNIQUE_KEY = "INCREMENTAL_BY_UNIQUE_KEY" |
22 | | - FULL = "FULL" |
23 | | - VIEW = "VIEW" |
24 | | - EMBEDDED = "EMBEDDED" |
25 | | - SEED = "SEED" |
26 | | - # TODO: Add support for snapshots |
27 | | - # SNAPSHOT = "SNAPSHOT" |
28 | | - |
29 | | - |
30 | | -class ModelKind(PydanticModel): |
31 | | - name: ModelKindName |
| 16 | +class ModelKindMixin: |
| 17 | + @property |
| 18 | + def model_kind_name(self) -> ModelKindName: |
| 19 | + """Returns the model kind name.""" |
| 20 | + raise NotImplementedError |
32 | 21 |
|
33 | 22 | @property |
34 | 23 | def is_incremental_by_time_range(self) -> bool: |
35 | | - return self.name == ModelKindName.INCREMENTAL_BY_TIME_RANGE |
| 24 | + return self.model_kind_name == ModelKindName.INCREMENTAL_BY_TIME_RANGE |
36 | 25 |
|
37 | 26 | @property |
38 | 27 | def is_incremental_by_unique_key(self) -> bool: |
39 | | - return self.name == ModelKindName.INCREMENTAL_BY_UNIQUE_KEY |
40 | | - |
41 | | - @property |
42 | | - def is_incremental(self) -> bool: |
43 | | - """Whether or not this model is incremental.""" |
44 | | - return isinstance(self, _Incremental) |
| 28 | + return self.model_kind_name == ModelKindName.INCREMENTAL_BY_UNIQUE_KEY |
45 | 29 |
|
46 | 30 | @property |
47 | 31 | def is_full(self) -> bool: |
48 | | - return self.name == ModelKindName.FULL |
49 | | - |
50 | | - # @property |
51 | | - # def is_snapshot(self) -> bool: |
52 | | - # return self.name == ModelKindName.SNAPSHOT |
| 32 | + return self.model_kind_name == ModelKindName.FULL |
53 | 33 |
|
54 | 34 | @property |
55 | 35 | def is_view(self) -> bool: |
56 | | - return self.name == ModelKindName.VIEW |
| 36 | + return self.model_kind_name == ModelKindName.VIEW |
57 | 37 |
|
58 | 38 | @property |
59 | 39 | def is_embedded(self) -> bool: |
60 | | - return self.name == ModelKindName.EMBEDDED |
| 40 | + return self.model_kind_name == ModelKindName.EMBEDDED |
61 | 41 |
|
62 | 42 | @property |
63 | 43 | def is_seed(self) -> bool: |
64 | | - return self.name == ModelKindName.SEED |
| 44 | + return self.model_kind_name == ModelKindName.SEED |
| 45 | + |
| 46 | + @property |
| 47 | + def is_external(self) -> bool: |
| 48 | + return self.model_kind_name == ModelKindName.EXTERNAL |
| 49 | + |
| 50 | + @property |
| 51 | + def is_symbolic(self) -> bool: |
| 52 | + """A symbolic model is one that doesn't execute at all.""" |
| 53 | + return self.model_kind_name in (ModelKindName.EMBEDDED, ModelKindName.EXTERNAL) |
65 | 54 |
|
66 | 55 | @property |
67 | 56 | def is_materialized(self) -> bool: |
68 | | - return self.name not in (ModelKindName.VIEW, ModelKindName.EMBEDDED) |
| 57 | + return not (self.is_symbolic or self.is_view) |
69 | 58 |
|
70 | 59 | @property |
71 | 60 | def only_latest(self) -> bool: |
72 | 61 | """Whether or not this model only cares about latest date to render.""" |
73 | | - return self.name in (ModelKindName.VIEW, ModelKindName.FULL) |
| 62 | + return self.model_kind_name in (ModelKindName.VIEW, ModelKindName.FULL) |
| 63 | + |
| 64 | + |
| 65 | +class ModelKindName(str, ModelKindMixin, Enum): |
| 66 | + """The kind of model, determining how this data is computed and stored in the warehouse.""" |
| 67 | + |
| 68 | + INCREMENTAL_BY_TIME_RANGE = "INCREMENTAL_BY_TIME_RANGE" |
| 69 | + INCREMENTAL_BY_UNIQUE_KEY = "INCREMENTAL_BY_UNIQUE_KEY" |
| 70 | + FULL = "FULL" |
| 71 | + VIEW = "VIEW" |
| 72 | + EMBEDDED = "EMBEDDED" |
| 73 | + SEED = "SEED" |
| 74 | + EXTERNAL = "EXTERNAL" |
| 75 | + |
| 76 | + @property |
| 77 | + def model_kind_name(self) -> ModelKindName: |
| 78 | + return self |
| 79 | + |
| 80 | + |
| 81 | +class ModelKind(PydanticModel, ModelKindMixin): |
| 82 | + name: ModelKindName |
74 | 83 |
|
75 | 84 | def to_expression(self, **kwargs: t.Any) -> d.ModelKind: |
76 | 85 | return d.ModelKind(this=self.name.value.upper(), **kwargs) |
77 | 86 |
|
| 87 | + @property |
| 88 | + def model_kind_name(self) -> ModelKindName: |
| 89 | + return self.name |
| 90 | + |
78 | 91 |
|
79 | 92 | class TimeColumn(PydanticModel): |
80 | 93 | column: str |
|
0 commit comments