BigQuery使用新的SQL語法訪問定制維度

[英]BigQuery accessing CustomDimensions with new SQL syntax


I am migrating to the new SQL syntax in BigQuery, since it seems more flexible. However I am a bit stuck when it comes to access the fields in the customDimensions. I am writing something quite simple like this:

我正在遷移到BigQuery中的新的SQL語法,因為它看起來更靈活。然而,當涉及到訪問customDimensions維度中的字段時,我有點不知所措。我寫的東西很簡單:

SELECT 
  cd.customDimensions.index,
  cd.customDimensions.value
FROM `xxxxx.ga_sessions_20170312`, unnest(hits) cd
limit 100

But I get the error

但我得到了誤差

Error: Cannot access field index on a value with type ARRAY<STRUCT<index INT64, value STRING>>

However if I run something like this works perfectly fine:

但是,如果我運行這樣的程序,效果很好:

    SELECT 
        date,
        SUM((SELECT SUM(latencyTracking.pageLoadTime) FROM UNNEST(hits))) pageLoadTime,
        SUM((SELECT SUM(latencyTracking.serverResponseTime) FROM UNNEST(hits))) serverResponseTime
   FROM `xxxxxx.ga_sessions_20170312`
    group by 1

Is there some different logic when it comes to query the customDimensions?

在查詢customDimensions時,是否存在一些不同的邏輯?

2 个解决方案

#1


4  

If the intention is to retrieve all custom dimensions in a flattened form, then join with UNNEST(customDimensions) as well:

如果目的是在一個扁平的表單中檢索所有自定義維度,那么就加入UNNEST(customDimensions):

#standardSQL
SELECT 
  cd.index,
  cd.value
FROM `xxxxx.ga_sessions_20170312`,
  unnest(hits) hit,
  unnest(hit.customDimensions) cd
limit 100;

#2


1  

SELECT
fullvisitorid,
( SELECT MAX(IF(index=1,value, NULL))FROM UNNEST(hits.customDimensions)) AS CustomDimension1,
( SELECT MAX(IF(index=2,value, NULL))FROM UNNEST(hits.customDimensions)) AS CustomDimension2
FROM
  `XXXXXXX`, unnest(hits) as hits

注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2017/03/22/25214138a499ddef8b1c029c8b6fb415.html



 
粤ICP备14056181号  © 2014-2021 ITdaan.com