【问题标题】:Error in getting value in custom dimension in google bigquery在 google bigquery 中获取自定义维度的值时出错
【发布时间】:2018-09-19 12:10:23
【问题描述】:

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

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

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: &lt;id&gt;.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

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

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

非常感谢!

【问题讨论】:

    标签: sql google-bigquery custom-dimensions


    【解决方案1】:

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

    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
    

    【讨论】:

      【解决方案2】:

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

          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

      【讨论】:

      • 先谢谢大家的帮助!我更换了ID,但还是返回同样的问题……就是:无法解析表名“hits”:数据集名丢失。
      • @PakHangLeung 我编辑了答案,我认为在 alis 中使用 h 进行命中,因此在选择命中时不会找到它,因此会产生错误
      • 您需要为查询启用标准 SQL,或使用新的 BigQuery UI。
      • @Zaynul Abadin Tuhin 不幸的是仍然不起作用..即使尝试简单地使用 select *,仍然有同样的问题。
      • @PakHangLeung 你能不能 SELECT * FROM UNNEST(hits) 只是想知道会返回什么想知道并请检查 select * from [.ga_sessions_20180805] 是否存在表
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多