Skip to content

Commit 814a44b

Browse files
authored
include catalog in table name (#1241)
1 parent 66c610a commit 814a44b

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

sqlmesh/core/snapshot/definition.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -875,7 +875,14 @@ def _ensure_categorized(self) -> None:
875875

876876
def table_name(physical_schema: str, name: str, version: str, is_temp: bool = False) -> str:
877877
temp_suffx = "__temp" if is_temp else ""
878-
return f"{physical_schema}.{name.replace('.', '__')}__{version}{temp_suffx}"
878+
parts = [
879+
physical_schema,
880+
f"{name.replace('.', '__')}__{version}{temp_suffx}",
881+
]
882+
catalog = exp.to_table(name).catalog
883+
if catalog:
884+
parts.insert(0, catalog)
885+
return ".".join(parts)
879886

880887

881888
def fingerprint_from_node(

tests/core/test_snapshot.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import json
2+
import typing as t
23
from copy import deepcopy
34
from datetime import timedelta
45
from pathlib import Path
@@ -509,7 +510,7 @@ def test_stamp(model: Model):
509510
assert original_fingerprint != stamped_fingerprint
510511

511512

512-
def test_table_name(snapshot: Snapshot):
513+
def test_table_name(snapshot: Snapshot, make_snapshot: t.Callable):
513514
# Mimic a direct breaking change.
514515
snapshot.fingerprint = SnapshotFingerprint(
515516
data_hash="1", metadata_hash="1", parent_data_hash="1"
@@ -574,6 +575,15 @@ def test_table_name(snapshot: Snapshot):
574575
snapshot.physical_schema_ = "private"
575576
assert snapshot.table_name_for_mapping(is_dev=True) == "private.name__3078928823"
576577

578+
fully_qualified_snapshot = make_snapshot(
579+
SqlModel(name="catalog.db.table", query=parse_one("select 1, ds"))
580+
)
581+
fully_qualified_snapshot.categorize_as(SnapshotChangeCategory.BREAKING)
582+
assert (
583+
fully_qualified_snapshot.table_name(is_dev=False, for_read=False)
584+
== "catalog.sqlmesh__db.catalog__db__table__2528031000"
585+
)
586+
577587

578588
def test_categorize_change_sql(make_snapshot):
579589
old_snapshot = make_snapshot(SqlModel(name="a", query=parse_one("select 1, ds")))

0 commit comments

Comments
 (0)