【问题标题】:UNNEST(hit.eCommerceAction), Google BigqueryUNNEST(hit.eCommerceAction),谷歌 Bigquery
【发布时间】:2017-01-11 00:00:37
【问题描述】:

我使用相同的逻辑来取消嵌套 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 类型的表达式

【问题讨论】:

    标签: google-bigquery


    【解决方案1】:

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

    #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
    

    【讨论】:

    • 您好 Felipe,非常感谢您的回复。这个对我有用。只是出于好奇,知道我可以去了解更多关于 google big query 的任何网站/教程吗?
    • 您好!取决于您要查找的内容,但我所了解的有关 BigQuery 的所有内容都会发布到 reddit.com/r/bigquery
    • 谢谢!等我完成这份报告后,我会看看。 :)
    猜你喜欢
    • 2012-05-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多