起(适用于探索)

此页面涉及 探索的一部分 from 参数。

from 还可以用作联接的一部分,如 from(用于联接)参数文档页面中所述。

用法


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

接受
现有视图的名称

定义

from 用于确定将定义探索中字段的视图。如果省略 from,Looker 会假定底层视图名称与探索名称相同。通常,只有当您希望探索及其字段的名称与底层视图的名称不同时,才使用 from

为了更清楚地说明这一点,不妨考虑一个示例,其中在名为 underlying_view 的视图中创建了一个名为 order_value 的维度:

  • 此字段通常在“探索”界面中显示为基础视图“订单价值”,并在 LookML 中通过 ${underlying_view.order_value} 引用。
  • 在给定的使用示例中,该字段将显示为 NEW ALIAS NAME Order Value,并引用为 ${new_alias_name.order_value}

示例

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

explore: customer {
  from: user
}

常见挑战

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

如上例所示,from 对探索的标签方式和字段的引用方式有许多影响。此外,还有一个 view_name 参数和一个 label 参数,它们具有相似但不同的效果。

使用 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

使用 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

使用 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}

注意事项

from 很少与 explore 一起使用

使用 from 重命名探索的情况并不常见。虽然存在正当的用例,但如果您发现自己想要使用此参数,请考虑是否可以改为直接重命名底层视图。更常见的情况是使用联接级 from 参数重命名联接。