You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

查询BigQuery GA会话中customDimensions总数报错如何解决

报错原因与修复方案

报错翻译

Cannot access field customDimensions on a value with type ARRAY<STRUCT<productSKU STRING, v2ProductName STRING, v2ProductCategory STRING, ...>> at [5:21]

翻译为:无法在ARRAY<STRUCT<productSKU STRING, v2ProductName STRING, v2ProductCategory STRING, ...>>类型的数组值上直接访问customDimensions字段,错误位于SQL语句第5行第21个字符处。

根因说明

  • 执行UNNEST(hits.product) AS prod后,hits.product依然是原生的数组类型,不能直接调用数组内结构体的customDimensions字段,应该使用展开后的单条产品结构体prod调用该字段
  • 统计计数时无需从最顶层hits开始嵌套引用,直接使用customDimensions展开后的别名cust取值即可

修复后SQL

仅统计有customDimensions的记录

SELECT COUNT(cust.value)
FROM `bigquery-public-data.google_analytics_sample.ga_sessions_xxxx`,
UNNEST(hits) AS hits,
UNNEST(hits.product) AS prod,
UNNEST(prod.customDimensions) AS cust

包含无customDimensions的产品的统计(无值时计数为0)

SELECT COUNT(cust.value)
FROM `bigquery-public-data.google_analytics_sample.ga_sessions_xxxx`,
UNNEST(hits) AS hits,
UNNEST(hits.product) AS prod
LEFT JOIN UNNEST(prod.customDimensions) AS cust

内容的提问来源于stack exchange,提问作者Daniel

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.27 00:36:04