fix(snowflake): use ALTER ICEBERG TABLE to register column comments on Iceberg tables - #6038
Open
sineline wants to merge 1 commit into
Open
fix(snowflake): use ALTER ICEBERG TABLE to register column comments on Iceberg tables#6038sineline wants to merge 1 commit into
sineline wants to merge 1 commit into
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.