Skip to content

Commit 97e5f99

Browse files
revise mapping schema set; add docstrings
1 parent 3b4598b commit 97e5f99

File tree

3 files changed

+21
-4
lines changed

3 files changed

+21
-4
lines changed

sqlmesh/core/loader.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,28 @@ def get_or_load_models(
7777

7878
@abc.abstractmethod
7979
def put(self, models: t.List[Model], path: Path) -> bool:
80+
"""Store models in the cache associated with the given path.
81+
82+
Args:
83+
models: List of models to cache
84+
path: File path to associate with the cached models
85+
86+
Returns:
87+
True if the models were successfully cached,
88+
False otherwise (empty list, not a list, unsupported model types)
89+
"""
8090
pass
8191

8292
@abc.abstractmethod
8393
def get(self, path: Path) -> t.List[Model]:
94+
"""Retrieve models from the cache for a given path.
95+
96+
Args:
97+
path: File path to look up in the cache
98+
99+
Returns:
100+
List of cached models associated with the path, an empty list if no cache entry exists
101+
"""
84102
pass
85103

86104

sqlmesh/core/model/definition.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -812,10 +812,8 @@ def convert_to_time_column(
812812
return exp.convert(time)
813813

814814
def set_mapping_schema(self, schema: t.Dict) -> None:
815-
# Make a shallow copy to avoid modifying the original in case they're the same
816-
temp_schema = schema.copy()
817815
self.mapping_schema.clear()
818-
self.mapping_schema.update(temp_schema)
816+
self.mapping_schema.update(schema)
819817

820818
def update_schema(self, schema: MappingSchema) -> None:
821819
"""Updates the schema for this model's dependencies based on the given mapping schema."""

sqlmesh/core/model/schema.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,8 @@ def process_models(completed_model: t.Optional[Model] = None) -> None:
9393
model = models[fqn]
9494
model._data_hash = data_hash
9595
model._metadata_hash = metadata_hash
96-
model.set_mapping_schema(mapping_schema)
96+
if model.mapping_schema != mapping_schema:
97+
model.set_mapping_schema(mapping_schema)
9798
optimized_query_cache.with_optimized_query(model, entry_name)
9899
_update_schema_with_model(schema, model)
99100
process_models(completed_model=model)

0 commit comments

Comments
 (0)