Repository navigation
Conversation
…n Iceberg tables Snowflake rejects `ALTER TABLE` for Iceberg tables and requires `ALTER ICEBERG TABLE` instead. `SnowflakeEngineAdapter._create_column_comments` builds its statement with a hardcoded `TABLE` kind, so registering column comments on an Iceberg table with a post-creation command emitted `ALTER TABLE ... ALTER COLUMN ... COMMENT`. The failure is swallowed and logged as a permissions warning, so the comments were silently dropped. This path is only taken when the comments can't be inlined into the CTAS schema definition, i.e. when the column types are not fully known. `_create_column_comments` now accepts `table_format`, mirroring the `_create_table` convention, and the base adapter passes it from the two table creation paths. The Snowflake adapter derives the Iceberg-specific table kind from it. Follow-up to SQLMesh#5722. Related: SQLMesh#5721 Signed-off-by: Guillem G <guillem.gimenez@titanos.tv>
|
@sineline Thanks for this PR! The core fix is good against Snowflake's documented syntax, and regression risk is low. But here's a few suggestions: 1. Dynamic Iceberg tables The new table_format=None if table_kind else kwargs.get("table_format"),Could you add a 2. A quick run against a real Snowflake Iceberg table would confirm the SQL beyond the unit tests. (You can spin up a free snowflake instance) |
Follow-up to #5722, related to #5721.
Snowflake rejects
ALTER TABLEfor Iceberg tables and requiresALTER ICEBERG TABLEinstead.SnowflakeEngineAdapter._create_column_commentsbuilds its statement with a hardcodedTABLEkind, so registering column comments on an Iceberg table with a post-creation command emits:The call is wrapped in
try/except, so the plan does not fail: the comments are silently dropped and a warning misattributes the failure to limited permissions.This path is only taken when the comments cannot be inlined into the CTAS schema definition, i.e. when the column types are not fully known. When the types are known, the comments are part of the
CREATE ICEBERG TABLEstatement and are registered correctly.Changes
EngineAdapter._create_column_commentsacceptstable_format, mirroring the_create_tableconvention, and the base adapter passes it from the two table creation paths (create_tableand_create_table_from_source_queries).SnowflakeEngineAdapter._create_column_commentsderives the Iceberg-specific kind from it, only when the kind isTABLE, so views are unaffected:The MySQL and BigQuery overrides gain the same parameter so their signatures stay compatible with the base class; they do not use it.
Reference: https://docs.snowflake.com/en/sql-reference/sql/alter-iceberg-table#syntax (
{ ALTER | MODIFY } [ COLUMN ] <col_name> COMMENT '<string>', comma-separated for multiple columns).Tests
test_column_comments_iceberg: a direct call emitsALTER ICEBERG TABLE ... ALTER COLUMN ... COMMENT ...for multiple columns.test_ctas_column_comments_iceberg: an end-to-endctaswith unknown column types emitsCREATE ICEBERG TABLE ... AS SELECT ...followed by theALTER ICEBERG TABLEcomment statement.The generated DDL is verified at unit level against the documented syntax; it has not been validated against a live Snowflake account.