sqlmesh 0.227.2.dev7__py3-none-any.whl → 0.227.2.dev9__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- sqlmesh/_version.py +2 -2
- sqlmesh/core/engine_adapter/fabric.py +109 -0
- {sqlmesh-0.227.2.dev7.dist-info → sqlmesh-0.227.2.dev9.dist-info}/METADATA +1 -1
- {sqlmesh-0.227.2.dev7.dist-info → sqlmesh-0.227.2.dev9.dist-info}/RECORD +8 -8
- {sqlmesh-0.227.2.dev7.dist-info → sqlmesh-0.227.2.dev9.dist-info}/WHEEL +0 -0
- {sqlmesh-0.227.2.dev7.dist-info → sqlmesh-0.227.2.dev9.dist-info}/entry_points.txt +0 -0
- {sqlmesh-0.227.2.dev7.dist-info → sqlmesh-0.227.2.dev9.dist-info}/licenses/LICENSE +0 -0
- {sqlmesh-0.227.2.dev7.dist-info → sqlmesh-0.227.2.dev9.dist-info}/top_level.txt +0 -0
sqlmesh/_version.py
CHANGED
|
@@ -28,7 +28,7 @@ version_tuple: VERSION_TUPLE
|
|
|
28
28
|
commit_id: COMMIT_ID
|
|
29
29
|
__commit_id__: COMMIT_ID
|
|
30
30
|
|
|
31
|
-
__version__ = version = '0.227.2.
|
|
32
|
-
__version_tuple__ = version_tuple = (0, 227, 2, '
|
|
31
|
+
__version__ = version = '0.227.2.dev9'
|
|
32
|
+
__version_tuple__ = version_tuple = (0, 227, 2, 'dev9')
|
|
33
33
|
|
|
34
34
|
__commit_id__ = commit_id = None
|
|
@@ -13,6 +13,8 @@ from sqlmesh.core.engine_adapter.shared import (
|
|
|
13
13
|
)
|
|
14
14
|
from sqlmesh.utils.errors import SQLMeshError
|
|
15
15
|
from sqlmesh.utils.connection_pool import ConnectionPool
|
|
16
|
+
from sqlmesh.core.schema_diff import TableAlterOperation
|
|
17
|
+
from sqlmesh.utils import random_id
|
|
16
18
|
|
|
17
19
|
|
|
18
20
|
logger = logging.getLogger(__name__)
|
|
@@ -153,6 +155,113 @@ class FabricEngineAdapter(MSSQLEngineAdapter):
|
|
|
153
155
|
f"Unable to switch catalog to {catalog_name}, catalog ended up as {catalog_after_switch}"
|
|
154
156
|
)
|
|
155
157
|
|
|
158
|
+
def alter_table(
|
|
159
|
+
self, alter_expressions: t.Union[t.List[exp.Alter], t.List[TableAlterOperation]]
|
|
160
|
+
) -> None:
|
|
161
|
+
"""
|
|
162
|
+
Applies alter expressions to a table. Fabric has limited support for ALTER TABLE,
|
|
163
|
+
so this method implements a workaround for column type changes.
|
|
164
|
+
This method is self-contained and sets its own catalog context.
|
|
165
|
+
"""
|
|
166
|
+
if not alter_expressions:
|
|
167
|
+
return
|
|
168
|
+
|
|
169
|
+
# Get the target table from the first expression to determine the correct catalog.
|
|
170
|
+
first_op = alter_expressions[0]
|
|
171
|
+
expression = first_op.expression if isinstance(first_op, TableAlterOperation) else first_op
|
|
172
|
+
if not isinstance(expression, exp.Alter) or not expression.this.catalog:
|
|
173
|
+
# Fallback for unexpected scenarios
|
|
174
|
+
logger.warning(
|
|
175
|
+
"Could not determine catalog from alter expression, executing with current context."
|
|
176
|
+
)
|
|
177
|
+
super().alter_table(alter_expressions)
|
|
178
|
+
return
|
|
179
|
+
|
|
180
|
+
target_catalog = expression.this.catalog
|
|
181
|
+
self.set_current_catalog(target_catalog)
|
|
182
|
+
|
|
183
|
+
with self.transaction():
|
|
184
|
+
for op in alter_expressions:
|
|
185
|
+
expression = op.expression if isinstance(op, TableAlterOperation) else op
|
|
186
|
+
|
|
187
|
+
if not isinstance(expression, exp.Alter):
|
|
188
|
+
self.execute(expression)
|
|
189
|
+
continue
|
|
190
|
+
|
|
191
|
+
for action in expression.actions:
|
|
192
|
+
table_name = expression.this
|
|
193
|
+
|
|
194
|
+
table_name_without_catalog = table_name.copy()
|
|
195
|
+
table_name_without_catalog.set("catalog", None)
|
|
196
|
+
|
|
197
|
+
is_type_change = isinstance(action, exp.AlterColumn) and action.args.get(
|
|
198
|
+
"dtype"
|
|
199
|
+
)
|
|
200
|
+
|
|
201
|
+
if is_type_change:
|
|
202
|
+
column_to_alter = action.this
|
|
203
|
+
new_type = action.args["dtype"]
|
|
204
|
+
temp_column_name_str = f"{column_to_alter.name}__{random_id(short=True)}"
|
|
205
|
+
temp_column_name = exp.to_identifier(temp_column_name_str)
|
|
206
|
+
|
|
207
|
+
logger.info(
|
|
208
|
+
"Applying workaround for column '%s' on table '%s' to change type to '%s'.",
|
|
209
|
+
column_to_alter.sql(),
|
|
210
|
+
table_name.sql(),
|
|
211
|
+
new_type.sql(),
|
|
212
|
+
)
|
|
213
|
+
|
|
214
|
+
# Step 1: Add a temporary column.
|
|
215
|
+
add_column_expr = exp.Alter(
|
|
216
|
+
this=table_name_without_catalog.copy(),
|
|
217
|
+
kind="TABLE",
|
|
218
|
+
actions=[
|
|
219
|
+
exp.ColumnDef(this=temp_column_name.copy(), kind=new_type.copy())
|
|
220
|
+
],
|
|
221
|
+
)
|
|
222
|
+
add_sql = self._to_sql(add_column_expr)
|
|
223
|
+
self.execute(add_sql)
|
|
224
|
+
|
|
225
|
+
# Step 2: Copy and cast data.
|
|
226
|
+
update_sql = self._to_sql(
|
|
227
|
+
exp.Update(
|
|
228
|
+
this=table_name_without_catalog.copy(),
|
|
229
|
+
expressions=[
|
|
230
|
+
exp.EQ(
|
|
231
|
+
this=temp_column_name.copy(),
|
|
232
|
+
expression=exp.Cast(
|
|
233
|
+
this=column_to_alter.copy(), to=new_type.copy()
|
|
234
|
+
),
|
|
235
|
+
)
|
|
236
|
+
],
|
|
237
|
+
)
|
|
238
|
+
)
|
|
239
|
+
self.execute(update_sql)
|
|
240
|
+
|
|
241
|
+
# Step 3: Drop the original column.
|
|
242
|
+
drop_sql = self._to_sql(
|
|
243
|
+
exp.Alter(
|
|
244
|
+
this=table_name_without_catalog.copy(),
|
|
245
|
+
kind="TABLE",
|
|
246
|
+
actions=[exp.Drop(this=column_to_alter.copy(), kind="COLUMN")],
|
|
247
|
+
)
|
|
248
|
+
)
|
|
249
|
+
self.execute(drop_sql)
|
|
250
|
+
|
|
251
|
+
# Step 4: Rename the temporary column.
|
|
252
|
+
old_name_qualified = f"{table_name_without_catalog.sql(dialect=self.dialect)}.{temp_column_name.sql(dialect=self.dialect)}"
|
|
253
|
+
new_name_unquoted = column_to_alter.sql(
|
|
254
|
+
dialect=self.dialect, identify=False
|
|
255
|
+
)
|
|
256
|
+
rename_sql = f"EXEC sp_rename '{old_name_qualified}', '{new_name_unquoted}', 'COLUMN'"
|
|
257
|
+
self.execute(rename_sql)
|
|
258
|
+
else:
|
|
259
|
+
# For other alterations, execute directly.
|
|
260
|
+
direct_alter_expr = exp.Alter(
|
|
261
|
+
this=table_name_without_catalog.copy(), kind="TABLE", actions=[action]
|
|
262
|
+
)
|
|
263
|
+
self.execute(direct_alter_expr)
|
|
264
|
+
|
|
156
265
|
|
|
157
266
|
class FabricHttpClient:
|
|
158
267
|
def __init__(self, tenant_id: str, workspace_id: str, client_id: str, client_secret: str):
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
sqlmesh/__init__.py,sha256=v_spqQEhcnGaahp1yPvMqUIa6mhH3cs3Bc1CznxvCEA,7965
|
|
2
|
-
sqlmesh/_version.py,sha256=
|
|
2
|
+
sqlmesh/_version.py,sha256=cOMi_-qCQXj5grzVPwCKvJZwOvqQ_im_TDT2bVVjN5c,721
|
|
3
3
|
sqlmesh/magics.py,sha256=xLh3u4eqpVrKRVN5KF3X84RPRqjygAB9AJP1TXwH8hg,42086
|
|
4
4
|
sqlmesh/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
5
5
|
sqlmesh/cicd/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
@@ -66,7 +66,7 @@ sqlmesh/core/engine_adapter/bigquery.py,sha256=edBWbAbeXA4bOtVG-YNTQbt9qqwL9QFff
|
|
|
66
66
|
sqlmesh/core/engine_adapter/clickhouse.py,sha256=GWGpwdxZd4RqLSAMlOHjtO8nPpSIo3zFeRWnj9eSOrM,36072
|
|
67
67
|
sqlmesh/core/engine_adapter/databricks.py,sha256=no6X3E9T31gI-GO7wZaq2r2E7SgLROHLzmot8reVZNY,16485
|
|
68
68
|
sqlmesh/core/engine_adapter/duckdb.py,sha256=9AXeRhaYXBcYSmIavyFY9LUzfgh94qkTO98v0-suQ8I,7993
|
|
69
|
-
sqlmesh/core/engine_adapter/fabric.py,sha256=
|
|
69
|
+
sqlmesh/core/engine_adapter/fabric.py,sha256=jY1bejscEcL5r-WdGjsSGr-dWDa1awavCikrAyhDFpk,19299
|
|
70
70
|
sqlmesh/core/engine_adapter/mixins.py,sha256=3rB7B2PZSB920BODO7k_kKqu6z0N-zj1etiRCYzpUcQ,27096
|
|
71
71
|
sqlmesh/core/engine_adapter/mssql.py,sha256=pqh6D_7eAeVCH6K4-81HPcNTLEPhTM_-Mou0QWBTOfA,18898
|
|
72
72
|
sqlmesh/core/engine_adapter/mysql.py,sha256=anKxdklYY2kiuxaHsC7FPN-LKzo7BP0Hy6hinA_c5Hg,6953
|
|
@@ -238,7 +238,7 @@ sqlmesh/utils/pydantic.py,sha256=-yppkVlw6iSBaSiKjbe7OChxL-u3urOS4-KCjJEgsRU,120
|
|
|
238
238
|
sqlmesh/utils/rich.py,sha256=cwQ5nJ6sgz64xHtoh6_ec7ReV5YpsOGhMtUJnwoRfEI,3549
|
|
239
239
|
sqlmesh/utils/windows.py,sha256=0F9RdpuuCoG5NiEDXvWlAGCiJ-59OjSAmgFF5wW05aY,1133
|
|
240
240
|
sqlmesh/utils/yaml.py,sha256=KFBd7hsKNRTtRudGR7d410qUYffQv0EWRcDM8hVNNZg,3025
|
|
241
|
-
sqlmesh-0.227.2.
|
|
241
|
+
sqlmesh-0.227.2.dev9.dist-info/licenses/LICENSE,sha256=OlMefUjgWJdULtf84BLW0AZZcY8DwdgQqb_1j2862j8,11346
|
|
242
242
|
sqlmesh_dbt/__init__.py,sha256=awYS5y5mz-1NUmx6i5h5NSTJ7tidRl9NC0FAnFWSF6U,350
|
|
243
243
|
sqlmesh_dbt/cli.py,sha256=p9foHjAW9ni7BTOJ2loynk47M0Sf43QIJZRggOzF5tc,6351
|
|
244
244
|
sqlmesh_dbt/console.py,sha256=RwWLYnEZHzn9Xp-e2gbZvkdKbWbBLN146geI84mJitg,1132
|
|
@@ -363,8 +363,8 @@ web/server/api/endpoints/models.py,sha256=kwj0s7uve3iZSMfmjkoPVMFMeY1sD0peTeyrWf
|
|
|
363
363
|
web/server/api/endpoints/modules.py,sha256=8hqqgonGay_mJmpCw0IdbjsPhWlQH2VLdKAqha-myac,468
|
|
364
364
|
web/server/api/endpoints/plan.py,sha256=bbbY50W_2MsZSTxOHWMKz0tbIm75nsRSlPy8GI2fg9Q,9306
|
|
365
365
|
web/server/api/endpoints/table_diff.py,sha256=8XTwgOh6QBbNy_hTM1JuHgRjbnie-pGPrphiW-FNLjQ,6058
|
|
366
|
-
sqlmesh-0.227.2.
|
|
367
|
-
sqlmesh-0.227.2.
|
|
368
|
-
sqlmesh-0.227.2.
|
|
369
|
-
sqlmesh-0.227.2.
|
|
370
|
-
sqlmesh-0.227.2.
|
|
366
|
+
sqlmesh-0.227.2.dev9.dist-info/METADATA,sha256=QGnR-qNquQZG7U6iF9rrgLO_G9oHd2or7N57JXyT1nY,26685
|
|
367
|
+
sqlmesh-0.227.2.dev9.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
368
|
+
sqlmesh-0.227.2.dev9.dist-info/entry_points.txt,sha256=sHAf6tQczIM8xZoduN4qaUjV7QEPVUUW_LCT8EDUMv4,155
|
|
369
|
+
sqlmesh-0.227.2.dev9.dist-info/top_level.txt,sha256=RQ-33FPe2IgL0rgossAfJkCRtqslz9b7wFARqiWLC5Q,24
|
|
370
|
+
sqlmesh-0.227.2.dev9.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|