Skip to content

Commit

Permalink
Fix: include column descriptions in optimized query cache key
Browse files Browse the repository at this point in the history
  • Loading branch information
georgesittas committed Dec 18, 2024
1 parent 3a89d9e commit b37d683
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"rich[jupyter]",
"ruamel.yaml",
"setuptools; python_version>='3.12'",
"sqlglot[rs]~=26.0.0",
"sqlglot[rs]~=26.0.1",
"tenacity",
],
extras_require={
Expand Down
2 changes: 1 addition & 1 deletion sqlmesh/core/model/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def _put(self, name: str, model: SqlModel) -> None:
@staticmethod
def _entry_name(model: SqlModel) -> str:
hash_data = _mapping_schema_hash_data(model.mapping_schema)
hash_data.append(gen(model.query))
hash_data.append(gen(model.query, comments=True))
hash_data.append(str([gen(d) for d in model.macro_definitions]))
hash_data.append(str([(k, v) for k, v in model.sorted_python_env]))
hash_data.extend(model.jinja_macros.data_hash_values)
Expand Down
32 changes: 32 additions & 0 deletions tests/core/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -6404,3 +6404,35 @@ def test_model_optimize(tmp_path: Path, assert_exp_eq):
context = Context(config=Config(model_defaults=ModelDefaultsConfig(dialect="duckdb")))
context.upsert_model(model)
context.plan(auto_apply=True, no_prompts=True)


def test_column_description_metadata_change():
context = Context(config=Config())

model = load_sql_based_model(
d.parse(
"""
MODEL (
name db.test_model,
kind full
);
SELECT
1 AS id /* description */
"""
),
default_catalog=context.default_catalog,
)

context.upsert_model(model)
context.plan(no_prompts=True, auto_apply=True)

context.upsert_model("db.test_model", query=parse_one("SELECT 1 AS id /* description 2 */"))
plan = context.plan(no_prompts=True, auto_apply=True)

snapshots = list(plan.snapshots.values())
assert len(snapshots) == 1

snapshot = snapshots[0]
assert len(snapshot.previous_versions) == 1
assert snapshot.change_category == SnapshotChangeCategory.METADATA

0 comments on commit b37d683

Please sign in to comment.