SYSTEM$CREATE_ SEMANTIC_ VIEW_ FROM_ OSI_ YAML¶
Creates a semantic view from a semantic model specification written in Open Semantic Interchange (OSI) YAML format.
OSI is an open standard for representing semantic models that enables interoperability across AI and BI tools. This stored procedure accepts an OSI YAML document, converts it to the Snowflake semantic model format, and creates the corresponding semantic view in the specified schema. If a semantic view with the same name already exists, the procedure attempts to replace it while preserving existing grants. This has the same effect as running CREATE OR REPLACE SEMANTIC VIEW … COPY GRANTS.
Syntax¶
Arguments¶
'fully_qualified_schema_name'Fully qualified name of the schema where you want to create the semantic view, in the form
database_name.schema_name.You must qualify the schema name with the database name (for example,
my_db.my_schema). Otherwise, an error occurs.'osi_yaml_specification'The semantic model definition as a YAML string conforming to the OSI Core Metadata Spec.
If the specification contains quotes, backslashes, or newlines, you can use a dollar-quoted string constant for this argument.
Returns¶
On success, returns the following VARCHAR string:
If the OSI YAML is invalid, the schema isn’t found, column references can’t be resolved, or any other validation error occurs, the procedure raises an exception with a descriptive error message.
Access control requirements¶
A role used to execute this operation must have the following privileges at a minimum:
| Privilege | Object | Notes |
|---|---|---|
| CREATE SEMANTIC VIEW | Schema | Required to create a new semantic view. |
| SELECT | Table, view | Required on any tables or views referenced in datasets[*].source. |
| OWNERSHIP | Existing semantic view with the same name. | Required only if a semantic view with that name already exists and needs to be replaced. OWNERSHIP is a special privilege on an object that is automatically granted to the role that created the object, but can also be transferred using the GRANT OWNERSHIP command to a different role by the owning role (or any role with the MANAGE GRANTS privilege). |
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.
OSI YAML specification¶
The top-level fields that Snowflake recognizes in the OSI YAML are:
| Field | Required | Description |
|---|---|---|
name | Yes | Unique identifier for the semantic model. Becomes the semantic view name. |
version | Yes | OSI specification version (for example, "0.1.1"). Must be a supported version. |
description | No | Human-readable description of the semantic model. |
ai_context | No | Additional natural-language context for AI tools. Preserved in the view’s extension metadata. |
datasets | No | Logical datasets (tables/views) that underlie the model. See Dataset fields. |
relationships | No | Foreign-key relationships between datasets. See Relationship fields. |
metrics | No | Model-level aggregate metrics. See Metric fields. |
custom_extensions | No | Vendor-specific extension metadata. Preserved as-is. |
Dataset fields¶
Each entry in datasets maps to a table in the Snowflake semantic view.
| Field | Required | Description |
|---|---|---|
name | Yes | Logical dataset name. |
source | No | Fully qualified table/view reference (db.schema.table) or a SQL subquery starting with SELECT or WITH. |
primary_key | No | List of column names forming the primary key (for example, ["order_id"]). |
unique_keys | No | List of unique key definitions. Each entry is a list of column names. |
description | No | Human-readable description of the dataset. |
ai_context | No | AI-tool context for the dataset. Preserved in extension metadata. |
fields | No | Row-level field definitions. See Field classification. |
custom_extensions | No | Vendor-specific extension metadata. |
Field classification¶
Each entry in datasets[*].fields is converted to one of three Snowflake column types based on its dimension marker:
| OSI field type | Snowflake column type |
|---|---|
dimension.is_time: true | time_dimensions |
dimension present (non-time) | dimensions |
No dimension marker | facts |
Each field must specify an expression with at least one supported dialect entry:
Snowflake prefers the SNOWFLAKE dialect. If not present, it falls back to ANSI_SQL. Fields that
have no SNOWFLAKE or ANSI_SQL dialect expression are silently skipped during conversion.
Relationship fields¶
| Field | Required | Description |
|---|---|---|
name | No | Identifier for the relationship. |
from | Yes | Dataset on the many side (contains the foreign key). Maps to left_table. |
to | Yes | Dataset on the one side (contains the primary/unique key). Maps to right_table. |
from_columns | Yes | Foreign key column names in the from dataset. |
to_columns | Yes | Corresponding key column names in the to dataset. Must be the same length as from_columns. |
custom_extensions | No | Vendor-specific extension metadata. |
Metric fields¶
| Field | Required | Description |
|---|---|---|
name | Yes | Unique metric identifier. |
expression | Yes | Aggregate expression with dialect support (same structure as field expressions). |
description | No | Human-readable description of the metric. |
ai_context | No | AI-tool context. Preserved in extension metadata. |
custom_extensions | No | Vendor-specific extension metadata. |
Metrics without a SNOWFLAKE or ANSI_SQL dialect expression are silently skipped.
Usage notes¶
- The
versionfield in the OSI YAML must be a supported version. Currently supported:0.1.1. Unsupported versions cause the procedure to raise an error listing the supported values. - The semantic view name is taken from the
namefield in the OSI YAML. The view is created in the schema identified byfully_qualified_schema_name. - Expression dialect priority:
SNOWFLAKEis used when present; otherwiseANSI_SQLis used as a fallback. Fields or metrics that have only non-supported dialects are silently omitted from the created view. - Dataset source values are parsed as follows:
- A string starting with
SELECTorWITHis treated as an inline subquery and mapped tobase_table.definition. - A dotted identifier such as
sales_db.public.ordersis resolved tobase_table.database/schema/table. - Unrecognized source strings are ignored (no
base_tableis set).
- A string starting with
- OSI metadata not natively represented in Snowflake’s semantic view format (
ai_context,custom_extensions,version) is preserved in the view’s extension metadata.
If the name of the database or schema is a double-quoted identifier (for example, if the name contains spaces), you must include double quotes around the name. For example:
OSI field-to-Snowflake mapping reference¶
| OSI construct | Snowflake semantic view construct |
|---|---|
datasets | tables |
datasets[*].source | tables[*].base_table (table ref or subquery) |
datasets[*].primary_key | tables[*].primary_key.columns |
datasets[*].unique_keys | tables[*].unique_keys[*].columns |
fields with dimension.is_time: true | time_dimensions |
fields with dimension (non-time) | dimensions |
fields without dimension | facts |
relationships[*].from | relationships[*].left_table |
relationships[*].to | relationships[*].right_table |
relationships[*].from_columns / to_columns | relationships[*].relationship_columns[*].left_column / right_column |
metrics | metrics (model-level) |
ai_context, custom_extensions, version | Preserved in extension metadata |