partition_keys

用量

view: view_name {
  derived_table: {
    partition_keys: [ "created_date" ]
    ...
  }
}
階層
partition_keys

- 或 -

partition_keys
預設值
None

接受
一或多個已分割資料欄名稱

特別規則
partition_keys 僅支援特定方言

定義

partition_keys 參數支援可分割資料欄的資料庫方言。如果查詢是根據分區資料欄篩選,資料庫只會掃描包含篩選資料的分區,而不是掃描整個資料表。由於掃描的資料表子區段較小,因此指定適當的分區和篩選條件後,查詢大型資料表的時間和費用可大幅減少。

partition_keys 參數只能搭配持續性資料表使用,例如 PDT 和匯總資料表。如果衍生資料表沒有持續性策略,則不支援「partition_keys」。

此外,使用 create_processsql_create 定義的衍生資料表不支援 partition_keys 參數。

建立永久衍生資料表 (PDT) 或匯總資料表時,如果基礎資料庫資料表使用分區,Looker 就能使用該分區。

如需支援 partition_keys 的方言清單,請參閱「支援 partition_keys 的方言」一節。

如要將分區資料欄新增至 PDT 或匯總資料表,請使用 partition_keys 並提供資料庫資料表中對應分區資料欄的名稱。

範例

在 BigQuery 資料庫中,以 date 欄的分割區鍵建立 customer_day_facts PDT:

view: customer_order_facts {
  derived_table: {
    explore_source: order {
      column: customer_id { field: order.customer_id }
      column: date { field: order.order_time }
      derived_column: num_orders {
        sql: COUNT(order.customer_id) ;;
      }
    }
    partition_keys: [ "date" ]
    datagroup_trigger: daily_datagroup
  }
}

在 Presto 資料庫中,於 datestate 資料欄上建立以 SQL 為基礎的衍生資料表,並使用分割區鍵:customer_day_facts

view: customer_day_facts {
  derived_table: {
    sql:
      SELECT
        customer_id,
        DATE(order_time) AS date,
        COUNT(*) AS num_orders
      FROM
        order
      GROUP BY
        customer_id ;;
    partition_keys: [ "date", "state" ]
    datagroup_trigger: daily_datagroup
  }
}

支援 partition_keys 的方言

使用 partition_keys 的能力取決於 Looker 連線使用的資料庫方言。在最新版 Looker 中,下列方言支援 partition_keys

在 BigQuery 中,分區只能用於一個資料表資料欄,且該資料欄必須是日期/時間資料欄,因此以 BigQuery 資料表為基礎的 Looker PDT 只能在一個日期/時間資料欄上使用分區。

方言 是否支援?
Actian Avalanche
Amazon Athena
Amazon Aurora MySQL
Amazon Redshift
Amazon Redshift 2.1+
Amazon Redshift Serverless 2.1+
Apache Druid
Apache Druid 0.13+
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 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
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