使用 SQL 命令创建和管理语义视图¶
本主题介绍如何使用以下 SQL 命令创建和管理 语义视图:
This topic also explains how to call the following stored procedure and function to create a semantic view from a YAML specification and get the specification for a semantic view:
Privileges required to create or replace a semantic view¶
To create or replace a semantic view, you must use a role with the following privileges:
对创建语义视图所在的架构具有 CREATE SEMANTIC VIEW 权限。
对创建语义视图所在的数据库和架构具有 USAGE 权限。
SELECT on the tables and views used in the semantic view.
有关查询语义视图所需权限的信息,请参阅 查询语义视图所需的权限。
Creating a semantic view by using the CREATE SEMANTIC VIEW command¶
To create a semantic view, use the CREATE SEMANTIC VIEW command.
备注
To create a semantic view from a YAML specification, call the SYSTEM$CREATE_SEMANTIC_VIEW_FROM_YAML stored procedure.
语义视图必须是有效的。请参阅 Snowflake 如何验证语义视图。
The following example uses the TPC-H sample data available in Snowflake. This data set contains tables that represent a simplified business scenario with customers, orders, and line items.
该示例使用 TPC-H 数据集中的表创建了一个名为 tpch_rev_analysis 的语义视图。该语义视图定义了以下内容:
三个逻辑表(
orders、customers和line_items)。orders和customers表之间的关系。line_items和orders表之间的关系。将用于计算指标的事实。
展示:包括客户名称、订单日期,以及下单年份。
指标:每个订单的平均金额和每个订单中明细项的平均数量。
接下来的章节将对此示例进行更详细的介绍:
备注
有关完整示例,请参阅 使用 SQL 创建语义视图的示例。
定义逻辑表¶
在 CREATE SEMANTIC VIEW 命令中,使用 TABLES 子句定义视图中的逻辑表。在本子句中,您可以执行以下操作:
指定物理表名和可选别名。
识别逻辑表中的以下列:
用作主键的列。
包含唯一值的列(主键列除外)。
您可以使用这些列在此语义视图中定义关系。
为表添加同义词(以增强可发现性)。
包括描述性注释。
在 前面介绍的示例 中,TABLES 子句定义了以下三个逻辑表:
一个
orders表,包含来自 TPC-Horders表的订单信息。一个
customers表,包含来自 TPC-Hcustomers表的客户信息。A
line_itemstable containing the line items in orders from the TPC-Hlineitemtable.
The example uses the PRIMARY KEY clause to identify the columns to be used as primary keys for each logical table. Primary keys and unique values help determine the types of relationships between the tables (for example, many-to-one or one-to-one).
该示例还提供了用于描述逻辑表的同义词和注释,使数据更易于发现。
识别逻辑表之间的关系¶
In the CREATE SEMANTIC VIEW command, use the RELATIONSHIPS clause to identify the relationships between the tables in the view. For each relationship, you specify:
关系的可选名称。
包含外键的逻辑表的名称。
表中用于定义外键的列。
包含主键或具有唯一值的列的逻辑表的名称。
表中定义主键或包含唯一值的列。
如果您已经在 TABLES 子句中为逻辑表指定 PRIMARY KEY,则无需在关系中指定主键列。
如果 TABLES 子句中逻辑表只有一个 UNIQUE 关键字,则无需在关系中指定相应的列。
You can also specify a date, time, timestamp, or numeric column, if you want to join the columns on a range.
在 前面介绍的示例 中,RELATIONSHIPS 子句指定了以下两种关系:
orders和customers表之间的关系。在orders表中,o_custkey是一个外键,指向customers表中的主键c_custkey。line_items和orders表之间的关系。在line_items表中,l_orderkey是一个外键,指向orders表中的主键o_orderkey。
Using a date, time, timestamp, or numeric range to join logical tables¶
By default, when you specify a relationship between two logical tables, the tables are joined on an equality condition.
If you need to join two logical tables on a date, time, timestamp, or numeric range (where the values in a column of one table need to be in the same range as the values in a column of another table), you can specify the ASOF keyword with the column name in the REFERENCES clause:
A query of the semantic view defined above produces an ASOF JOIN that uses the
>= comparison operator in the MATCH_CONDITION clause. This joins the two tables so that the values in col_table_1 are
greater than or equal to the values in col_table_2:
备注
No other comparison operator in MATCH_CONDITION clause is supported.
You can use the ASOF keyword for columns of the same types that you can use with ASOF JOIN.
备注
You can specify at most one ASOF keyword in the definition of a given relationship. You can specify this keyword before any column in the list.
For example, suppose that you have tables containing customer, customer address, and order data:
In this example, the customer_address table has a ca_start_date column, which indicates when the customer started residing
at the specified address. The orders table has a o_ord_date column, which is the date of the order.
Suppose that you want to be able to query information about customer orders and retrieve the zip codes corresponding to where the customer resided when the orders were placed.
You can define a semantic view that specifies an ASOF join between the ca_start_date and o_ord_date columns:
Suppose that you query this semantic view to return the sum of the order amounts per month for each zip code:
The query effectively uses an ASOF JOIN to join the tables on the date columns, where the order date is greater than or equal to the address starting date:
Joining logical tables that contain ranges of values¶
You can use a range join when you want to join a table with another table that defines a range of possible values in the first table. For example, suppose that one table represents sales orders and has a column with the timestamp when the order was placed. Suppose that another table represents fiscal quarters and contains the distinct ranges of time that represent these quarters. You can create a semantic view that joins the two tables so that the row for an order includes the fiscal quarter in which the order was placed.
In the table that contains the ranges, each range must be distinct. No two ranges can overlap.
In the table data, if you want to specify the lowest possible value for the range or the highest possible value for the range, use NULL.
For example, the following table defines a set of ranges of times that do not overlap:
The first row covers the range that includes everything up to (but not including) January 1, 2024.
The last row covers the range that includes everything from March 20, 2024, onwards.
备注
No two rows can contain NULL in the start column, and no two rows can contain NULL in the end column.
For cases like these, you can set up a semantic view that supports range-join queries. When you create the semantic view, you must do the following:
For the logical table containing the start and end times of a time period, define a constraint that specifies that no two ranges can overlap.
In the TABLE clause of the CREATE SEMANTIC VIEW command, specify the CONSTRAINT clause in the logical table definition. For the syntax, see the documentation for CONSTRAINT in the CREATE SEMANTIC VIEW topic.
Define a relationship between the column containing the timestamp in one table and the start and end time columns in the other table.
In the RELATIONSHIPS clause of the CREATE SEMANTIC VIEW command, use the BETWEEN clause to specify the columns containing the start and end times. For the syntax, see the documentation for RELATIONSHIP in the CREATE SEMANTIC VIEW topic.
For example, suppose that the my_time_periods table defines distinct periods of time:
Suppose that the my_events table captures events that occurred within those periods of time:
You can define a semantic view that joins the tables. Rows in my_events are joined with rows in my_time_periods,
where the value in the event_timestamp column in my_events is within the range specified by the start_time and
end_time columns in my_time_periods.
The following query demonstrates how the rows are joined:
As shown in the examples, the dim_time_period_name dimension for each row in the results is the name of the time period that
the dim_event_timestamp dimension falls into.
定义事实、维度和指标¶
在 CREATE SEMANTIC VIEW 命令中,使用 FACTS、DIMENSIONS 和 METRICS 子句定义语义视图中的事实、维度和指标。
您必须在语义视图中定义至少一个维度或指标。
对于每个事实、维度或指标,您可以指定以下内容:
它所属的逻辑表。
备注
If you want to define a derived metric (a metric that is not specific to one logical table), you must omit the logical table name. See Defining derived metrics.
事实、维度或指标的名称。
用于计算它的 SQL 表达式。
备注
For dimensions, you can specify a Cortex Search Service to use for the dimension. For information, see Defining a dimension that uses a Cortex Search Service.
可选的同义词和注释。
备注
If a metric should not be aggregated across specific dimensions, you should specify that those dimensions should be non-additive.
For information, see Identifying the dimensions that should be non-additive for a metric.
前面介绍的示例 定义了以下多个事实、维度和指标:
备注
有关定义使用窗口函数的指标的其他指南,请参阅 定义和查询窗口函数指标。
Defining a dimension that uses a Cortex Search Service¶
To define a dimension that uses a Cortex Search Service, set the WITH CORTEX SEARCH SERVICE clause to the name of the Cortex Search Service. If the service is in a different database or schema, qualify the name of the service. For example:
Defining derived metrics¶
When you define a metric, you specify the name of the logical table that the metric belongs to. This is the logical table on which the metric is aggregated.
If you want to define a metric based on metrics from different logical tables, you can define a derived metric. A derived metric is a metric that is scoped to the semantic view (rather than to a specific logical table). A derived metric can combine metrics from multiple logical tables.
In the definition of a derived metric, omit the logical table name.
For example, suppose that you want to define a metric my_derived_metric_1 that is the sum of the metrics table_1.metric_1
and table_2.metric_2. When you define my_derived_metric_1, don't qualify the name with any logical table name:
You can use other derived metrics in the expression. For example:
Note the following restrictions when you define a derived metric:
You cannot use the same name for a derived metric and a regular metric.
The expression for a derived metric can use:
Aggregations of dimensions and facts defined in any logical table in the semantic view.
Scalar expressions of metrics defined in any logical table in the semantic view.
Other derived metrics.
In the following example:
derived_metric_1uses a scalar expression with two metrics.derived_metric_2uses an aggregation of a dimension.derived_metric_3adds an aggregation of a dimension to another derived metric.
You don't need to qualify the name of a metric, dimension, or fact in the expression if the name is not ambiguous. For example:
Note that
metric_1needs to be qualified bytable_1because there are two metrics namedmetric_1, butmy_unique_metric_namedoes not need to be qualified because the name is unique.In the expression for a derived metric, you cannot use the following:
Aggregations of metrics.
Window functions.
References to physical columns.
References to facts or dimensions that are not aggregated.
You cannot use a derived metric in the expression for a regular metric, dimension, or fact. Only another derived metric can use a derived metric in its expression.
Specifying the relationship for a metric when multiple relationship paths exist¶
In some cases, you multiple relationship paths might exist between two specific logical tables in a semantic view. In these cases, when you define a metric, you must specify the relationship path to use.
The problem with multiple relationship paths¶
Suppose that you have two tables that contain information about flights and airports:
Suppose that you define a semantic view that provides information about the total number of flights departing from and arriving to a specific city:
The semantic view specifies two different relationships between the flights table and the airports table
(flight_departure_airport and flight_arrival_airport). Because there are multiple relationship paths between the tables,
querying for the m_flight_count metric and selecting the airports.city_name dimension (or any dimension in the
airports table) fails:
Because there are multiple paths between the flights and airports tables, the query fails. If the query did not select a
dimension from the airports table, the query would have succeeded.
Specifying the relationship to use¶
In the metric definition in the CREATE SEMANTIC VIEW command, you can specify which relationship to use in the USING clause:
备注
Each relationship that you specify must start from the logical table containing the metric. For example, suppose that you want to specify:
The relationship
table_a_to_table_bmust start fromtable_a:You cannot specify a sequence of relationships (for example,
table_a_to_table_bandtable_b_to_table_c). Each relationship must start from the logical table containing the metric.If you need to identify the relationships from the logical table containing the metric to different tables, you can specify the relationships in the USING clause. For example, suppose that you want the metric to be computed by specific relationships from
table_atotable_band fromtable_atotable_c. In this case, you specify both relationships in the USING clause:You cannot specify the USING clause in a derived metric.
For example, the following statement defines two additional metrics that use specific relationships:
m_flight_departure_count, which uses theflight_departure_airportrelationship.m_flight_arrival_count, which uses theflight_arrival_airportrelationship.
When querying this view, you can specify the two new metrics that use specific relationships:
Add dimensions that rely on the same relationships¶
The query in the previous example used the airports.city_name dimension, which is in the airports logical table that the
relationships are based on.
If you add a dimension for a different logical table to the view, queries of that dimension benefit from the relationships that you specified earlier.
For example, suppose that you create a table named regions with additional information about the airport regions specified in
the airport_region_code column of the airports table:
You can extend the semantic view that you defined earlier to return the region name:
Add a new logical table for the
regionstable.Add a relationship between the
regionsandairportstables.Add a dimension for the region name.
You don't need to make any additional changes to the USING clause for the metrics because there's a single relationship between
the regions and airports tables.
If you query the view, specifying the region_name dimension, and there is ambiguity about which relationship to use, the USING
clause determines the relationships to use:
Specify relationships to different tables¶
If the semantic view uses dimensions from multiple tables, and you need to specify the relationships to use for these dimensions, you can specify multiple relationships in the USING clause.
For example, suppose that you create a table named weather with weather information about the airports in the airports
table:
You can extend the semantic view that you defined earlier to return the weather condition:
Add a new logical table for the
weathertable.Add two relationships between the
weatherandflightstables (one for departing flights and one for arrriving flights).Add a dimension for the weather information.
Specify that the metrics should also use the two new relationships between the
weatherandflightstables.
When you query the view and specify the weather_condition dimension, the USING clause determines the relationships that are
used:
Define derived metrics based on metrics that use specific relationships¶
Although you cannot specify the USING clause in a derived metric, you can define a derived metric that uses metrics that specify the USING clause.
For example, the following semantic view defines two derived metrics:
global_m_departure_arrival_ratioglobal_m_departure_arrival_sum
The definitions of these derived metrics use the flights.m_flight_departure_count and flights.m_flight_arrival_count
metrics, which both specify the USING clause:
Identifying the dimensions that should be non-additive for a metric¶
In some cases, a metric should not be aggregated across specific dimensions. In these cases, you can mark the dimensions as non-additive.
Understanding the problem with aggregating metrics across some dimensions¶
Suppose you have a table that contains the account balances of each customer's checking and savings accounts on a specific day.
Suppose that you want to define a semantic view that includes:
The following dimensions:
Customer ID
Account type
Year
Month
Day
A metric for the sum of the balance.
The following statement creates a semantic view that includes the dimensions and metrics listed above:
If you want to retrieve the total balance of the checking and savings accounts for each customer at the end of each year, you can
query the semantic view for the m_account_balance metric and specify the customer_id_dim and year_dim dimensions.
However, the m_account_balance metric will be the sum of the balances of each day for each customer because the metric is
aggregated by the date dimensions.
In the example above, for cust-001 in 2024, 910 is the sum of the balances for each day
(100 + 110 + 140 + 150 + 200 + 210).
Preventing a metric from being aggregated across specific dimensions¶
To prevent the metric from being aggregated by the date dimensions, specify the date dimensions in the NON ADDITIVE BY clause when creating the semantic view:
备注
If you specify the NON ADDITIVE BY clause in a metric, you cannot refer to that metric in the definitions of metrics that are not derived. Only derived metrics can refer to metrics that specify non-additive dimensions.
Specifying the NON ADDITIVE BY clause makes the metric a semi-additive metric.
When you query this semantic view, the m_account_balance metric is no longer aggregated by the date dimensions. The query
aggregates the account balances at the end of the period in each group of queried dimensions.
In the example above, for cust-001 in 2024, 210 is the sum of the checking and savings account balances for the last day
of the year that contains data:
The last day of 2024 that contains data is
2024-03-30.There is no row with that date for the checking account, so the resulting metric is the balance of the savings account (
210).
As another example, if you just want the total account balance for all customers at the end of the year, you can specify the
year_dim dimension.
Because the date dimensions are marked as non-additive, the query sums the values at the end of the period (by date) for the checking and savings account balances for each customer.
During query processing, the rows are sorted by the non-additive dimensions, and the values from the last rows (the latest snapshots of values) are aggregated to compute the metric.
备注
Because the rows are sorted by the non-additive dimensions, the order in which you specify the dimensions is important. This is similar to the order in which you specify columns in the ORDER BY clause.
Specifying the sort order for non-additive dimensions¶
As demonstrated in the example, the metric aggregates the values of the checking and savings balances for each customer at the end of a period. If you want to change the sort order, you can specify the ASC or DESC keyword next to the dimension name. For example:
In this example, the metric evaluates to the earliest date specified by year_dim, month_dim, and day_dim.
If the dimension includes NULL values, you can use the NULLS FIRST or NULLS LAST keywords to specify whether NULL values are sorted first or last in the results:
Marking a fact or metric as private¶
If you are defining a fact or metric only for use in calculations in the semantic view and you don't want the fact or metric to be returned in a query, you can specify the PRIVATE keyword to mark the fact or metric as private. For example:
备注
You cannot mark a dimension as private. Dimensions are always public.
When you query a semantic view that has private facts or metrics, you cannot specify a private fact or metric in the following clauses:
The SELECT list
执行 CREATE SEMANTIC VIEW 命令。
执行 CREATE SEMANTIC VIEW 命令。
METRICS
执行 CREATE SEMANTIC VIEW 命令。
Some commands and functions include private facts and metrics:
Private facts and metrics do appear in the output of the DESCRIBE SEMANTIC VIEW command. The rows for private facts and metrics have
PRIVATEin theaccess_modifiercolumn.Private facts and metrics are listed in the return value of a GET_DDL function call, as noted in 获取语义视图的 SQL 语句.
Some commands and functions include private facts and metrics only under specific conditions:
Private facts and metrics are listed in the INFORMATION_SCHEMA SEMANTIC_FACTS and SEMANTIC_METRICS views only if you are using a role that has been granted the REFERENCES or OWNERSHIP privilege on the semantic view.
Otherwise, these views list only the public facts and metrics.
Other commands and functions do not include private facts and metrics:
以上任一权限也用于让该视图出现在 SHOW SEMANTIC VIEWS 命令的输出结果中。
以上任一权限也用于让该视图出现在 SHOW SEMANTIC VIEWS 命令的输出结果中。
Providing custom instructions for Cortex Analyst¶
In a semantic view, you can provide instructions for Cortex Analyst that explain how to:
Generate the SQL statement
Classify questions and prompt for additional information
To provide these custom instructions, use the following clauses:
For instructions on how to generate the SQL statement, use the AI_SQL_GENERATION clause in the CREATE SEMANTIC VIEW command.
For example, to tell Cortex Analyst to generate the SQL statement so that all numeric columns are rounded to two decimal points, specify the following:
For instructions on how to classify questions, use the AI_QUESTION_CATEGORIZATION clause.
For example, to tell Cortex Analyst to reject questions about users, specify the following:
You can also provide instructions to ask for more details, if the question isn't clear. For example:
根据 YAML 规范创建语义视图¶
To create a semantic view from a YAML specification, you can call the SYSTEM$CREATE_SEMANTIC_VIEW_FROM_YAML stored procedure.
首先,将 TRUE 作为第三个实参传递,以验证您是否可以根据 YAML 规范创建语义视图。
以下示例验证了您是否可以在 YAML 中使用给定的语义模型规范,在数据库 my_db 和架构 tpch_analysis 中创建名为 my_schema 的语义视图:
如果规范有效,则存储过程返回以下消息:
如果 YAML 语法无效,则存储过程会引发异常。例如,如果缺少冒号:
存储过程会抛出异常,表示 YAML 语法无效:
如果规范引用的物理表不存在,则存储过程会引发异常:
同样,如果规范引用的主键列不存在,则存储过程会引发异常:
然后,无需传入第三个实参即可调用存储过程来创建语义视图。
以下示例在数据库 my_db 和架构 tpch_analysis 中创建了一个名为 my_schema 的语义视图:
替换现有的语义视图¶
要查看语义视图的详细信息,请执行 DESCRIBE SEMANTIC VIEW 命令。例如:
备注
You can't use the ALTER SEMANTIC VIEW command to change properties other than the comment. To change other properties of the semantic view, replace the semantic view. See 替换现有的语义视图.
以下示例使用 CREATE SEMANTIC VIEW 命令创建语义视图。
替换现有的语义视图¶
要替换现有的语义视图(例如更改视图的定义),请在执行 CREATE SEMANTIC VIEW 时指定 OR REPLACE。如果要保留对现有语义视图授予的任何权限,请指定 COPY GRANTS。例如:
列出语义视图¶
要列出当前架构或指定架构中的语义视图,请执行 SHOW SEMANTIC VIEWS 命令。例如:
The output of the SHOW OBJECTS command includes semantic views. In the kind column, the type of
object is listed as VIEW. For example:
您还可以通过 查询 ACCOUNT_USAGE 和 INFORMATION_SCHEMA 架构中的视图来获取语义视图的信息。
列出维度和指标¶
要列出视图、架构、数据库或账户中可用的维度和指标,您可以运行 SHOW SEMANTIC DIMENSIONS 和 SHOW SEMANTIC METRICS 命令。
默认情况下,这些命令会列出在当前架构中定义的语义视图中可用的维度和指标:
The following examples demonstrate how to list the dimensions, facts, and metrics for semantic views within different scopes:
List the dimensions, facts, and metrics in semantic views in the current database:
List the dimensions, facts, and metrics in semantic views in a specific schema or database:
List the dimensions, facts, and metrics in semantic views in the account:
List the dimensions, facts, and metrics in a specific semantic view:
如果您要查询语义视图,可以使用 SHOW SEMANTIC DIMENSIONS FOR METRIC 命令来确定在指定给定指标时可以返回哪些维度。有关详细信息,请参阅 为给定指标选择可以返回的维度。
When you run the SHOW COLUMNS command for a semantic view, the output includes the dimensions, facts,
and metrics in the semantic view. The kind column indicates if the row represents a dimension, fact, or metric.
For example:
查看有关语义视图的详细信息¶
要查看语义视图的详细信息,请执行 DESCRIBE SEMANTIC VIEW 命令。例如:
获取语义视图的 SQL 语句¶
您可以调用 GET_DDL 函数来检索用于创建语义视图的 DDL 语句。
备注
To call this function for a semantic view, you must use a role that has been granted the REFERENCES or OWNERSHIP privilege on the semantic view.
调用 GET_DDL 时,将 'SEMANTIC_VIEW' 作为对象类型传入。例如:
The return value includes private facts and metrics (facts and metrics that are marked with the PRIVATE keyword).
获取语义视图的 YAML 规范¶
To get the YAML specification for a semantic view, call the SYSTEM$READ_YAML_FROM_SEMANTIC_VIEW function.
以下示例返回数据库 my_db 和架构 my_schema 中名为 tpch_analysis 的语义视图的 YAML 规范:
Exporting a semantic view to a Tableau Data Source (TDS) file¶
To export a semantic view to a Tableau Data Source (TDS) file (https://help.tableau.com/current/pro/desktop/en-us/export_connection.htm#options-for-saving-a-local-data-source), call the SYSTEM$EXPORT_TDS_FROM_SEMANTIC_VIEW function.
The following example returns the TDS file content for the semantic view my_sv_for_export:
Copy the XML to a .tds file and open the file in Tableau Desktop.
Tableau Desktop displays a folder for each logical table in the list of folders on the left. The names of the folders use spaces
instead of underscores, and each word starts with an uppercase letter. For example, the folder name for the date_dim logical
table is Date Dim.
Each folder contains Tableau dimensions and measures that correspond to the dimensions, facts, and metrics in the semantic view.
The next sections provide more detail and the limitations of the conversion process:
About the conversion¶
The function converts dimensions, facts, and metrics in the semantic view to the following equivalents in the Tableau TDS file:
Element in the semantic view |
Tableau equivalent (dimension or measure) |
How the data is aggregated |
|---|---|---|
Dimension |
|
|
Numeric fact |
Measure |
SUM |
Non-numeric fact |
Dimension |
|
Numeric metric |
Measure |
The TDS file uses a calculated field in place of the metric. The calculated field passes the value of the metric to the Snowflake AGG function. |
Non-numeric metric |
Dimension |
|
Numeric derived metric |
Measure |
The TDS file uses a calculated field in place of the metric. The calculated field passes the value of the metric to the Snowflake AGG function. |
Non-numeric derived metric |
Dimension |
|
The following Snowflake data types are mapped to corresponding Tableau TDS data types:
Snowflake data type |
Equivalent Tableau data type |
|---|---|
NUMBER/FIXED (if the scale is greater than 0) |
real |
NUMBER/FIXED (if the scale is 0 or null) |
integer |
FLOAT or DECFLOAT |
real |
STRING or BINARY |
string |
BOOLEAN |
boolean |
TIME |
time |
DATE |
date |
DATETIME or TIMESTAMP |
datetime |
GEOGRAPHY |
spatial |
Semi-structured (VARIANT, OBJECT, ARRAY), structured (ARRAY, OBJECT, MAP), unstructured (FILE), GEOMETRY, UUID, VECTOR |
string |
The TDS file has the following capabilities (https://help.tableau.com/current/pro/desktop/en-us/odbc_capabilities.htm) customized for the connection to Snowflake:
Customization name |
Value |
Effect of the customization |
|---|---|---|
|
|
Prevents Tableau from actually running a query like |
|
|
Prevents Tableau from "preparing" a statement (sending it to Snowflake to be parsed without executing) to learn about types. |
|
|
Prevents Tableau from using a |
|
|
Forces Tableau to enable and use the standard ODBC |
|
|
Prevents Tableau from escaping underscores when searching for the database name. |
Limitations when using a semantic view in Tableau Desktop¶
The following limitations apply to semantic views in Tableau Desktop:
You cannot create an extract from a semantic view.
If you change your connection from Live to Extract, Tableau Desktop fails with the following error:
You cannot use the Measure Values field in a semantic view.
If you select the Measure Values field in a semantic view, Tableau Desktop reports the following error:
You cannot select the Count field in a semantic view.
If you select SemanticViewName(Count), Tableau Desktop reports the following error:
Tableau Desktop cannot report the number of rows in the semantic view because the number of rows can vary, depending on the dimensions, facts, and metrics that are specified in the query.
You cannot drag a measure by itself.
If you drag a measure, Tableau Desktop reports the following error:
You cannot directly use a non-numeric metric.
SYSTEM$EXPORT_TDS_FROM_SEMANTIC_VIEW converts non-numeric metrics to dimensions in Tableau. If you attempt to use one of these dimensions, Tableau Desktop reports the following error:
To work around this, convert the dimension to a measure:
Right-click on the dimension, and select Convert to Measure.
This converts the dimension to a measure, using the default aggregation Count (Distinct).
To use a different aggregation, right-click on the converted measure, select Default Properties » Aggregations, and select the aggregation that you want to use.
移除语义视图¶
要移除语义视图,请执行 DROP SEMANTIC VIEW 命令。例如:
移除语义视图¶
要移除语义视图,请执行 DROP SEMANTIC VIEW 命令。例如:
授予语义视图的权限¶
语义视图权限 列出了您可以授予的语义视图权限。
需要语义视图的以下权限才能使用该视图:
Any privilege (for example, MONITOR, REFERENCES, or SELECT) on a view is required to run the DESCRIBE SEMANTIC VIEW command on that view.
Any privilege on a view is required to display that view in the output of the SHOW SEMANTIC VIEWS command.
SELECT is required to query the semantic view.
要在 Cortex Analyst 中使用并非自己拥有的语义视图,您必须使用一个拥有该视图的 REFERENCES 和 SELECT 权限的角色。
要授予语义视图的 REFERENCES 和 SELECT 权限,请使用 GRANT <privileges> ... TO ROLE 命令。例如,若要将名为 my_semantic_view 的语义视图的 REFERENCES 和 SELECT 权限授予角色 my_analyst_role,可以执行以下语句:
如果您有一个包含语义视图的架构,并希望将其共享给 Cortex Analyst 用户,则您可以使用 未来授权 授予该架构中今后创建的所有语义视图的权限。例如: