【问题标题】:BigQuery SQL: Cannot query the cross product of repeated fields /BigQuery SQL:无法查询重复字段的叉积/
【发布时间】:2018-04-16 09:51:39
【问题描述】:

我的目标是过滤所有访问者,仅分析客户(位于 customDimension.index =2 中,然后进一步仅过滤客户的特定类型的综合浏览量。

SELECT customDimensions.value AS CustomerID,
SUM(totals.pageviews) as page_views,
SUM(CASE WHEN hits.type = 'PAGE' AND hits.contentGroup.contentGroup2 = 'important' THEN 1 ELSE 0 END) AS important_pageviews
FROM `xxxxxxxx.ga_sessions_20180415`
WHERE customDimensions.index = 2
GROUP BY CustomerID 

我收到以下错误(使用 StandardSQL):

Error: Cannot access field index on a value with type
ARRAY<STRUCT<index INT64, value STRING>> at [5:24]

对于旧版 SQL:

错误:无法查询重复字段的叉积 customDimensions.index 和 hits.contentGroup.contentGroup2。

编辑:

SELECT cd.value AS CustomerID,
SUM(totals.pageviews) as page_views,
SUM(CASE WHEN hits.type = 'PAGE' AND hits.contentGroup.contentGroup2 = 'important' THEN 1 ELSE 0 END) AS important_pageviews
FROM `xxxxxxxx.ga_sessions_20180415`,
UNNEST(customDimensions) AS cd
WHERE cd.index = 2
GROUP BY CustomerID 

返回:

Error: Cannot access field type on a value with type ARRAY<STRUCT<hitNumber INT64, time INT64, hour INT64, ...>> at [3:20]

我尝试使用 UNNEST(hits.type) = 'PAGE' AND UNNEST(hitscontentGroup.contentGroup2) = 'important' 更正 3:20 行,这给出了 Error: Syntax error: Unexpected keyword UNNEST at [3:15]

【问题讨论】:

  • 我猜你正在寻找unnestFROM xxxxxxxx.ga_sessions_20180415, unnset(customDimensions) as cd where cd.index = 2(您也可以在子查询中取消嵌套以保留行数)
  • @danihp 我仍然得到相同的错误(标准 SQL) - 错误:无法访问类型为 ARRAY> at [1:25] 的值的字段值
  • @GRS 。 . .你有一个数组。您需要从数组中提取一个或多个元素以进行查询。如果我们能看到数据的样子会有所帮助。

标签: sql google-bigquery legacy-sql


【解决方案1】:

由于 customDimensions 是一个数组,您需要 unnest this 才能引用它的内容,请参阅下面的 StandardSQL 示例,我在 BigQuery 中从 Google Analytics 数据中取消嵌套 UserID:

SELECT customDimension.value AS UserID
FROM `my.project.data` AS t
  CROSS JOIN UNNEST(t.customdimensions) AS customDimension
  WHERE customDimension.index = 2

【讨论】:

  • 谢谢,但我正在尝试将 2 个未嵌套组合在一起。在第二行添加t.hits.contentGroup.contentGroup2后,为了获取这些客户查看的页面数的数据,我返回我的错误。
  • 对不起,你的第二个不可靠在哪里,我只能看到一个?您可以在第一个之后直接添加另一个取消嵌套以进一步取消嵌套吗?
猜你喜欢
  • 2015-08-04
  • 1970-01-01
  • 2017-09-25
  • 1970-01-01
  • 2020-06-04
  • 2016-07-17
  • 1970-01-01
  • 2016-03-30
  • 2013-07-10
相关资源
最近更新 更多