looker-open-source/looker-skills

lookml-fields

Overview of LookML field types (Dimension, Measure, Filter, Parameter) and the role of the sql parameter in each.

소스 보기

사용 방법

  1. 설치 명령을 복사하고 자신의 에이전트 환경에 설치하기 전에 소스 패키지를 확인하세요.
  2. 필요한 도구, 인증 정보, 지원 환경은 원본 문서에서 확인하세요.
  3. 입력과 원하는 산출물을 설명하고 출처와 결과를 대조하세요.
npx skills add https://github.com/looker-open-source/looker-skills --skill lookml-fields

시작 전 확인

  • 설치에는 모델 구독, API 한도, 파일 접근 권한이 포함되지 않습니다.
  • 별점 수와 설치 수는 활동 지표이며 독립적인 품질·보안 검증이 아닙니다.
원본 Skill 문서

원본 저장소의 제목, 예시, 코드, 표, 링크, 이미지를 유지해 표시합니다.

Instructions

1. Field Types Overview

LookML fields are the building blocks of your data model. Each type serves a specific purpose in generating SQL.

Field TypePurposeSQL Generation Phase
DimensionDescribes data (attributes). Groups results.SELECT and GROUP BY clause.
MeasureAggregates data (metrics). Calculates results.SELECT clause (with aggregation).
FilterRestricts data based on conditions.WHERE or HAVING clause (via templated filters).
ParameterCaptures user input for dynamic logic.None directly (injects values into other fields).
Dimension GroupGenerates time-based dimensions (type: time) or calculates date diffs/durations (type: duration).SELECT and GROUP BY clause (multiple columns).

2. The Role of sql Parameter

The sql parameter behaves differently strictly based on the field type.

Dimensions: The "What"

  • Role: Defines the raw transformation of the column before any aggregation.
  • SQL Context: The expression is placed directly into the GROUP BY clause.
  • Input: Can reference table columns (${TABLE}.col), other dimensions (${dim}), or raw SQL functions.
  • Example:
lookml
    dimension: full_name {
      sql: CONCAT(${first_name}, ' ', ${last_name}) ;;
    }
    -- Generates: CONCAT(table.first_name, ' ', table.last_name)

Measures: The "How Much"

  • Role: Defines the value to be aggregated or the calculation involving other aggregates.
  • SQL Context: Puts the expression inside the aggregation function (e.g., SUM(sql)), or as a standalone calculation for type: number.
  • Input:
  • For type: sum/avg/min/max: References dimensions or columns.
  • For type: number: References other measures.
  • For type: count: sql is ignored (always COUNT(*) or COUNT(primary_key)).
  • Example:
lookml
    measure: total_profit {
      type: sum
      sql: ${sale_price} - ${cost} ;; 
    }
    -- Generates: SUM(sale_price - cost)

Filters: The "Which"

  • Role: Defines the condition logic, usually for Templated Filters used in Derived Tables or sql_always_where.
  • SQL Context: The sql parameter in a filter field is rarely used directly in modern LookML. Instead, the input to the filter is used in {% condition %} tags.
  • Best Practice: Identify if you need a filter field or just a parameter + dimension.
  • Example (Templated Filter):
lookml
    filter: date_filter { type: date }
    -- Usage in Derived Table SQL:
    -- WHERE {% condition date_filter %} created_at {% endcondition %}

Parameters: The "User Input"

  • Role: Does NOT generate SQL itself. It holds a user-selected value to be injected into other fields.
  • SQL Context: Accessed via Liquid variables ({% parameter name %}) inside Dimensions, Measures, or Derived Tables.
  • Input: User selects from a UI list or types a value.
  • Example:
lookml
    parameter: timeframe_selector {
      type: unquoted
      allowed_value: { value: "month" }
      allowed_value: { value: "year" }
    }
    dimension: dynamic_date {
      sql: DATE_TRUNC({% parameter timeframe_selector %}, ${created_raw}) ;;
    }

Dimension Groups: The "Time Generator & Date Diff Calculator"

  • Role: For type: time, generates multiple timeframes from a source timestamp. For type: duration, calculates time elapsed / date differences (e.g. month_since_signup, datediff) between two timestamps.
  • SQL Context: Casts, truncates, or calculates date differences across columns.
  • Input: Standardized timestamp/date expressions or start/end timestamp columns.
  • Example:
lookml
    dimension_group: created {
      type: time
      timeframes: [date, month]
      sql: ${TABLE}.created_at ;;
    }
    -- Generates:
    -- created_date -> CAST(table.created_at AS DATE)
    -- created_month -> DATE_TRUNC(table.created_at, MONTH)

3. Summary of Differences

Typesql references...Can reference Measures?Aggregated?
DimensionColumns, Other DimensionsNONo
Measure (Agg)Columns, DimensionsNOYes
Measure (Num)Other MeasuresYESYes (already agg)
Filter(Rarely used)NoN/A
Parameter(None)NoN/A

Reference Skills

For detailed standards on specific field types, refer to:

관련 작업

같은 저장소의 Skills

더 많은 Skills

모든 Skills