- Categories:
System functions (Information)
SYSTEM$READ_ OSI_ YAML_ FROM_ SEMANTIC_ VIEW¶
Reads an existing semantic view and returns its definition as an Open Semantic Interchange (OSI) YAML document.
OSI is an open standard for representing semantic models that enables interoperability across AI and BI tools. This function converts the semantic view’s internal representation to OSI format and returns the resulting YAML string. Snowflake-specific features that have no OSI equivalent are preserved in vendor custom extensions so they survive a round-trip through external tools.
Syntax¶
Arguments¶
'fully_qualified_semantic_view_name'The fully qualified name of an existing semantic view, in the form
database_name.schema_name.semantic_view_name.If any part of the name contains special characters (spaces, mixed case), wrap each part in double quotes inside the single-quoted argument string. For example:
'"my database"."my schema"."My Model"'.
Returns¶
On success, returns a VARCHAR containing the OSI YAML document in the standard document wrapper format:
If the semantic view doesn’t exist or the calling role lacks privileges, the function raises an exception with a descriptive error message.
Access control requirements¶
A role used to execute this SQL command must have at least one of the following privileges at a minimum:
| Privilege | Object | Notes |
|---|---|---|
| SELECT or USAGE | Semantic view | Required to read the semantic view definition. |
Operating on an object in a schema requires at least one privilege on the parent database and at least one privilege on the parent schema.
For instructions on creating a custom role with a specified set of privileges, see Creating custom roles.
For general information about roles and privilege grants for performing SQL actions on securable objects, see Overview of Access Control.
Snowflake-to-OSI mapping reference¶
| Snowflake semantic view construct | OSI construct | Notes |
|---|---|---|
tables | datasets | Each table becomes a dataset. |
tables[*].base_table (table ref) | datasets[*].source | Reconstructed as db.schema.table dotted name. |
tables[*].base_table (subquery) | datasets[*].source | Returned as the raw SQL definition string. |
tables[*].primary_key.columns | datasets[*].primary_key | List of column names. |
tables[*].unique_keys[*].columns | datasets[*].unique_keys | List of lists of column names. |
dimensions | fields with dimension (is_time: false) | Dimension marker added, is_time defaults to false. |
time_dimensions | fields with dimension.is_time: true | Dimension marker added with is_time set to true. |
facts | fields without dimension | No dimension marker on the field. |
metrics (model-level) | metrics | Preserved at the top level of the semantic model. |
| relationships (EQUI only) | relationships | Only equi-join relationships are exported. |
Extension metadata (version, ai_context, custom_extensions) | Restored to top-level OSI fields | Round-tripped from the write path’s stored extension properties. |
Field expression handling¶
Every field and metric expression is emitted with a single SNOWFLAKE dialect entry:
If the view was originally created from OSI YAML that included an ANSI_SQL dialect, only the SNOWFLAKE expression
is returned (since Snowflake stores a single resolved expression internally).
Snowflake-specific data in custom_ extensions¶
Snowflake features that have no direct OSI representation are serialized into a SNOWFLAKE vendor custom extension
at the appropriate level. External tools can ignore these extensions or pass them through unchanged.
Model-level SNOWFLAKE extension:
| Field | Included when |
|---|---|
max_staleness | Model has a staleness policy. |
custom_instructions | Model has AI instructions. |
module_custom_instructions | Model has module-level instructions. |
variables | Model defines variables. |
verified_queries | Model has verified query examples. |
tags | Model has tags. |
Dataset-level SNOWFLAKE extension:
| Field | Included when |
|---|---|
synonyms | Dataset has synonym names. |
metrics | Dataset has table-level metrics (not representable as OSI global metrics). |
filters | Dataset has table-level filters. |
tags | Dataset has tags. |
constraints | Dataset has constraint definitions. |
Field-level SNOWFLAKE extension:
| Field | Applies to | Included when |
|---|---|---|
synonyms | Dimensions | Field has synonym names. |
tags | Dimensions | Field has tags. |
sample_values | Dimensions, TimeDimensions, Facts | Field has sample values. |
cortex_search_service | Dimensions | Field is backed by a Cortex Search service. |
is_enum | Dimensions | Field is marked as an enumeration. |
access_modifier | Facts | Field has a non-default access modifier. |
Metric-level SNOWFLAKE extension:
| Field | Included when |
|---|---|
synonyms | Metric has synonym names. |
access_modifier | Metric has a non-default access modifier. |
non_additive_dimensions | Metric specifies non-additive dimensions. |
additive_dimensions | Metric specifies additive dimensions. |
using_relationships | Metric declares relationship usage. |
tags | Metric has tags. |
What is converted faithfully¶
The following survive a full round-trip (write OSI YAML then read it back):
- Model name, description, and version
- Dataset names, descriptions, sources (qualified names and subqueries)
- Primary keys and unique keys
- All field names, descriptions, and expressions
- Field classification (dimension vs. time_dimension vs. fact)
- Equi-join relationships (name, from/to tables, column mappings)
- Model-level metrics (name, description, expression)
ai_contextat model, dataset, and field levelscustom_extensionsfrom any vendor (DBT, SALESFORCE, DATABRICKS, COMMON, SNOWFLAKE)
What is lost or not converted¶
| OSI concept / Snowflake feature | Behavior | Reason |
|---|---|---|
| Non-EQUI relationships (ASOF, RANGE) | Silently dropped from output. | OSI spec only defines equi-join semantics. |
| Field labels | Lost on round-trip. | The write path doesn’t persist the label property. |
| Data types | Not included in output. | By design, OSI fields carry expressions, not storage types. |
| Multi-dialect expressions | Only SNOWFLAKE dialect returned. | Snowflake stores a single resolved expression. |
| Table-level metrics | Moved to dataset custom_extensions. | OSI only supports model-level metrics. |
| Table-level filters | Moved to dataset custom_extensions. | No OSI equivalent. Preserved for round-trip via extension. |
Usage notes¶
- The output always uses the document wrapper format (top-level
version+semantic_modelarray with one entry), regardless of whether the view was created from the flat or wrapper format. - Semantic views created by any method (native YAML, DDL, or OSI YAML) can be exported with this function.
Snowflake-specific features appear in the
SNOWFLAKEvendor extension. - Null fields are omitted from the output YAML (no empty keys cluttering the document).
- The output
versionfield is determined as follows:- If the semantic view was originally created from OSI YAML, the version stored in extension metadata is used.
- If the semantic view was created through native YAML or SQL (no stored OSI version), the default version
"0.1.1"is used.
If the name of the database, schema, or view is a double-quoted identifier (for example, if the name contains spaces), you must include double quotes around the name. For example:
Examples¶
Read a semantic view as OSI YAML¶
Returns:
Read a view that has Snowflake-specific features¶
Returns (Snowflake-specific features appear in custom_extensions):