本頁面是指 探索中的
from參數。
from也可做為聯結的一部分,詳情請參閱from(適用於聯結) 參數說明文件頁面。
用量
explore: explore_name {
from: view_name
}
|
階層
from |
預設值
名稱與探索名稱相符的檢視區塊
接受
現有檢視畫面的名稱
|
定義
from 會決定要定義探索欄位的檢視畫面。如果省略 from,Looker 會假設基礎檢視區塊名稱與「探索」名稱相同。通常只有在您希望「探索」及其欄位的名稱與基礎檢視區塊不同時,才會使用 from。
為清楚說明,請參考以下範例:在名為 underlying_view 的檢視區塊中,建立名為 order_value 的維度:
- 這個欄位通常會以「基礎檢視區塊訂單價值」的形式顯示在「探索」使用者介面中,並以
${underlying_view.order_value}參照 LookML。 - 在上述使用範例中,欄位會改為顯示「NEW ALIAS NAME Order Value」(新別名訂單價值),並參照為
${new_alias_name.order_value}。
範例
根據名為 user 的檢視畫面,在「探索」選單中新增名為「客戶」的選項:
explore: customer {
from: user
}
常見挑戰
from、view_name 和 label 經常會混淆,但行為不同
如先前的範例所示,from 對於 Explore 的標籤方式和欄位的參照方式有許多影響。此外,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 參數重新命名聯結,是更常見的做法。