from(Explore の場合)

このページでは、Explore の一部である from パラメータについて説明します。

from は、from(結合の場合)パラメータのドキュメント ページで説明されているように、結合の一部としても使用できます。

用途


explore: explore_name {
  from: view_name
}
階層
from
デフォルト値
名前が Explore の名前と一致するビュー

許可
既存のビューの名前

定義

from は、Explore のフィールドを定義するビューを決定します。from を省略すると、Looker は基盤となるビュー名が Explore 名と同じであると想定します。通常、from は、Explore とそのフィールドに基盤となるビューとは異なる名前を付けたい場合にのみ使用します。

これを明確にするため、underlying_view というビューに order_value というディメンションが作成されている例を考えてみましょう。

  • このフィールドは通常、Explore UI で [UNDERLYING VIEW Order Value] として表示され、LookML で ${underlying_view.order_value} を使用して参照されます。
  • 上記の使用例では、フィールドは NEW ALIAS NAME Order Value として表示され、${new_alias_name.order_value} として参照されます。

user というビューに基づいて、[Explore] メニューに [Customer] というオプションを追加します。

explore: customer {
  from: user
}

一般的な課題

fromview_namelabel は混同されがちですが、動作は異なります

上記の例でわかるように、from は、Explore のラベル付けの方法やフィールドの参照方法に大きな影響を与えます。同様の効果がある view_name パラメータと label パラメータもあります。

from の使用

このオプションは、同じビューから複数の Explore を作成し、各 Explore でフィールドを異なる方法で参照する場合に使用します。

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 を作成し、各 Explore で同じ方法でフィールドを参照する場合に使用します。

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 を作成する必要はないが、Explore の名前を [Explore] メニューに異なる名前で表示したい場合に選択します。

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}

知っておくべきこと

fromexplore と併用されることはほとんどありません

from を使用して Explore の名前を変更することはあまり一般的ではありません。正当なユースケースもありますが、このパラメータを使用したい場合は、代わりに基盤となるビューの名前を変更するだけで済むかどうかを検討してください。結合の名前を変更するには、結合レベルの from パラメータを使用するのが一般的です。