sqlmesh icon indicating copy to clipboard operation
sqlmesh copied to clipboard

Feat: make MacroEvaluator.columns_to_types more lenient

Open georgesittas opened this issue 1 year ago • 0 comments

This PR makes the columns_to_types method more lenient by leveraging any existing snapshots in the evaluator's context as a fallback to fetch the target model's schema.

The motivation can be found here: one real-world example is executing ALTER statements for the physical table of a model after it's created, for which we need to know the model's schema. This is not possible today, because the model's own schema is not included in its mapping_schema -- it only includes its dependencies' schemas.

I also added a guard that protects from returning the dummy schema unless we're at the loading runtime stage, to avoid cryptic errors such as "Column __schema_unavailable_at_load__ does not exist!" when queries are executed during table creation or model evaluation.

georgesittas avatar Aug 13 '24 22:08 georgesittas