Skip to content

Commit 60d0b1a

Browse files
sinelineGuillem G.
authored andcommitted
feat: Implement special DDL generation for Snowflake Iceberg tables with PARTITION BY to correctly handle property ordering and CTAS limitations.
1 parent 8263170 commit 60d0b1a

File tree

4 files changed

+15
-9
lines changed

4 files changed

+15
-9
lines changed

sqlmesh/core/config/connection.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2013,8 +2013,9 @@ def _static_connection_kwargs(self) -> t.Dict[str, t.Any]:
20132013
OAuth2Authentication,
20142014
)
20152015

2016+
auth: t.Any
20162017
if self.method.is_basic or self.method.is_ldap:
2017-
auth = BasicAuthentication(self.user, self.password)
2018+
auth = BasicAuthentication(self.user, self.password or "")
20182019
elif self.method.is_kerberos:
20192020
if self.keytab:
20202021
os.environ["KRB5_CLIENT_KTNAME"] = self.keytab
@@ -2032,9 +2033,11 @@ def _static_connection_kwargs(self) -> t.Dict[str, t.Any]:
20322033
elif self.method.is_oauth:
20332034
auth = OAuth2Authentication()
20342035
elif self.method.is_jwt:
2035-
auth = JWTAuthentication(self.jwt_token)
2036+
auth = JWTAuthentication(self.jwt_token or "")
20362037
elif self.method.is_certificate:
2037-
auth = CertificateAuthentication(self.client_certificate, self.client_private_key)
2038+
auth = CertificateAuthentication(
2039+
self.client_certificate or "", self.client_private_key or ""
2040+
)
20382041
else:
20392042
auth = None
20402043

sqlmesh/core/engine_adapter/base.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -295,8 +295,8 @@ def _get_source_queries(
295295
)
296296
for c in target_columns_to_types
297297
]
298-
query_factory = (
299-
lambda: exp.Select()
298+
query_factory = lambda: (
299+
exp.Select()
300300
.select(*select_columns)
301301
.from_(query_or_df.subquery("select_source_columns"))
302302
)
@@ -1184,7 +1184,6 @@ def get_alter_operations(
11841184
def alter_table(
11851185
self,
11861186
alter_expressions: t.Union[t.List[exp.Alter], t.List[TableAlterOperation]],
1187-
**kwargs: t.Any,
11881187
) -> None:
11891188
"""
11901189
Performs the alter statements to change the current table into the structure of the target table.

sqlmesh/core/engine_adapter/snowflake.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
SnowparkSession,
4343
)
4444
from sqlmesh.core.node import IntervalUnit
45+
from sqlmesh.core.schema_diff import TableAlterOperation
4546

4647

4748
@set_catalog(
@@ -689,7 +690,7 @@ def clone_table(
689690
**kwargs,
690691
)
691692

692-
def alter_table(
693+
def alter_table( # type: ignore[override]
693694
self,
694695
alter_expressions: t.Union[t.List[exp.Alter], t.List["TableAlterOperation"]],
695696
**kwargs: t.Any,
@@ -712,7 +713,7 @@ def alter_table(
712713
for alter_expr in resolved_expressions:
713714
self.execute(alter_expr)
714715
else:
715-
super().alter_table(alter_expressions, **kwargs)
716+
super().alter_table(alter_expressions)
716717

717718
@t.overload
718719
def _columns_to_types(

sqlmesh/core/snapshot/evaluator.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2109,7 +2109,10 @@ def migrate(
21092109
_check_additive_schema_change(
21102110
snapshot, alter_operations, kwargs["allow_additive_snapshots"]
21112111
)
2112-
self.adapter.alter_table(alter_operations, table_format=snapshot.model.table_format)
2112+
alter_kwargs: t.Dict[str, t.Any] = {}
2113+
if snapshot.model.table_format:
2114+
alter_kwargs["table_format"] = snapshot.model.table_format
2115+
self.adapter.alter_table(alter_operations, **alter_kwargs)
21132116

21142117
# Apply grants after schema migration
21152118
deployability_index = kwargs.get("deployability_index")

0 commit comments

Comments
 (0)