模型参数

模型文件用于指定数据库连接,定义使用该连接的探索集,并定义探索与其他视图的关系。与其他 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 移除了 3.52 不再需要
template 移除了 3.30 不再需要