BigQuery除了双嵌套列

时间:2017-03-29 10:32:06

标签: select google-bigquery standard-sql

您需要从我的表中排除列hits.latencyTracking.userTimingLabel并选择所有其他列。我怎样才能在Standard Sql中执行此操作? 我发现已经有类似问题的问题(BigQuery select * except nested column),但在我的情况下,我有一个双嵌套列,我无法调整代码。 感谢

3 个答案:

答案 0 :(得分:1)

如果hits是一个数组且latencyTracking是一个结构,那么:

SELECT ARRAY(SELECT (SELECT AS STRUCT latencyTracking.* EXCEPT(userTimingLabel)) AS latencyTracking FROM UNNEST(hits)) AS hits
FROM YourTable;

答案 1 :(得分:0)

select * except nested column与您的问题之间的差异,是由于hits是ARRAY的事实。以下是如何从结构数组中排除列:

SELECT * REPLACE 
 (ARRAY(SELECT AS STRUCT * EXCEPT(page) FROM UNNEST(hits) h) AS hits)
FROM `google.com:analytics-bigquery.LondonCycleHelmet.ga_sessions_20130910`

答案 2 :(得分:0)

以下是我的几分钱:
我认为它可以回答你的确切问题/案例

context.tbl_1
    .Where(i => i.VisitorUserId = 'bf8581b04429fdf56c6ebc')
    .Select(i => new { SellerId = i.SellerId, ProductCount = i.tbl_2.Count() })

我在公共桌面上测试了它,如下所示:

#standardSQL
SELECT * REPLACE(
  ARRAY(
    SELECT AS STRUCT hit.* 
      REPLACE((SELECT AS STRUCT latencyTracking.* EXCEPT(userTimingLabel)) AS latencyTracking)
    FROM UNNEST(hits) AS hit
  ) AS hits)
FROM `yourProject.yourDataset.yourTable`