在 google bigquery 中获取自定义维度的值时出错

Error in getting value in custom dimension in google bigquery

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

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

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

然后我得到一个错误 "Table name "hits" cannot be resolved: dataset name is missing."

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

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

还是returns同样的错误....

我为这两个脚本犯的错误是什么?我怎样才能获得自定义维度值?

非常感谢!

您可以使用所有支持的案例

    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

在您的第一个查询中 - 您应该在下面的行

中修复 table 引用
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 Standard 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