UNNEST(hit.eCommerceAction),Google Bigquery

时间:2017-01-11 00:00:37

标签: google-bigquery

我使用相同的逻辑来取消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 个答案:

答案 0 :(得分:5)

我可以通过更简单的查询重现错误:

#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