用法
view: view_name { derived_table: { partition_keys: [ "created_date" ] ... } }
|
层次结构
partition_keys- 或 - partition_keys |
默认值
None
接受
一个或多个分区列名称
特殊规则
partition_keys 仅在特定方言中受支持
|
定义
partition_keys 参数支持能够对列进行分区的数据库方言。当运行按分区列过滤的查询时,数据库将仅扫描包含过滤数据的分区,而不是扫描整个表。由于扫描的只是表中的一小部分,因此在指定适当的分区和过滤条件后,查询大型表所需的时间和费用会大幅减少。
partition_keys参数仅适用于永久性表,例如 PDT 和汇总表。对于没有持久性策略的派生表,不支持partition_keys。此外,对于使用
create_process或sql_create定义的派生表,不支持partition_keys参数。
创建持久性派生表 (PDT) 或汇总表时,如果底层数据库表使用分区,Looker 可以使用该分区。
如需查看支持
partition_keys的方言列表,请参阅partition_keys的方言支持部分。
如需向 PDT 或汇总表添加分区列,请使用 partition_keys 并提供数据库表中相应分区列的名称。
示例
在 BigQuery 数据库中创建一个 customer_day_facts PDT,并以 date 列作为分区键:
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 数据库上创建基于 customer_day_facts SQL 的派生表,并在 date 和 state 列上设置分区键:
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 |