symmetric_aggregates

用量

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 扇出問題」這篇社群貼文。

並非所有資料庫方言都支援中位數和百分位數的對稱式匯總函式測量類型

啟用對稱式匯總函式後,當 join 涉及擴散傳遞時,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
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+
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