我正在迁移到BigQuery中的新SQL语法,因为它似乎更灵活。但是,在访问customDimensions中的字段时,我有些困惑。我正在写一些很简单的东西:

SELECT
  cd.customDimensions.index,
  cd.customDimensions.value
FROM `xxxxx.ga_sessions_20170312`, unnest(hits) cd
limit 100


但是我得到了错误

Error: Cannot access field index on a value with type ARRAY<STRUCT<index INT64, value STRING>>


但是,如果我运行类似的命令,效果很好:

    SELECT
        date,
        SUM((SELECT SUM(latencyTracking.pageLoadTime) FROM UNNEST(hits))) pageLoadTime,
        SUM((SELECT SUM(latencyTracking.serverResponseTime) FROM UNNEST(hits))) serverResponseTime
   FROM `xxxxxx.ga_sessions_20170312`
    group by 1


查询customDimensions是否有一些不同的逻辑?

最佳答案

如果要以展平的形式检索所有自定义尺寸,则还应加入UNNEST(customDimensions)

#standardSQL
SELECT
  cd.index,
  cd.value
FROM `xxxxx.ga_sessions_20170312`,
  unnest(hits) hit,
  unnest(hit.customDimensions) cd
limit 100;

09-26 23:29