Semantic View Editor¶
Snowsight 中的 Semantic View Editor 提供用于创建和编辑 语义视图 的可视化界面。无论是要细化由 Autopilot 创建的视图、从头开始构建视图,还是编辑上传的 YAML 规范,编辑器可帮助您定义业务概念、指标和数据关系。
The Semantic View Editor allows you to:
Define logical tables that map to your physical database tables
创建维度(分类属性)、事实(行级数据)和指标(汇总度量值)
Establish relationships between tables
添加已验证的查询作为 Cortex Analyst 示例
Provide custom instructions for query generation
配置同义词和描述以提高可发现性
访问编辑器¶
You can access the Semantic View Editor through the data catalog or through Cortex Analyst.
通过数据目录¶
要通过数据目录访问现有语义视图,请执行以下操作:
登录 Snowsight。
In the navigation menu, select Catalog » Database Explorer
Navigate to your database and schema.
Select Semantic Views in the object list.
Select the semantic view you want to edit.
Select the Semantic information tab to open the editor.
通过 Cortex Analyst¶
To access semantic views through Cortex Analyst:
登录 Snowsight。
在导航菜单中,选择 AI & ML » Cortex Analyst。
Select the Semantic Views tab.
要么:
选择现有视图进行编辑
Select Create new to create a new semantic view
Edit semantic view metadata¶
语义视图名称和描述可帮助用户发现和理解视图的用途。
To edit the semantic view name or description:
In the editor, select Edit next to the semantic view name at the top of the page.
更新 Name 或 Description 字段。
选择 Save。
小技巧
撰写清晰、详细的描述,说明以下内容:
此视图可以解答哪些业务问题
其中包括哪些数据源
谁应该使用此视图
示例:“跨产品和客户的收入分析,包括同比趋势。使用此视图按区域、产品类别和客户群分析销售业绩。”
Manage logical tables¶
逻辑表表示业务实体(例如客户、订单或产品),并映射到物理数据库表或视图。每个语义视图都包含一个或多个逻辑表。
Add a logical table¶
要将逻辑表添加到语义视图,请执行以下操作:
In the editor, select + Logical Table.
Browse and select the physical table or view from your database.
选择 Next。
Choose which columns to include from the table.
选择 Generate logical table。
编辑器会根据所选列自动生成维度和事实。
Edit a logical table¶
To modify an existing logical table:
Select Edit next to the table name (or select More options » Edit Logical Table).
修改表属性:
Name:选择使用 时默认使用的角色和仓库。此表的业务友好名称
Description:选择使用 时默认使用的角色和仓库。此表所表示内容的说明
Synonyms: Alternative names (comma-separated)
Primary Key:选择使用 时默认使用的角色和仓库。唯一标识行的列
选择 Save。
小技巧
Use the Generate fields button to let AI automatically fill in descriptions and synonyms based on your data and column names. This can significantly speed up the initial setup process.
Managing facts, dimensions, and metrics¶
在每个逻辑表中,您可以定义用户可以查询的业务概念:维度、事实和指标。
了解内容类型¶
维度:提供上下文的分类属性(例如客户名称、产品类别或订单日期)
Facts: Row-level quantitative data (such as, sale amount, quantity, or unit price)
指标:SUM、AVG 或 COUNT 等函数计算的汇总度量值(例如总收入、平均订单价值)
添加维度、事实或指标¶
要将新项目添加到逻辑表中,请执行以下操作:
在编辑器中导航到逻辑表。
Select + next to Dimensions, Facts, or Metrics.
Enter the required details:
Name:选择使用 时默认使用的角色和仓库。此项目的描述性名称
Expression:用于计算值的 SQL 表达式
Data Type:选择使用 时默认使用的角色和仓库。结果的数据类型
Select Add
Edit or remove items¶
要修改或删除现有维度、事实或指标,请执行以下操作:
选择项目以打开其详细信息并编辑属性。
Or select More options » Remove to delete the item.
Select Save to apply changes.
高级功能¶
派生指标:您可以创建组合多个表中指标的视图级指标。有关更多信息,请参阅 Defining derived metrics。
专用访问修饰符:将事实或指标标记为专用,即可在查询中隐藏它们,同时仍能在其他计算中使用。有关更多信息,请参阅 Marking a fact or metric as private。
管理关系¶
关系定义了逻辑表如何联接在一起,从而实现跨多个表的查询。每个关系定义一个表中的哪些列引用另一个表中的列。
Adding a relationship¶
要在创建两个逻辑表之间的关系,请执行以下操作:
In the editor, select + next to Relationships.
Enter a descriptive Name for the relationship (for example, "orders_to_customers").
Select the Left Table (the table with the foreign key).
选择 :ui:`Right Table`(被引用的表)。
Specify the Join Columns for each table:
Left Column:选择使用 时默认使用的角色和仓库。左侧表中的外键列
Right Column:选择使用 时默认使用的角色和仓库。右侧表中的主键或唯一列
选择 Add。
The relationship now appears in the Relationships list and enables Cortex Analyst to generate queries that join these tables.
备注
对于语义视图,通常不需要指定联接类型(左外部、内部)或关系类型(一对一、多对一)。这些是在查询时从数据和主键定义中自动推断出来的。
Editing or removing relationships¶
To modify or delete a relationship:
Select the relationship to view its details.
根据需要编辑属性,或选择 Remove 将其删除。
Select Save to apply changes.
Advanced features for Cortex Analyst¶
要提高 Cortex Analyst 的准确性和可靠性,您可以通过经过验证的查询、同义词和自定义指令添加上下文和指导。
经过验证的查询¶
经过验证的查询提供示例问题及其正确的 SQL 答案。它们有两个用途:
帮助 Cortex Analyst 了解如何回答类似问题
为用户提供入门建议问题
Adding a verified query:
选择 Verified Queries 旁边的 +。
输入自然语言 :ui:`Question`(例如,“收入排名前 10 的产品是哪些?”)。
Enter the corresponding SQL Query that correctly answers the question.
(可选)检查 Use as onboarding question 是否将其显示为向用户提供的建议。
选择 Add。
小技巧
Add verified queries for:
用户可能会问的常见业务问题
需要特定逻辑的复杂查询
边缘情况或异常计算
展示视图功能的问题
同义词¶
备注
手动添加同义词,而不是使用 AI 自动生成同义词。专注于特定领域的备用名称,例如内部术语、缩写或旧名称。自动生成的同义词通常会降低语义视图的质量。
Synonyms help users discover and query your data using alternative terminology. For example, users might refer to "customers" as "clients" or "accounts."
向表或字段添加同义词:
Navigate to the table, dimension, fact, or metric you want to add synonyms for.
Select Edit to open the item's properties.
在 Synonyms 字段中输入替代术语,并用逗号分隔。
选择 Save。
Example synonyms:
对于“customer_name”维度:“client name、account name、buyer name”
对于“revenue”指标:“sales、income、earnings”
对于“orders”表:“sales orders、purchases”
自定义指令¶
自定义指令针对 SQL 生成和问题分类提供 Cortex Analyst 的具体指导。使用自定义指令执行以下操作:
定义业务规则和约束
指定默认行为
处理有歧义的问题
拒绝某些类型的问题
Add a custom instruction by:
In the editor, select the Custom Instructions section.
使用自然语言输入指令。示例:
"Always filter by active customers (status = 'ACTIVE') unless specified otherwise"
“将所有货币值四舍五入到小数点后 2 位”
“当询问收入时,除非明确要求提供总收入,否则使用 net_revenue 指标”
“如果问题在未指定区域的情况下询问用户,则要求用户明确是哪个区域”
选择 Save。
有关语义视图自定义指令的更多信息,请参阅 Providing custom instructions for Cortex Analyst。
上传 YAML 文件¶
如果您有现有的语义视图 YAML 规范或旧的语义模型 YAML 文件,可以上传该文件以创建新的语义视图或更新现有语义视图。
To upload a YAML file:
在导航菜单中,选择 AI & ML » Cortex Analyst。
选择 Create new » Upload YAML file。
Browse and select your YAML file.
在编辑器中查看生成的语义视图结构。
Select Convert and save to create the semantic view as a schema-level object.
编辑器将 YAML 规范转换为原生 Snowflake 语义视图,然后您可以使用可视化界面进行编辑。
有关 YAML 规范格式的信息,请参阅 语义视图的 YAML 规范。
有关以编程方式将规范转换为语义视图的信息,请参阅 根据 YAML 规范创建语义视图。