lookml-sets

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

LookML Sets

LookML Sets

Sets are reusable lists of fields (dimensions, measures, and filters) defined within a view or a model. They are primarily used to group fields together for various purposes such as drill-down paths, explore field visibility, and more.
Sets是在view或model中定义的可重用字段列表(包括dimensions、measures和filters)。它们主要用于将字段分组,以实现钻取路径设置、Explore字段可见性控制等多种用途。

Syntax

Syntax

lookml
set: set_name {
  fields: [field_name1, field_name2, view_name.field_name3, ...]
}
lookml
set: set_name {
  fields: [field_name1, field_name2, view_name.field_name3, ...]
}

Key Features

Key Features

  • Reusability: Define a list of fields once and use it in multiple places.
  • Composition:
    • Include All:
      [set_name*]
      includes all fields from another set.
    • Exclude:
      [-field_name]
      excludes a specific field.
    • External Reference:
      view_name.set_name*
      refers to a set in another view (ensure views are joined).
  • Reusability:只需定义一次字段列表,即可在多个地方复用。
  • Composition(组合):
    • Include All
      [set_name*]
      包含另一个set中的所有字段。
    • Exclude
      [-field_name]
      排除特定字段。
    • External Reference
      view_name.set_name*
      引用另一个view中的set(确保视图已关联)。

Use Cases

Use Cases

1. Drill Fields (Primary Use Case)

1. Drill Fields (Primary Use Case)

Sets are the standard way to define what happens when a user clicks on a measure value. Instead of listing fields repeatedly, define a set and reference it.
lookml
view: orders {
  # ... dimensions ...

  set: order_details {
    fields: [id, created_date, status, user.email]
  }

  measure: count {
    type: count
    drill_fields: [order_details*]
  }
}
Sets是定义用户点击度量值时触发行为的标准方式。无需重复列出字段,只需定义一个set并引用它。
lookml
view: orders {
  # ... dimensions ...

  set: order_details {
    fields: [id, created_date, status, user.email]
  }

  measure: count {
    type: count
    drill_fields: [order_details*]
  }
}

2. Controlling Explore Visibility (Field Picker)

2. Controlling Explore Visibility (Field Picker)

You can use sets at the Explore level to explicitly define which fields are visible to users. This is best practice for curating Explores.
lookml
explore: orders {
  fields: [ALL_FIELDS*]         # Start with everything (default)
  # OR
  fields: [orders.order_details*, users.user_info*] # Whitelist specific sets
}
你可以在Explore级别使用sets来明确定义对用户可见的字段。这是整理Explore的最佳实践。
lookml
explore: orders {
  fields: [ALL_FIELDS*]         # 默认包含所有字段
  # OR
  fields: [orders.order_details*, users.user_info*] # 仅允许特定sets
}

3. Excluding Fields

3. Excluding Fields

Use sets to exclude specific fields from an Explore without hiding them at the view level (which hides them globally).
lookml
explore: orders {
  fields: [ALL_FIELDS*, -users.password_hash]
}
使用sets可以在Explore级别排除特定字段,无需在view级别隐藏(这会全局隐藏字段)。
lookml
explore: orders {
  fields: [ALL_FIELDS*, -users.password_hash]
}

Best Practices

Best Practices

1. The
detail
Set

1. The
detail
Set

Every view should ideally have a default set (commonly named
detail
or
drill_set
) that includes the most relevant fields for drilling into a record from that view.
lookml
view: users {
  dimension: id { primary_key: yes ... }
  dimension: name { ... }
  dimension: email { ... }

  # Standard set for drilling
  set: detail {
    fields: [id, name, email]
  }
}
每个view理想情况下都应包含一个默认set(通常命名为
detail
drill_set
),其中包含从该view钻取记录时最相关的字段。
lookml
view: users {
  dimension: id { primary_key: yes ... }
  dimension: name { ... }
  dimension: email { ... }

  # 用于钻取的标准set
  set: detail {
    fields: [id, name, email]
  }
}

2. Naming Conventions

2. Naming Conventions

  • Use
    snake_case
    for set names.
  • Use descriptive names like
    user_info
    ,
    financial_metrics
    ,
    drill_detail
    .
  • 为set名称使用
    snake_case
    格式。
  • 使用描述性名称,例如
    user_info
    financial_metrics
    drill_detail

3. Avoid Cross-View Dependencies in View Sets

3. Avoid Cross-View Dependencies in View Sets

While you can reference
other_view.field
in a view's set, this creates a dependency. Ensure that
other_view
is always joined whenever the set is used.
  • Better: Define sets local to the view (only its own fields).
  • Explore Level: Combine sets from different views at the Explore level (e.g.,
    fields: [orders.detail*, users.detail*]
    ).
虽然你可以在view的set中引用
other_view.field
,但这会创建依赖关系。确保在使用该set时,
other_view
始终已关联。
  • 更佳方案:定义视图本地的set(仅包含自身字段)。
  • Explore级别:在Explore级别组合来自不同视图的sets(例如:
    fields: [orders.detail*, users.detail*]
    )。

4. Cumulative Sets

4. Cumulative Sets

You can build sets on top of other sets.
lookml
set: basic_info {
  fields: [id, name]
}

set: extended_info {
  fields: [basic_info*, email, created_date]
}
你可以基于其他sets构建新的set。
lookml
set: basic_info {
  fields: [id, name]
}

set: extended_info {
  fields: [basic_info*, email, created_date]
}