1

我有一个关于在谷歌大查询中提取自定义维度的问题。有些人已经问过这个问题,但是,解决方案不起作用..

问题是,当我尝试像这样提取自定义维度的信息时

SELECT
fullvisitorId,
visitid,
hit.hitnumber,
(SELECT x.value FROM UNNEST(hit.customDimensions) x WHERE x.index = 1) as productCategory,
(SELECT x.value FROM UNNEST(hit.customDimensions) x WHERE x.index = 2) as loyaltyClass,
(SELECT x.value FROM UNNEST(hit.customDimensions) x WHERE x.index = 3) as existingCustomer
FROM [<id>.ga_sessions_20180805],UNNEST(hits) as hit
LIMIT 100

然后我收到一个错误“无法解析表名“命中”:数据集名称丢失。”

我试着像这样使用其他人的解决方案

SELECT
    fullvisitorId,
    visitid,
    hit.hitnumber,
    (SELECT x.value FROM UNNEST(hit.customDimensions) x WHERE x.index = 1) as productCategory,
    (SELECT x.value FROM UNNEST(hit.customDimensions) x WHERE x.index = 2) as loyaltyClass,
    (SELECT x.value FROM UNNEST(hit.customDimensions) x WHERE x.index = 3) as existingCustomer
FROM `<id>.ga_sessions_*`, UNNEST(hits) AS h
WHERE _TABLE_SUFFIX = '20180805'

然后我得到另一个错误 Invalid table name: <id>.ga_sessions_*[Try using standard SQL ( https://cloud.google.com/bigquery/docs/reference/standard-sql/enabling-standard-sql)]

更新:我什至尝试了最基本的查询

    SELECT
      *
    FROM [<id>.ga_sessions_20180805]
    LEFT JOIN UNNEST(hits) as hits
   LIMIT 10

仍然返回相同的错误....

我为这两个脚本犯了什么错误?以及如何获得自定义维度值?

非常感谢!

4

2 回答 2

4

在您的第一个查询中 - 您应该只在下面的行中修复表引用

FROM [<id>.ga_sessions_20180805],UNNEST(hits) as hit

类似于

FROM `yourproject.yourdataset.ga_sessions_20180805`,UNNEST(hits) as hit  

第二个查询的类似修复,但除此之外 - 别名h应替换hit 为如下

FROM `yourproject.yourdataset.ga_sessions_*`, UNNEST(hits) AS hit

注意:以上适用于 BigQuery 标准 SQL - 因此您可以将以下行作为第一行添加到查询的最顶部

#standardSQL     

例如

#standardSQL     
SELECT
  fullvisitorId,
  visitid,
  hit.hitnumber,
  (SELECT x.value FROM UNNEST(hit.customDimensions) x WHERE x.index = 1) as productCategory,
  (SELECT x.value FROM UNNEST(hit.customDimensions) x WHERE x.index = 2) as loyaltyClass,
  (SELECT x.value FROM UNNEST(hit.customDimensions) x WHERE x.index = 3) as existingCustomer
FROM `yourproject.yourdataset.ga_sessions_20180805`,UNNEST(hits) as hit 
LIMIT 100
于 2018-09-19T13:44:28.787 回答
3

您可以使用所有支持的情况

    SELECT
    fullvisitorId,
    visitid,
    h.hitnumber,
    case when x.index = 1 then x.value end as productCategory,
    case when x.index = 2 then x.value end as loyaltyClass,
    case when x.index = 3 then x.value end as existingCustomer
    FROM [<id>.ga_sessions_20180805]
    LEFT JOIN UNNEST( hits ) as h
   WHERE _TABLE_SUFFIX = '20180805'

注意:为查询启用标准 SQL,或使用新的 BigQuery UI

于 2018-09-19T12:14:01.713 回答