当前位置:  开发笔记 > 编程语言 > 正文

UNNEST(hit.eCommerceAction),Google Bigquery

如何解决《UNNEST(hit.eCommerceAction),GoogleBigquery》经验,为你挑选了1个好方法。

我使用相同的逻辑来取消hit.eCommerceAction,但它不像其他字段那样工作.有关这个问题的任何帮助?另外,max(if())函数是否是用于获取两个hits.customeDimenison.value的正确函数?

SELECT
 Date
  ,COUNT(DISTINCT FULLVISITORID)
 , product.v2ProductCategory

  ,max(if(customDimensions.index=2, customDimensions.value,null))  as dest
  ,max(if(customDimensions.index=21, customDimensions.value,null))  as pax
 ,eCommerceAction.action_type
 ,product.v2ProductName

FROM `table` as t
  CROSS JOIN UNNEST(hits) AS hit
  CROSS JOIN UNNEST(hit.customDimensions) AS customDimensions
  CROSS JOIN UNNEST(hit.eCommerceAction) as eCommerceAction
  CROSS JOIN UNNEST(hit.product) AS product
GROUP BY 
      Date
      ,product.v2ProductCategory
    ,eCommerceAction.action_type
,product.v2ProductName

我得到的错误代码是错误:UNNEST中引用的值必须是数组.UNNEST包含STRUCT类型的表达式



1> Felipe Hoffa..:

我可以使用更简单的查询重现错误:

#standardSQL
SELECT DISTINCT hit.eCommerceAction.action_type 
FROM `73156703.ga_sessions_20170109` t
  , UNNEST(hits) hit
  , UNNEST(hit.customDimensions) customDimensions
  , UNNEST(hit.eCommerceAction) as eCommerceAction

这里的问题是它eCommerceAction不是REPEATED记录,因此没有数组UNNEST.

固定查询:

#standardSQL
SELECT DISTINCT hit.eCommerceAction.action_type 
FROM `ga_sessions_20170109`  t
  , UNNEST(hits) hit
  , UNNEST(hit.customDimensions) customDimensions

推荐阅读
mylvfamily
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有