-
Notifications
You must be signed in to change notification settings - Fork 354
Description
SQLMesh Bug Report
Title: INCREMENTAL_BY_TIME_RANGE: Time column not found when using normalization_strategy=case_insensitive with Snowflake
Repo: https://github.com/TobikoData/sqlmesh/issues
Bug Description
When using INCREMENTAL_BY_TIME_RANGE models with a Snowflake connection and normalization_strategy=case_insensitive in the dialect, sqlmesh plan fails with:
ConfigError: Time column '' not found in model 'my_schema.my_model'
Root Cause
In sqlmesh/core/model/definition.py, the convert_to_time_column method (line ~831) does a case-sensitive Python dict lookup:
if self.time_column.column.name not in columns_to_types:normalization_strategy=case_insensitivelowercases the model'stime_column.column.name→createdatutcengine_adapter.columns()returns Snowflake's native UPPERCASE column names →CREATEDATUTC- The case-sensitive
not incheck always fails
Reproduction
config.yaml:
gateways:
snowflake_prod:
model_defaults:
dialect: "tsql,normalization_strategy=case_insensitive"
connection:
type: snowflake
# ...model.sql:
MODEL (
name my_schema.my_model,
kind INCREMENTAL_BY_TIME_RANGE (
time_column CreatedAtUtc
)
);
SELECT
src.CreatedAtUtc,
src.Id
FROM upstream.source AS src
WHERE src.CreatedAtUtc BETWEEN @start_date AND @end_dateRun sqlmesh --gateway snowflake_prod plan → fails with Time column '' not found.
Suggested Fix
Normalize the column names from engine_adapter.columns() before comparison, or make the lookup in convert_to_time_column case-insensitive:
# Before
if self.time_column.column.name not in columns_to_types:
# After
columns_to_types_lower = {k.lower(): v for k, v in columns_to_types.items()}
if self.time_column.column.name.lower() not in columns_to_types_lower:A more robust fix might normalize column names at the point they're returned from engine_adapter.columns() (line ~501) to match the model's normalization strategy.
Environment
- SQLMesh version: 0.230.1
- Python: 3.12
- Connection: Snowflake
- Dialect:
tsql,normalization_strategy=case_insensitive