Skip to content

Commit 332ea32

Browse files
committed
CTEs no qualify
1 parent 0ff075c commit 332ea32

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

sqlmesh/core/engine_adapter/fabric.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,14 @@ def create_view(
303303
qualified_view_name = self._fully_qualify(view_name)
304304

305305
if isinstance(query_or_df, exp.Expression):
306+
# CTEs should not be qualified with the database name.
307+
cte_names = {cte.alias_or_name for cte in query_or_df.find_all(exp.CTE)}
308+
306309
for table in query_or_df.find_all(exp.Table):
310+
if table.this.name in cte_names:
311+
continue
312+
313+
# Qualify all other tables that don't already have a catalog.
307314
if not table.catalog:
308315
qualified_table = self._fully_qualify(table)
309316
table.replace(qualified_table)

0 commit comments

Comments
 (0)