模型参数

模型文件用于指定数据库连接,定义使用该连接的探索集,并定义探索与其他视图的关系。与其他 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_attributeallowed_values 子参数。
explore 在“探索”菜单中公开视图。如需详细了解探索及其参数,请参阅探索参数参考页面。
include 将文件添加到模型
test 创建数据测试以验证模型的逻辑。项目设置包含一个用于要求进行数据测试的选项。为项目启用此选项后,项目中的开发者必须先运行数据测试,然后才能将其更改部署到生产环境。此参数具有 explore_sourceassert 子参数。
显示参数
label (适用于模型) 更改模型在“探索”菜单中的显示方式
过滤条件参数
case_sensitive (适用于模型) 指定过滤条件是否对模型区分大小写
查询参数
connection 更改模型的数据库连接
datagroup 为模型创建数据组缓存政策。此参数具有 labeldescriptionmax_cache_agesql_trigger 子参数。
fiscal_month_offset 指定会计年度的起始月份(如果与日历年不同)
persist_for (适用于模型) 更改模型的缓存设置
persist_with (适用于模型) 指定用于模型缓存政策的数据组
week_start_day 指定与周相关的维度应从哪一天开始
可视化和格式设置参数
map_layer (适用于模型) 创建要与 map_layer_name 搭配使用的自定义地图
named_value_format 创建要与 value_format_name 搭配使用的自定义值格式。此参数具有 value_formatstrict_value_format 子参数。
应避免使用的参数
scoping Removed 3.52 No longer required
template Removed 3.30 No longer required