|
5 | 5 | import typing as t |
6 | 6 | import sqlmesh.core.dialect as d |
7 | 7 | from pathlib import Path |
| 8 | +from collections import defaultdict |
8 | 9 | from sqlmesh.core.config import ( |
9 | 10 | Config, |
10 | 11 | ConnectionConfig, |
@@ -137,16 +138,22 @@ def _to_sqlmesh(config: BMC, context: DbtContext) -> Model: |
137 | 138 | package_context.set_and_render_variables(package.variables, package.name) |
138 | 139 | package_models: t.Dict[str, BaseModelConfig] = {**package.models, **package.seeds} |
139 | 140 |
|
| 141 | + package_models_by_path: t.Dict[Path, t.List[BaseModelConfig]] = defaultdict(list) |
140 | 142 | for model in package_models.values(): |
141 | 143 | if isinstance(model, ModelConfig) and not model.sql.strip(): |
142 | 144 | logger.info(f"Skipping empty model '{model.name}' at path '{model.path}'.") |
143 | 145 | continue |
| 146 | + package_models_by_path[model.path].append(model) |
144 | 147 |
|
145 | | - sqlmesh_model = cache.get_or_load_models( |
146 | | - model.path, loader=lambda: [_to_sqlmesh(model, package_context)] |
147 | | - )[0] |
148 | | - |
149 | | - models[sqlmesh_model.fqn] = sqlmesh_model |
| 148 | + for path, path_models in package_models_by_path.items(): |
| 149 | + sqlmesh_models = cache.get_or_load_models( |
| 150 | + path, |
| 151 | + loader=lambda: [ |
| 152 | + _to_sqlmesh(model, package_context) for model in path_models |
| 153 | + ], |
| 154 | + ) |
| 155 | + for sqlmesh_model in sqlmesh_models: |
| 156 | + models[sqlmesh_model.fqn] = sqlmesh_model |
150 | 157 |
|
151 | 158 | models.update(self._load_external_models(audits, cache)) |
152 | 159 |
|
|
0 commit comments