关于 lookml-explore
这是一份 LookML Explore 配置参考技能,供构建和维护 Looker 查询入口的数据建模人员使用。内容涵盖命名、描述、关联、筛选、缓存、聚合表优化和 Explore 扩展。
主要功能
- 01规定 Explore 命名与必需参数
- 02说明关联关系和连接条件
- 03介绍可变与固定筛选配置
- 04涵盖聚合表与物化设置
- 05说明 Explore 继承与扩展
适用场景
- 01建立带关联的 Explore
- 02限制用户可查询的字段
- 03配置查询筛选与缓存
- 04用聚合表优化常见查询
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ looker-open-source/ looker-skills --skill lookml-explore安装后在 Claude Code 中输入/lookml-explore确认已加载。
附带文件references/advanced.mdreferences/joins.md
详细介绍
说明
1. 核心标准
- 命名约定:Explore 名称使用
snake_case。 - 必需参数:
description:覆盖率 100%。每个 Explore 都必须有描述。label:在 UI 中显示的、便于用户理解的 Explore 名称。view_name:默认与 Explore 名称相同,但显式定义更稳妥。
- 联接:
relationship:必需(one_to_one、many_to_one)。sql_on:必需。使用${left.id} = ${right.id}语法。type:默认为left_outer。如有需要,显式使用inner或full_outer。
- 格式:
- 不要仅为美观而使用
from重命名视图。请改用view_label。 - 例外:多态联接、自联接、重设作用域的扩展。
- 不要仅为美观而使用
2. 高级配置
always_filter:用户可以更改但无法移除的特定筛选条件。sql_always_where:用户无法更改的特定限制条件。persist_with:将 Explore 缓存关联到数据组(例如default_datagroup)。fields:必要时使用包含式列表严格控制内容(ALL_FIELDS*、-view.field)。
3. 性能优化(聚合表)
聚合表(聚合感知)让 Looker 能查询更小的预聚合表,而不是原始的细粒度数据,从而大幅提升查询性能。
聚合表的结构
explore: orders {
aggregate_table: rollup_name {
query: {
dimensions: [created_date, status]
measures: [total_revenue, count]
filters: [orders.created_date: "6 months"]
}
materialization: {
datagroup_trigger: ecommerce_etl
# partition_keys: ["created_date"] # BigQuery/Presto optimization
# increment_key: "created_date" # Incremental builds
# increment_offset: 3 # Rebuild last 3 periods
}
}
}
关键参数
-
查询:定义汇总数据的“形状”。
- 维度:包含仪表板中常用的所有维度(包括筛选条件)。
- 度量:包含基础度量(sum、count)。Looker 可以根据 sum 和 count 计算平均值。
- 筛选条件:可选。将汇总数据限制在数据子集内(例如“最近 6 个月”)。
-
物化:
- datagroup_trigger:(推荐)在 ETL 作业完成时重新构建。
- sql_trigger_value:在 SQL 查询返回新值时重新构建。
- increment_key:(高级)追加新数据,而非完整重建。最适用于超大型表。
- indexes / partition_keys / cluster_keys:特定方言的优化选项。
-
最佳实践:
- 时间粒度:包含所需的最细粒度(例如
date)。Looker 可以自动将date汇总到month或year。 - 精确匹配:要满足感知逻辑,用户的查询字段必须是聚合表字段的严格子集。
- 筛选感知:如果用户按聚合表中不存在的字段筛选,Looker 就无法使用该表(“精确匹配”这一特殊情况除外)。将常用筛选字段添加到
dimensions列表中。
- 时间粒度:包含所需的最细粒度(例如
4. 扩展 Explore
- 继承:使用
extends: [base_explore],从另一个 Explore 继承联接、字段和描述。- 使用场景:创建包含常用联接的“基础”Explore,然后创建用于特定分析的“扩展”Explore(例如,
orders->marketing_orders)。
- 使用场景:创建包含常用联接的“基础”Explore,然后创建用于特定分析的“扩展”Explore(例如,
示例
基本 Explore
explore: orders {
label: "Orders"
description: "Analyze order data, including user and product details."
view_name: orders
join: users {
relationship: many_to_one
sql_on: ${orders.user_id} = ${users.id} ;;
}
}
带筛选条件和缓存的 Explore
explore: events {
label: "Web Events"
description: "User interaction events."
persist_with: default_datagroup
# Users can change this filter, but it defaults to '7 days'
always_filter: {
filters: [events.created_date: "7 days"]
}
# Users CANNOT change this filter.
sql_always_where: ${events.is_test_data} = false ;;
join: sessions {
relationship: many_to_one
sql_on: ${events.session_id} = ${sessions.session_id} ;;
}
}
## Aggregate Table (Advanced)
```lookml
explore: orders {
aggregate_table: monthly_sales_summary {
query: {
dimensions: [created_month, status, products.category]
measures: [total_revenue, count]
filters: [orders.created_date: "2 years"]
}
materialization: {
datagroup_trigger: ecommerce_etl
partition_keys: ["created_month"]
increment_key: "created_month"
increment_offset: 1 # Rebuild current and previous month
}
}
}
扩展的 Explore
explore: orders_extended {
extends: [orders]
label: "Orders (Marketing View)"
view_name: orders
# Add new joins specific to this view
join: marketing_channels {
sql_on: ${orders.channel_id} = ${marketing_channels.id} ;;
relationship: many_to_one
}
}
## Reference Skills
For more complex scenarios, refer to these specialized skills:
- [Advanced Explore Configuration](references/advanced.md): UNNESTing, lateral flattens, and row-level security.
- [Joins Deep Dive](references/joins.md): Detailed join types, relationships, and aliasing.
评论
支持 Markdown