用法
view: view_name {
dimension: field_name {
fanout_on: repeated_record_name
}
}
|
层次结构
fanout_on |
可能的字段类型
维度、维度组、指标
接受
Google BigQuery 旧版 SQL REPEATED 子记录
|
定义
fanout_on 参数用于指定维度或指标应展开的 Google BigQuery 旧版 SQL REPEATED 子记录。
Google BigQuery 旧版 SQL 支持嵌套记录,其中一条记录可以包含多条子记录。在 Looker 中表达这些子记录会导致结果集“扇出”,这意味着父记录会重复多次。为了让 Looker 正确关联常规数据和重复数据,您可以使用 fanout_on 参数指定子记录的扇出关系。
请看以下示例数据表:
| 列名 | 类型 |
|---|---|
| name | 字符串,必需 |
| age | 整数,必需 |
| citiesLived | 记录(重复) |
| citiesLived.place | 字符串,可为 null |
| citiesLived.numberOfYears | 整数,可为 null |
不含 citiesLived 记录的数据可能如下所示:
| name | age |
|---|---|
| Wilbur Wright | 45 |
不过,添加重复的 citiesLived 记录会导致扇出,其中 name 和 age 数据会重复多次:
| name | age | citiesLived.place | citiesLived.numberOfYears |
|---|---|---|---|
| Wilbur Wright | 45 | 代顿 | 40 |
| Wilbur Wright | 45 | 巴黎 | 2 |
| Wilbur Wright | 45 | Kitty Hawk | 1 |
在对此类数据进行建模时,citiesLived 记录会导致扇出,因此它会用在 fanout_on 参数中:
dimension: city_lived {
sql: ${TABLE}.citiesLived.place ;;
fanout_on: "citiesLived"
}
dimension: years_lived {
sql: ${TABLE}.citiesLived.numberOfYears ;;
fanout_on: "citiesLived"
}
measure: cities_count {
type: count_distinct
sql: ${city_lived} ;;
fanout_on: "citiesLived"
}
measure: city_list {
type: list
list_field: city_lived
fanout_on: "citiesLived"
}
-
请注意,如果维度和指标在计算中包含重复记录,则必须使用 fanout_on。