【问题标题】:Using Bigquery remove the nested columns which has "REPEATED" mode使用 Bigquery 删除具有“重复”模式的嵌套列
【发布时间】:2021-12-30 05:00:06
【问题描述】:

使用 Bigquery,我试图删除如下所示的嵌套架构,但无法这样做。谁能告诉我。如何实现?

表格:

FiledName          Type       Mode
Person            RECORD   REPEATED
Person.Name       STRING   NULLABLE
Person.Add        RECORD   NULLABLE
Person.Add.line   STRING   NULLABLE

代码:

create table `project_id.dataset.new_table_name` as 
select * replace(
   (select as ARRAY(struct person.* except(add))) as person
)
from `project_id.dataset.table_name`;

预期输出:

FiledName          Type       Mode
Person            RECORD   REPEATED
Person.Name       STRING   NULLABLE

【问题讨论】:

    标签: sql google-bigquery


    【解决方案1】:

    考虑以下方法

    create table `project_id.dataset.new_table_name` as 
    select * replace(
        array(select as struct person.* except(add) from t.person) as person
      )
    from `project_id.dataset.table_name` t;
    

    【讨论】:

    【解决方案2】:

    试试这个

    create table `project_id.dataset.new_table_name` as 
    SELECT 
          [STRUCT (P.NAME AS NAME)] AS PERSON
    
    from `project_id.dataset.table_name`,UNNEST(PERSON) AS P;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-10-19
      • 2021-11-27
      • 2017-08-22
      • 1970-01-01
      • 2022-07-07
      • 2016-06-26
      • 1970-01-01
      • 2017-04-22
      相关资源
      最近更新 更多