BigQuery 除了双嵌套列

BigQuery except double nested column

您好需要从我的 table 和 select 所有其他列中排除列 hits.latencyTracking.userTimingLabel。我如何在标准 Sql 中执行此操作? 我已经发现了一个关于类似问题的问题 (),但在我的例子中,我有一个双嵌套列,我无法调整代码。 谢谢

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

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

和您的问题之间的区别在于 hits 是一个数组。以下是如何从结构数组中排除列:

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

以下是我对此的几点看法:
我认为它回答了你的确切问题/案例

#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`    

我在 public table 上测试如下:

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