Skip to content

Commit 9c0a2dd

Browse files
committed
remove table_exist and columns
1 parent 6895570 commit 9c0a2dd

2 files changed

Lines changed: 24 additions & 87 deletions

File tree

sqlmesh/core/engine_adapter/fabric.py

Lines changed: 0 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -20,87 +20,6 @@ class FabricAdapter(MSSQLEngineAdapter):
2020
SUPPORTS_TRANSACTIONS = False
2121
INSERT_OVERWRITE_STRATEGY = InsertOverwriteStrategy.DELETE_INSERT
2222

23-
def table_exists(self, table_name: TableName) -> bool:
24-
"""
25-
Checks if a table exists.
26-
27-
Querying the uppercase `INFORMATION_SCHEMA` required
28-
by case-sensitive Fabric environments.
29-
"""
30-
table = exp.to_table(table_name)
31-
sql = (
32-
exp.select("1")
33-
.from_("INFORMATION_SCHEMA.TABLES")
34-
.where(f"TABLE_NAME = '{table.alias_or_name}'")
35-
)
36-
database_name = table.db
37-
if database_name:
38-
sql = sql.where(f"TABLE_SCHEMA = '{database_name}'")
39-
40-
result = self.fetchone(sql, quote_identifiers=True)
41-
42-
return result[0] == 1 if result else False
43-
44-
def columns(
45-
self,
46-
table_name: TableName,
47-
include_pseudo_columns: bool = True,
48-
) -> t.Dict[str, exp.DataType]:
49-
"""Fabric doesn't support describe so we query INFORMATION_SCHEMA."""
50-
51-
table = exp.to_table(table_name)
52-
53-
sql = (
54-
exp.select(
55-
"COLUMN_NAME",
56-
"DATA_TYPE",
57-
"CHARACTER_MAXIMUM_LENGTH",
58-
"NUMERIC_PRECISION",
59-
"NUMERIC_SCALE",
60-
)
61-
.from_("INFORMATION_SCHEMA.COLUMNS")
62-
.where(f"TABLE_NAME = '{table.name}'")
63-
)
64-
database_name = table.db
65-
if database_name:
66-
sql = sql.where(f"TABLE_SCHEMA = '{database_name}'")
67-
68-
columns_raw = self.fetchall(sql, quote_identifiers=True)
69-
70-
def build_var_length_col(
71-
column_name: str,
72-
data_type: str,
73-
character_maximum_length: t.Optional[int] = None,
74-
numeric_precision: t.Optional[int] = None,
75-
numeric_scale: t.Optional[int] = None,
76-
) -> tuple:
77-
data_type = data_type.lower()
78-
if (
79-
data_type in self.VARIABLE_LENGTH_DATA_TYPES
80-
and character_maximum_length is not None
81-
and character_maximum_length > 0
82-
):
83-
return (column_name, f"{data_type}({character_maximum_length})")
84-
if (
85-
data_type in ("varbinary", "varchar", "nvarchar")
86-
and character_maximum_length is not None
87-
and character_maximum_length == -1
88-
):
89-
return (column_name, f"{data_type}(max)")
90-
if data_type in ("decimal", "numeric"):
91-
return (column_name, f"{data_type}({numeric_precision}, {numeric_scale})")
92-
if data_type == "float":
93-
return (column_name, f"{data_type}({numeric_precision})")
94-
95-
return (column_name, data_type)
96-
97-
columns = [build_var_length_col(*row) for row in columns_raw]
98-
99-
return {
100-
column_name: exp.DataType.build(data_type, dialect=self.dialect)
101-
for column_name, data_type in columns
102-
}
103-
10423
def _insert_overwrite_by_condition(
10524
self,
10625
table_name: TableName,

tests/core/engine_adapter/test_fabric.py

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@ def test_table_exists(adapter: FabricAdapter):
5353
assert not adapter.table_exists("db.table")
5454

5555

56-
def test_insert_overwrite_by_time_partition(adapter: FabricAdapter):
56+
def test_insert_overwrite_by_time_partition(
57+
adapter: FabricAdapter, assert_exp_eq
58+
): # Add assert_exp_eq fixture
5759
adapter.insert_overwrite_by_time_partition(
5860
"test_table",
5961
parse_one("SELECT a, b FROM tbl"),
@@ -64,11 +66,27 @@ def test_insert_overwrite_by_time_partition(adapter: FabricAdapter):
6466
columns_to_types={"a": exp.DataType.build("INT"), "b": exp.DataType.build("STRING")},
6567
)
6668

67-
# Fabric adapter should use DELETE/INSERT strategy, not MERGE.
68-
assert to_sql_calls(adapter) == [
69-
"""DELETE FROM [test_table] WHERE [b] BETWEEN '2022-01-01' AND '2022-01-02';""",
70-
"""INSERT INTO [test_table] ([a], [b]) SELECT [a], [b] FROM (SELECT [a], [b] FROM [tbl]) AS [_subquery] WHERE [b] BETWEEN '2022-01-01' AND '2022-01-02';""",
71-
]
69+
# Get the list of generated SQL strings
70+
actual_sql_calls = to_sql_calls(adapter)
71+
72+
# There should be two calls: DELETE and INSERT
73+
assert len(actual_sql_calls) == 2
74+
75+
# Assert the DELETE statement is correct (string comparison is fine for this simple one)
76+
assert (
77+
actual_sql_calls[0]
78+
== "DELETE FROM [test_table] WHERE [b] BETWEEN '2022-01-01' AND '2022-01-02';"
79+
)
80+
81+
# Assert the INSERT statement is semantically correct
82+
expected_insert_sql = """
83+
INSERT INTO [test_table] ([a], [b])
84+
SELECT [a], [b] FROM (SELECT [a], [b] FROM [tbl]) AS [_subquery]
85+
WHERE [b] BETWEEN '2022-01-01' AND '2022-01-02';
86+
"""
87+
88+
# Use assert_exp_eq to compare the parsed SQL expressions
89+
assert_exp_eq(actual_sql_calls[1], expected_insert_sql)
7290

7391

7492
def test_replace_query(adapter: FabricAdapter):

0 commit comments

Comments
 (0)