別名

用量

view: view_name {
  dimension: field_name {
    alias: [old_field_name, old_field_name, ...]
  }
}
階層
alias
可能的欄位類型
維度、維度群組、指標、篩選器、參數

接受
以方括號括住的欄位名稱清單

定義

alias 參數會為查詢網址中可能出現的欄位提供替代名稱。如果模型中的欄位名稱有所變更,但您有預先存在的查詢網址,且希望這些網址繼續運作,這項功能就非常實用。

以下範例說明如何將名為 count 的欄位變更為新名稱 number_of_items,而不中斷任何參照 count 的現有查詢。

measure: number_of_items {  # the new name
  alias: [count]            # the old name
  type: count
}

如果多次重新命名欄位,也可以提供多個別名。舉例來說,如果您將上一個範例中的 number_of_items 欄位重新命名為 number_of_order_items,則可以使用下列項目:

measure: number_of_order_items {   # the new name
  alias: [count, number_of_items]  # the old names
  type: count
}

如要搭配維度群組使用 alias,請變更維度群組名稱,而非維度群組中的每個欄位。舉例來說,如要將維度群組 created_date 重新命名為 order_date,請執行下列操作:

dimension_group: order_date {  # the new name
  alias: [created_date]        # the old name
  type: time
  timeframes: [time, hour, date, week, month, year, hour_of_day, day_of_week, month_num, raw]
  sql: ${TABLE}.created_at ;;
}

請注意,alias 僅用於維持網址運作。在 LookML 中參照欄位時,不應使用這個屬性。例如:

measure: number_of_items {
  alias: [count]
  type: count
}
measure: percent_items_sold {
  sql: ${sold_items} / ${number_of_items} ;; # will work because there
  type: number                               # is a measure named number_of_items
}
measure: percent_items_sold {
  sql: ${sold_items} / ${count} ;; # will NOT work because you
  type: number                     # should not use alias names in LookML
}

注意事項

如果您將欄位命名為其他欄位已使用的名稱,LookML 驗證器會傳回錯誤。alias