Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions sqlmesh/core/model/definition.py
Original file line number Diff line number Diff line change
Expand Up @@ -850,13 +850,17 @@ def convert_to_time_column(
if columns_to_types is None:
columns_to_types = self.columns_to_types_or_raise

if self.time_column.column.name not in columns_to_types:
time_column_name = self.time_column.column.name
time_column_type = columns_to_types.get(time_column_name)
if time_column_type is None:
time_column_type = {k.lower(): v for k, v in columns_to_types.items()}.get(
time_column_name.lower()
)
if time_column_type is None:
raise ConfigError(
f"Time column '{self.time_column.column.sql(dialect=self.dialect)}' not found in model '{self.name}'."
)

time_column_type = columns_to_types[self.time_column.column.name]

return to_time_column(
time,
time_column_type,
Expand Down
24 changes: 24 additions & 0 deletions tests/core/test_time_column_case_insensitive.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from sqlglot import exp
from sqlmesh.core.model import load_sql_based_model
from sqlmesh.core.dialect import parse


def test_convert_to_time_column_case_insensitive_columns_to_types():
expressions = parse(
"""
MODEL (
name my_schema.my_model,
dialect 'tsql,normalization_strategy=case_insensitive',
kind INCREMENTAL_BY_TIME_RANGE (
time_column CreatedAtUtc
)
);
SELECT 1 AS id, CAST('2024-01-01' AS TIMESTAMP) AS createdatutc
"""
)
model = load_sql_based_model(expressions)
result = model.convert_to_time_column(
"2024-01-02",
columns_to_types={"ID": exp.DataType.build("INT"), "CREATEDATUTC": exp.DataType.build("TIMESTAMP")},
)
assert isinstance(result, exp.Expr)