用法
explore: explore_name {
symmetric_aggregates: yes
}
|
层次结构
symmetric_aggregates |
默认值
yes
接受
布尔值(yes 或 no)
|
定义
symmetric_aggregates 参数决定了是否在给定探索中应用对称聚合。当 symmetric_aggregates 处于开启状态时,即使联接导致扇出,聚合函数也会返回正确的结果。了解对称聚合最佳实践页面中更详细地介绍了对称聚合,SQL 扇出问题社区帖子中介绍了对称聚合解决的扇出问题。
默认情况下,Looker 中的每个探索都会启用对称聚合。这意味着,如果您的 SQL 方言支持对称聚合,则只有在您想为某个探索停用该功能时,才需要添加 symmetric_aggregates 参数。
示例
为 product 探索启用对称聚合:
explore: product {
symmetric_aggregates: yes # the default value, could be excluded
}
为“customer”探索关闭对称聚合:
explore: customer {
symmetric_aggregates: no
}
注意事项
在对称聚合处于关闭状态时,请谨慎创建联接
当联接导致扇出时,对称聚合可防止某些计算给出不正确的结果。因此,如果您的方言不支持对称聚合,或者您选择关闭对称聚合,则在 Looker 中执行联接时需要小心。社区帖子 SQL 扇出问题中详细介绍了此问题及其解决方法。
并非所有数据库方言都支持具有对称聚合的中位数和百分位数测量类型
启用对称聚合后,如果联接涉及扇出,Looker 会自动将 percentile 和 median 测量类型转换为 percentile_distinct 和 median_distinct。并非所有支持对称聚合的数据库方言都支持 percentile_distinct 和 median_distinct 测量类型。您可以在测量类型文档页面上查看您的数据库方言是否支持这些测量类型。
如果您收到类似于 SQL dialect doesn't support Symmetric Aggregates with percentiles, field ignored. 的错误,则表示您的数据库方言不支持 percentile_distinct 和 median_distinct 测量类型。如需解决此问题,请将测量类型更改为 type: number,然后使用 sql: median(${dimension}) 指定聚合函数。不过,这会停用对称聚合。
对称聚合和 Value Overflow 错误
尝试下载或查看信息中心时,您可能会遇到错误,例如 A LookML model issue occurred. Non-unique value/primary key (or sql_distinct_key), value overflow or collision when computing sum.
在聚合具有较大值的测量时,对称聚合的后台计算可能会导致小数溢出错误。当 Looker 尝试对超过 14 位数(大于 10,000,000,000,000)的极大值执行左联接对称聚合(例如 type: sum)时,会导致十进制溢出错误。
如需解决此问题,您可以使用 precision 参数,并将其设置为 5 或更低。例如:
measure: average_value {
type: average
precision: 5
sql: ${value} ;;
}
对称聚合的方言支持
能否使用对称聚合取决于 Looker 连接使用的数据库方言。在最新版本的 Looker 中,以下方言支持汇总感知:
| 方言 | 是否支持? |
|---|---|
| Actian Avalanche | |
| Amazon Athena | |
| Amazon Aurora MySQL | |
| Amazon Redshift | |
| Amazon Redshift 2.1+ | |
| Amazon Redshift Serverless 2.1+ | |
| Apache Druid | |
| Apache Druid 0.13.x - 0.17.x | |
| Apache Druid 0.18+ | |
| Apache Hive 2.3+ | |
| Apache Hive 3.1.2+ | |
| Apache Spark 3+ | |
| ClickHouse | |
| ClickHouse 26+ | |
| Cloudera Impala 3.1+ | |
| Cloudera Impala 3.1+ with Native Driver | |
| Cloudera Impala with Native Driver | |
| DataVirtuality | |
| Databricks | |
| Denodo 7 | |
| Denodo 8 & 9 | |
| Dremio | |
| Dremio 11+ | |
| Dremio 26+ with Arrow Flight SQL | |
| Exasol | |
| Google BigQuery Legacy SQL | |
| Google BigQuery Standard SQL | |
| Google Cloud AlloyDB for PostgreSQL | |
| Google Cloud PostgreSQL | |
| Google Cloud SQL | |
| Google Spanner | |
| Greenplum | |
| HyperSQL | |
| IBM Netezza | |
| MariaDB | |
| Microsoft Azure PostgreSQL | |
| Microsoft Azure SQL Database | |
| Microsoft Azure Synapse Analytics | |
| Microsoft SQL Server 2008+ | |
| Microsoft SQL Server 2012+ | |
| Microsoft SQL Server 2016 | |
| Microsoft SQL Server 2017+ | |
| MongoBI | |
| MongoSQL | |
| MySQL | |
| MySQL 8.0.12+ | |
| Oracle | |
| Oracle ADWC | |
| PostgreSQL 9.5+ | |
| PostgreSQL pre-9.5 | |
| PrestoDB | |
| PrestoSQL | |
| SAP HANA | |
| SAP HANA 2+ | |
| SingleStore | |
| SingleStore 7+ | |
| Snowflake | |
| Teradata | |
| Trino | |
| Vector | |
| Vertica |