用法
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