Skip to content
6 changes: 6 additions & 0 deletions sqlmesh/core/engine_adapter/fabric.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
from tenacity import retry, stop_after_attempt, wait_exponential, retry_if_result
from sqlmesh.core.engine_adapter.mssql import MSSQLEngineAdapter
from sqlmesh.core.engine_adapter.shared import (
CommentCreationTable,
CommentCreationView,
InsertOverwriteStrategy,
)
from sqlmesh.utils.errors import SQLMeshError
Expand All @@ -30,6 +32,10 @@ class FabricEngineAdapter(MSSQLEngineAdapter):
SUPPORTS_TRANSACTIONS = False
SUPPORTS_CREATE_DROP_CATALOG = True
INSERT_OVERWRITE_STRATEGY = InsertOverwriteStrategy.DELETE_INSERT
# There is no standard method to handle comments in Fabric for now, so we disable it.
# Otherwise, it would be inherited from MSSQL and would not work.
COMMENT_CREATION_TABLE = CommentCreationTable.UNSUPPORTED
COMMENT_CREATION_VIEW = CommentCreationView.UNSUPPORTED

def __init__(
self, connection_factory_or_pool: t.Union[t.Callable, t.Any], *args: t.Any, **kwargs: t.Any
Expand Down
20 changes: 20 additions & 0 deletions tests/core/engine_adapter/test_fabric.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,3 +286,23 @@ def test_merge_exists(
f"MERGE INTO [target] AS [__MERGE_TARGET__] USING (SELECT CAST([id] AS INT) AS [id], CAST([ts] AS DATETIME2(6)) AS [ts] FROM [__temp_target_{temp_table_id}]) AS [__MERGE_SOURCE__] ON [__MERGE_TARGET__].[id] = [__MERGE_SOURCE__].[id] AND [__MERGE_TARGET__].[ts] = [__MERGE_SOURCE__].[ts] WHEN NOT MATCHED THEN INSERT ([id], [ts]) VALUES ([__MERGE_SOURCE__].[id], [__MERGE_SOURCE__].[ts]);",
f"DROP TABLE IF EXISTS [__temp_target_{temp_table_id}];",
]


def test_comments(make_mocked_engine_adapter: t.Callable, mocker: MockerFixture):
adapter = make_mocked_engine_adapter(FabricEngineAdapter)
comment = "\\"

create_table_comment_mock = mocker.patch.object(adapter, "_create_table_comment")
create_column_comments_mock = mocker.patch.object(adapter, "_create_column_comments")
mocker.patch.object(adapter, "_create_table")

adapter.create_table(
"test_table",
{"a": exp.DataType.build("INT"), "b": exp.DataType.build("INT")},
table_description=comment,
column_descriptions={"a": comment},
)

create_table_comment_mock.assert_not_called()
create_column_comments_mock.assert_not_called()
assert to_sql_calls(adapter) == []
21 changes: 21 additions & 0 deletions tests/core/engine_adapter/test_mssql.py
Original file line number Diff line number Diff line change
Expand Up @@ -1002,3 +1002,24 @@ def python_scd2_model(context, **kwargs):
snapshot: Snapshot = make_snapshot(m)
assert snapshot.node.physical_properties == m.physical_properties
assert snapshot.node.physical_properties.get("mssql_merge_exists")


def test_comments(make_mocked_engine_adapter: t.Callable, mocker: MockerFixture):
adapter = make_mocked_engine_adapter(MSSQLEngineAdapter)
table = exp.to_table("test_table")
comment = "\\"

mocker.patch.object(adapter, "_create_table")

adapter.create_table(
"test_table",
{"a": exp.DataType.build("INT"), "b": exp.DataType.build("INT")},
table_description=comment,
column_descriptions={"a": comment},
)

sql_calls = to_sql_calls(adapter)
assert sql_calls == [
adapter._build_create_comment_table_exp(table, comment),
adapter._build_create_comment_column_exp(table, "a", comment),
]
Loading