无法访问类型为 ARRAY<STRUCT<hitNumber INT64, time INT64, hour INT64, ...>> at [1:104] 的值的字段 customDimensions

Cannot access field customDimensions on a value with type ARRAY<STRUCT<hitNumber INT64, time INT64, hour INT64, ...>> at [1:104]

我是 google 的新手 bigquery.I 我正在尝试从 google bigquery 数据集之一获取数据,但遇到错误 screenshot attached

SQL查询:

SELECT  h.value
FROM `bigquery-public-data.google_analytics_sample.ga_sessions_20170801`,
UNNEST(hits.customDimensions) AS h
LIMIT 10;

请让我知道我在这里做错了什么。

hits 是一个数组。您不能直接访问数组的元素;您需要取消嵌套数组以生成一系列您可以引用的元素。您可能打算取消 hitscustomDimensions 的嵌套:

SELECT cd.value
FROM `bigquery-public-data.google_analytics_sample.ga_sessions_20170801`,
UNNEST(hits) AS h,
UNNEST(h.customDimensions) AS cd
LIMIT 10;

customDimensions 数组对于 bigquery-public-data.google_analytics_sample.ga_sessions_20170801 table 中的每一行都是空的,因此您将收到此查询的空结果集。实际上,如果您在自己的 table、运行 中有非空 customDimensions,针对它的类似查询将产生结果。