view_name

用法

explore: explore_name {
  view_name: view_name
}
层次结构
view_name
默认值
名称与探索名称匹配的视图

接受
现有视图的名称

定义

view_name 用于确定将定义探索中字段的视图。如果省略 view_name,Looker 会假定底层视图名称与探索名称相同。通常,view_name 仅用于从同一视图创建多个探索。

示例

在“探索”菜单中添加一个名为 Customer 的选项,该选项基于名为 users 的视图:

explore: customer {
  view_name: users
}

常见挑战

view_namefromlabel 经常被混淆,但行为不同

view_namefromlabel 参数具有相似但不同的效果。

使用 view_name

使用 view_name 从同一视图创建多个探索,并以相同的方式引用每个探索的字段:

explore: customer {
  view_name: users
}
# Would appear in the Explore menu as 'Customer'
# Fields would appear like 'User Name'
# You would reference fields like ${users.name}

explore: buyer {
  view_name: users
}
# Would appear in the Explore menu as 'Buyer'
# Fields would appear like 'Users Name'
# You would reference fields like ${users.name}

使用 view_name: users 时,生成的 SQL 会使用原始表名称,如下所示:FROM schema.users AS users

使用 from

使用 from 从同一视图创建多个探索,并为每个探索以不同的方式引用字段:

explore: customer {
  from: users
}
# Would appear in the Explore menu as 'Customer'
# Fields would appear like 'Customer Name'
# You would reference fields like ${customer.name}

explore: buyer {
  from: users
}
# Would appear in the Explore menu as 'Buyer'
# Fields would appear like 'Buyer Name'
# You would reference fields like ${buyer.name}

使用 from: users 时,生成的 SQL 会为原始表名称添加别名,如下所示:FROM schema.users AS customer

使用 label

如果您不需要从同一视图创建多个探索,并且希望探索的名称在“探索”菜单中以不同的方式显示,请使用 label

explore: users {
  label: "Customer"
}
# Would appear in the Explore menu as 'Customer'
# Fields would appear like 'Users Name'
# You would reference fields like ${users.name}

注意事项

view_name 很少用于重命名探索

除非您要创建扩展模型并需要从同一视图创建多个探索,否则很少使用 view_name 重命名探索。

请考虑重命名底层视图或使用 label 更改探索在字段选择器中的显示方式。