mcpField
L
lookml-explore

lookml-explore

github.com/looker-open-sourceデータ・データベース43149 回インストール2 週間前に更新
リポジトリ

lookml-explore について

Lookerのクエリー入口を構築・保守する人向けの、LookML Explore設定リファレンススキルです。命名、説明、結合、フィルター、キャッシュ、集約テーブルによる最適化、Exploreの拡張を扱います。

主な機能

  1. 01Exploreの命名と必須パラメーターを規定
  2. 02結合関係と条件を説明
  3. 03変更可能・固定フィルターを解説
  4. 04集約テーブルとマテリアライズを説明
  5. 05Exploreの継承と拡張を解説

活用シーン

  1. 01結合を含むExploreを作成
  2. 02ユーザーが参照できるフィールドを制限
  3. 03クエリーのフィルターとキャッシュを設定
  4. 04集約テーブルで一般的なクエリーを最適化

インストール

コマンドをコピーしてターミナルで実行します。

$npx skills add https://github.com/looker-open-source/looker-skills --skill lookml-explore

インストール後、Claude Code で/lookml-exploreを入力して読み込まれたか確認します。

同梱ファイルreferences/advanced.mdreferences/joins.md

詳細

手順

1. 基本規則

  1. 命名規則:Explore の名前には snake_case を使用します。
  2. 必須パラメーター:
    • description:網羅率 100%。すべての Explore に説明を指定する必要があります。
    • label:UI で Explore に表示する、ユーザーにわかりやすい名前です。
    • view_name:デフォルトでは Explore 名が使われますが、明示的に定義するほうが安全です。
  3. 結合:
    • relationship:必須(one_to_one、many_to_one)。
    • sql_on:必須。${left.id} = ${right.id} の構文を使用します。
    • type:デフォルトは left_outer です。必要に応じて inner または full_outer を明示的に指定します。
  4. 書式:
    • 見た目を整えるためだけにビューの名前を変更する目的で from を使用しないでください。代わりに view_label を使用します。
    • 例外:ポリモーフィック結合、自己結合、スコープ変更を伴う拡張。

2. 高度な設定

  • always_filter:ユーザーが変更できるものの、削除できない特定のフィルターです。
  • sql_always_where:ユーザーが変更できない特定の制約です。
  • persist_with:Explore のキャッシュをデータグループに関連付けます(例:default_datagroup)。
  • fields:必要に応じて、内容を厳密に制御するために包括的なリストを使用します(ALL_FIELDS*、-view.field)。

3. パフォーマンスの最適化(集計テーブル)

集計テーブル(集計認識)を使用すると、Looker は詳細な未加工データではなく、より小さな事前集計済みテーブルに対してクエリを実行できるため、クエリのパフォーマンスが大幅に向上します。

集計テーブルの構造
explore: orders {
  aggregate_table: rollup_name {
    query: {
      dimensions: [created_date, status]
      measures: [total_revenue, count]
      filters: [orders.created_date: "6 months"]
    }
    materialization: {
      datagroup_trigger: ecommerce_etl
      # partition_keys: ["created_date"] # BigQuery/Presto optimization
      # increment_key: "created_date"    # Incremental builds
      # increment_offset: 3              # Rebuild last 3 periods
    }
  }
}
主なパラメーター
  1. クエリ:「集計」の構成を定義します。

    • ディメンション:ダッシュボードでよく使用されるすべてのディメンション(フィルターを含む)を含めます。
    • メジャー:基本メジャー(sum、count)を含めます。Looker は sum と count から平均を算出できます。
    • フィルター:任意です。集計対象をデータの一部に制限します(例:「過去 6 か月」)。
  2. マテリアライズ:

    • datagroup_trigger:(推奨)ETL ジョブの完了時に再構築します。
    • sql_trigger_value:SQL クエリが新しい値を返したときに再構築します。
    • increment_key:(高度な設定)全件再構築ではなく、新しいデータを追加します。大規模なテーブルに最適です。
    • indexes/partition_keys/cluster_keys:方言固有の最適化です。
  3. ベストプラクティス:

    • 時間粒度:必要な最小粒度(例:date)を含めます。Looker は date を month や year に自動的に集約できます。
    • 完全一致:集計認識ロジックが機能するには、ユーザーのクエリのフィールドが集計テーブルのフィールドの厳密なサブセットである必要があります。
    • フィルター認識:ユーザーが集計テーブルに含まれていないフィールドでフィルターを適用した場合、「完全一致」の特別なケースを除き、Looker はそのテーブルを使用できません。よく使われるフィルターフィールドを dimensions リストに追加してください。

4. Explore の拡張

  • 拡張:extends: [base_explore] を使用して、別の Explore から結合、フィールド、説明を継承します。
    • 使用例:共通の結合を含む「Base」Explore を作成し、特定の分析向けに「Extended」Explore を作成します(例:orders -> marketing_orders)。

例

基本的な Explore

explore: orders {
  label: "Orders"
  description: "Analyze order data, including user and product details."
  view_name: orders
  
  join: users {
    relationship: many_to_one
    sql_on: ${orders.user_id} = ${users.id} ;;
  }
}

フィルターとキャッシュを使用する Explore

explore: events {
  label: "Web Events"
  description: "User interaction events."
  persist_with: default_datagroup

  # Users can change this filter, but it defaults to '7 days'
  always_filter: {
    filters: [events.created_date: "7 days"]
  }

  # Users CANNOT change this filter.
  sql_always_where: ${events.is_test_data} = false ;;
  
  join: sessions {
    relationship: many_to_one
    sql_on: ${events.session_id} = ${sessions.session_id} ;;
  }
}

## Aggregate Table (Advanced)

```lookml
explore: orders {
  aggregate_table: monthly_sales_summary {
    query: {
      dimensions: [created_month, status, products.category]
      measures: [total_revenue, count]
      filters: [orders.created_date: "2 years"]
    }
    materialization: {
      datagroup_trigger: ecommerce_etl
      partition_keys: ["created_month"]
      increment_key: "created_month"
      increment_offset: 1 # Rebuild current and previous month
    }
  }
}

拡張された Explore

explore: orders_extended {
  extends: [orders]
  label: "Orders (Marketing View)"
  view_name: orders
  
  # Add new joins specific to this view
  join: marketing_channels {
    sql_on: ${orders.channel_id} = ${marketing_channels.id} ;;
    relationship: many_to_one
  }
}

## Reference Skills

For more complex scenarios, refer to these specialized skills:
- [Advanced Explore Configuration](references/advanced.md): UNNESTing, lateral flattens, and row-level security.
- [Joins Deep Dive](references/joins.md): Detailed join types, relationships, and aliasing.

コメント