用量
探索:探索名称 {
查看名称: 查看名称
}
查看名称: 查看名称
}
层次结构
view_name |
默认值
名称与“探索”名称匹配的视图接受
现有视图的名称 |
定义
view_name
决定将定义“探索”各个字段的视图。如果省略 view_name
,Looker 会假设基础视图名称与探索名称相同。通常,view_name
仅用于从同一视图中创建多个探索。
示例
根据名为 user
的视图,在“探索”菜单中添加一个名为客户的选项:
explore: customer {
view_name: user
}
常见挑战
view_name
、from
和 label
通常容易混淆,但具有不同的行为
view_name
、from
和 label
参数具有类似但不同的效果。
使用 view_name
使用 view_name
从同一数据视图创建多个探索,并采用相同的方式为每个探索引用字段:
explore: customer {
view_name: user
}
# Would appear in the Explore menu as 'Customer'
# Fields would appear like 'User Name'
# You would reference fields like ${user.name}
explore: buyer {
view_name: user
}
# Would appear in the Explore menu as 'Buyer'
# Fields would appear like 'User Name'
# You would reference fields like ${user.name}
使用 view_name: user
时,生成的 SQL 会使用原始表名称,如下所示:FROM schema.users AS users
。
使用 from
使用 from
可从同一数据视图创建多个探索,并为每个探索引用不同的字段:
explore: customer {
from: user
}
# Would appear in the Explore menu as 'Customer'
# Fields would appear like 'Customer Name'
# You would reference fields like ${customer.name}
explore: buyer {
from: user
}
# Would appear in the Explore menu as 'Buyer'
# Fields would appear like 'Buyer Name'
# You would reference fields like ${buyer.name}
使用 from: user
时,生成的 SQL 将别名为原始表名称,如下所示:FROM schema.users AS customer
。
使用 label
如果您不需要从同一个数据视图中创建多个探索,并且希望该探索的名称在“探索”菜单中的显示方式有所不同,请使用 label
:
explore: user {
label: "Customer"
}
# Would appear in the Explore menu as 'Customer'
# Fields would appear like 'User Name'
# You would reference fields like ${user.name}
注意事项
view_name
很少用于重命名探索
很少使用 view_name
重命名探索,除非您要创建扩展模型,并且需要从同一个视图中创建多个探索。
不妨考虑重命名底层视图,或使用 label
更改“探索”功能在字段选择器中的显示方式。