Using Snowsight to create and manage semantic views¶
In Snowsight, you can create and manage semantic views:
创建语义视图¶
In Snowsight, you can create a semantic view by using a wizard or by uploading a semantic model specification.
Using the wizard to create a semantic view¶
备注
要创建语义视图,必须使用具有 创建语义视图所需的权限 中所述权限的角色。
Access the wizard for creating semantic views in one of the following ways:
-
Sign in to Snowsight.
In the navigation menu, select Catalog » Database Explorer.
Select the database and schema where you want to create the semantic view.
Select Create » Semantic View » Create with guided setup.
Cortex Analyst:
Sign in to Snowsight.
In the navigation menu, select AI & ML » Cortex Analyst.
Select Create new » Create new Semantic View.
-
In the Getting started step in the wizard:
From Location to store, select the database and schema where the model should be stored.
In Name, enter a name for your semantic view.
必须指定以字母或下划线开头且仅包含字母、数字、下划线或美元符号的名称。
(Optional) In Description, describe the data that your semantic view makes available.
Select Next.
在向导的 Select tables 步骤中:
In the All tab, select the tables or views that contain the data that you want to use in your semantic view. Note the following:
必须选择至少一个表或视图。
为了获得更好的性能,选择的表不要超过十个。
如果要查看所选表和视图的列表,请选择 Selected 选项卡。
Select Next.
在向导的 Select columns 步骤中:
Select the columns to include in the view.
要选择表或视图中的所有列,请选择表或视图。
为了获得更好的性能,请不要选择超过 50 个列。
选择 Create and Save。
在 Logical tables 下:
查看为每个表或视图定义的事实、维度和指标。
提供对企业友好的名称和描述。
添加所需的任何其他事实、维度和指标。
在 Relationships 下:
确认生成器定义的所有关系。
根据需要修改关系属性。
添加所需的任何其他关系。
If you made any changes to the semantic view, select Save.
Uploading a YAML specification to create a semantic view¶
If you are planning to create the semantic view from Cortex Analyst, create a stage for the YAML file.
Upload the YAML file in one of the following ways:
-
Sign in to Snowsight.
In the navigation menu, select Catalog » Database Explorer.
Select the database and schema where you want to create the semantic view.
Select Create » Semantic View » Upload YAML file.
Select the YAML file to upload.
Under Select database, schema and stage, select the database, schema, and stage where you want to upload the YAML file.
If you want the YAML file uploaded to a specific path in the stage, specify that path.
Select Upload.
Cortex Analyst:
Sign in to Snowsight.
In the navigation menu, select AI & ML » Cortex Analyst.
Select Create new » Upload YAML file.
Select the YAML file to upload.
Select Convert and save.
-
编辑语义视图¶
要编辑语义视图,请执行以下操作:
Access the semantic view in one of the following ways:
-
Sign in to Snowsight.
In the navigation menu, select Catalog » Database Explorer.
Select the database and schema containing the semantic view.
Select Semantic views.
Select the semantic view.
Select the Semantic information tab.
Cortex Analyst:
Sign in to Snowsight.
In the navigation menu, select AI & ML » Cortex Analyst.
Select the Semantic views tab.
Under Select database to see semantic views, select the database and schema containing the semantic view that you want to edit.
Select the semantic view that you want to edit.
-
Make changes to the semantic view. You can make the following types of changes:
To modify the name or description of the semantic view:
Select Edit next to the name of the semantic view.
Make changes to the name or description.
Select Apply.
To add a new logical table to the semantic view:
Select + Logical Table in the database object explorer or + in Cortex Analyst.
In the Select a table step in the wizard:
Select the table or view that contains the data that you want to use in your semantic view.
Select Next.
在向导的 Select columns 步骤中:
Select the columns to include in the view.
要选择表或视图中的所有列,请选择表或视图。
Select Generate logical table.
To make changes to the name, description, synonyms, or primary key of a logical table in the semantic view:
Select
» Edit Logical Table next to the logical table name in the database object explorer or Edit next to the logical table name in Cortex Analyst.
Make your changes to the name, description, synonyms, and primary key.
If you have not specified the description or synonyms, you can select Generate fields to fill in these fields automatically.
Select Save.
To add a fact, dimension, or metric:
To modify or remove a fact, dimension, or metric:
To add a relationship:
Open the form for adding the new item:
In the database object explorer, select + Relationship.
In Cortex Analyst, select + next to Relationships.
Enter a name for the relationship, select the tables in the relationship, and select the columns to use to join the tables.
Select Add.
If you plan to use Cortex Analyst with this view, consider the following:
Add sample queries to the Verified Queries section. Note that this section is available only in Cortex Analyst.
这些示例查询可帮助 Cortex Analyst 了解如何使用语义视图。
添加代表数据常见用例的查询。
为您的表、事实、维度或指标添加同义词。
这些同义词是用户可能在查询中使用的替代术语。
同义词有助于 Cortex Analyst 正确解释用户的问题。
添加自定义指令。
它们为如何解释数据提供了更多上下文信息。
包括应考虑的业务规则或限制。
Select Save.
Granting the privilege to use a semantic view to another role¶
To grant another role the privileges to view and query a semantic view:
Access the semantic view in one of the following ways:
-
Sign in to Snowsight.
In the navigation menu, select Catalog » Database Explorer.
Select the database and schema containing the semantic view.
Select Semantic views.
Select the semantic view.
Cortex Analyst:
Sign in to Snowsight.
In the navigation menu, select AI & ML » Cortex Analyst.
Select the Semantic views tab.
Select the semantic view.
Select Share.
-
Select the role that should be granted the privileges to view and query the semantic view.
Select Done.
This grants the SELECT and REFERENCES privileges on the semantic view to the selected role.
Querying a semantic view¶
If you are viewing a semantic view in the database object explorer, you can open a worksheet to construct a query for that view
by selecting » Query with SQL.
For information on how to construct the query, see 查询语义视图.
Best practices for creating a semantic view¶
提供清晰的描述:
在所有名称和描述中使用业务术语。
使描述足够详细,以方便非技术用户理解。
包括代表性的用户问题:
包括可以帮助模型生成器更好地理解您的意图的问题。
包括提问方式的变体。
仔细查看生成的建议:
确保问题与用例相关。
确保建议的关系符合您的业务理解。
使用真实问题进行测试:
创建语义视图后,使用实际业务问题对其进行测试。
根据模型对这些问题的支持程度,完善语义视图。
迭代开发语义视图:
从一个简单的星型架构开始。
从核心表和指标开始,然后扩展。为了简单起见,建议使用三个表。
获取业务用户的反馈,并完善您的语义视图。
故障排除¶
If your semantic view is not listed in the list of views, refresh the list of models (not the page itself).
如果语义视图中的关系出现错误,请确保这些关系与实际数据结构相匹配。
如果查询速度很慢,请减少表或列的数量。
如果在使用语义视图时 Cortex Analyst 产生意外的结果,请查看语义视图中的事实、维度和指标。