模型檔案會指定資料庫連線、定義使用該連線的一組探索,以及定義探索與其他檢視區塊的關係。與其他 LookML 元素不同,模型不會使用特定「model」參數宣告。而是由 LookML 開發人員建立副檔名為 .model.lkml 的 LookML 專案檔案,藉此定義模型。模型名稱取自檔案名稱。
模型名稱在執行個體的所有專案中不得重複。如果執行個體包含兩個同名的 .model.lkml 檔案,您可能會遇到錯誤,例如「LookML 專案」頁面上的模型設定錯誤,以及 LookML 資訊主頁的轉譯錯誤,因為 LookML 資訊主頁會在網址格式中使用模型名稱 (<hostname>/dashboard/model_name::<dashboard_name>
您可以使用 LookML 驗證器,確認執行個體中是否有重複的模型名稱。不過,即使 LookML 驗證工具在執行個體上偵測到重複的模型名稱,您仍可將程式碼推送至正式環境。因此,請務必先修正所有重複的模型名稱錯誤,再將 LookML 專案部署至正式環境。
模型檔案通常包含任何 explore 宣告,以及多項模型層級設定。
這個頁面會連結至模型層級的 LookML 參數。這類註解通常會寫在模型檔案頂端,且不應巢狀內嵌於其他參數中。
應用實例
將指標懸停在參數名稱上,即可查看簡短說明。按一下參數即可前往參照頁面。如果參數可設為多個特定選項之一,預設值會列在最前面。
## STRUCTURAL PARAMETERS
include:"filename_or_pattern"
## Possibly more include declarations
explore: explore_name {
# Desired explore parameters (described on Explore Parameters page)
}
## Possibly more explore declarations
access_grant: access_grant_name{
user_attribute: user_attribute_name
allowed_values: ["value_1", "value_2", ...]
}
## Possibly more access_grant declarations
test: test_name{
explore_source: explore_name {
# Desired subparameters (described on test page)
}
assert: assert_statement {
expression:Looker expression ;;
}
# Possibly more assert declarations
}
## Possibly more test declarations
## DISPLAY PARAMETERS
label: "desired label"
## FILTER PARAMETERS
case_sensitive: yes | no
## QUERY PARAMETERS
connection: "connection_name"
datagroup: datagroup_name{
label: "desired label"
description: "desired description"
max_cache_age: "N (minutes | hours | days)"
sql_trigger: SQL query ;;
}
## Possibly more datagroup declarations
fiscal_month_offset: N
persist_for: "N (seconds | minutes | hours)"
persist_with: datagroup_name
week_start_day: monday | tuesday | wednesday | thursday | friday | saturday | sunday
## VISUALIZATION AND FORMATTING PARAMETERS
map_layer: map_name{
extents_json_url: "URL to JSON extents file"
feature_key: "Name of TopoJSON object"
file: "TopoJSON or GeoJSON filename" # or use the url subparameter
format: topojson | vector_tile_region
label: "desired label"
max_zoom_level: number indicating max zoom
min_zoom_level: number indicating min zoom
projection: Preferred geographic projection
property_key: "TopoJSON property"
property_label_key: "Label for TopoJSON property"
url: "URL that contains map file" # or use the file subparameter
}
## Possibly more map layer declarations
named_value_format: desired_name {
value_format: "excel formatting string"
strict_value_format: yes | no
}
## Possibly more named value format declarations
參數定義
| 參數名稱 | 說明 |
|---|---|
| 結構參數 | |
access_grant |
建立存取權授權,將 LookML 結構的存取權限制為僅限獲派核准使用者屬性值的使用者。這個參數包含 user_attribute 和 allowed_values 子參數。 |
explore |
在「探索」選單中公開檢視畫面。如要進一步瞭解探索和相關參數,請參閱「探索參數參考資料」頁面。 |
include |
將檔案新增至模型 |
test |
建立資料測試,驗證模型的邏輯。專案設定包含需要資料測試的選項。為專案啟用這項功能後,專案開發人員必須先執行資料測試,才能將變更部署至正式環境。這個參數包含 explore_source 和 assert 子參數。 |
| 顯示參數 | |
label (適用於模型) |
變更模型在「探索」選單中的顯示方式 |
| 篩選參數 | |
case_sensitive (適用於模型) |
指定模型的篩選器是否區分大小寫 |
| 查詢參數 | |
connection |
變更模型的資料庫連線 |
datagroup |
為模型建立資料群組快取政策。這個參數包含 label、description、max_cache_age 和 sql_trigger 子參數。 |
fiscal_month_offset |
指定會計年度的起始月 (如與日曆年不同) |
persist_for (適用於模型) |
變更模型的快取設定 |
persist_with (適用於模型) |
指定要用於模型快取政策的資料群組 |
week_start_day |
指定與週相關的維度應從星期幾開始 |
| 視覺化和格式化參數 | |
map_layer (適用於模型) |
建立自訂地圖,以便搭配 map_layer_name 使用 |
named_value_format |
建立自訂值格式,以搭配 value_format_name 使用。這個參數包含 value_format 和 strict_value_format 子參數。 |
| 應避免使用的參數 | |
scoping |
移除 3.52 已不需要 |
template |
已移除 3.30 已不需要 |