Add persist_docs support for semantic views - #7
Conversation
Implements relation-level persist_docs functionality that automatically adds model descriptions from schema.yml as COMMENT clauses to Semantic View DDL. Key features: - Supports persist_docs.relation configuration - Detects and avoids conflicts with existing inline COMMENT syntax - Follows existing copy_grants pattern for consistency - Includes comprehensive test coverage for both enabled and disabled scenarios Resolves the TODO in semantic_view materialization and addresses the "persist_docs not supported" limitation documented in README.
|
Hey @sfc-gh-yutliu could we push this? 🙏🏻 |
|
This would be great to have! |
|
Hey @sfc-gh-yutliu 👋 Just checking in — any chance this could get a review when you have a moment? Happy to make any changes if needed. Thanks! |
|
This is not only nice to have but a feature that can make the difference between keeping on using dbt / metricflow semantic layer VS fully adopting Snowflake solutions and downstream AI capabilities. Any chance this can be pushed? 🙏 |
|
@RyutoYoda please resolve the conflicts in this PR before merging, thanks |
|
@sfc-gh-sarur @RyutoYoda anything to do to get this merged? Not familiar on how to contribute/finish for this, but as @LizzyHunter said this will increase adoption of Snowflake semantic views for teams like mine that use dbt |
- create.sql: keep both feature sets; apply the persist_docs COMMENT before the copy_grants handling, for CREATE OR REPLACE and CREATE OR ALTER alike - README: document persist_docs as a config option alongside the new ones - schema.yml: keep both integration test models
Snowflake rejects MAX_STALENESS followed by COMMENT with a syntax error, so persist_docs combined with max_staleness produced invalid DDL. Append the COMMENT first, then MAX_STALENESS, then COPY GRANTS.
Its body ended with MAX_STALENESS followed by COMMENT, which Snowflake rejects, so the model failed to build regardless of persist_docs.
| {%- if persist_docs.get('relation', false) and model.description -%} | ||
| {%- set relation_comment = model.description -%} | ||
| {%- endif -%} |
There was a problem hiding this comment.
🟠 MEDIUM · COMMENT injection via unescaped model description in append_comment_if_missing enables SQL DDL breakout [NEW] · CWE-89
|
@sfc-gh-sarur Conflicts are resolved and the PR is mergeable again. The security bot check passed. Your earlier approval was dismissed by the new commits, so this needs another look when you have a moment. Two things worth knowing before you review. 1. Snowflake requires -- rejected: syntax error line 6 at position 0 unexpected 'COMMENT'.
MAX_STALENESS = '1 hour'
COMMENT='...'
-- accepted
COMMENT='...'
MAX_STALENESS = '1 hour'
COPY GRANTSThe macro now appends the trailing clauses in that order. 2. Its body ends with Verification I rendered the DDL that the macro actually emits for each config combination and ran it against Snowflake, then asserted on
Commits
|
|
@sfc-gh-yutliu tagging you as well, since you own most of this area of the package. Short version: the conflicts with The one item that may need your judgement is that |
An apostrophe in a model description terminated the string literal and broke the DDL. Double the quotes, matching how the package already escapes the semantic view name for the materializations SP.
Summary
Implements relation-level
persist_docsfunctionality for semantic views, addressing the "persist_docs not supported" limitation mentioned in the README and resolving the TODO comment in the materialization.schema.ymlasCOMMENTclauses to Semantic View DDLCOMMENTsyntaxcopy_grantspattern for consistencyUsage Example
Results in DDL with:
COMMENT='Customer metrics for analysis'Test Plan
Changes
macros/relations/semantic_view/create.sqlwith newappend_comment_if_missingmacromacros/materializations/semantic_view.sqlto remove TODO comment