使用 Bigquery 删除具有“重复”模式的嵌套列
Posted
技术标签:
【中文标题】使用 Bigquery 删除具有“重复”模式的嵌套列【英文标题】:Using Bigquery remove the nested columns which has "REPEATED" mode 【发布时间】: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
【问题讨论】:
【参考方案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;
【讨论】:
这是字符串函数的替换函数吗?这 -> cloud.google.com/bigquery/docs/reference/standard-sql/… 不。查看Modifiers for * operator【参考方案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;
【讨论】:
以上是关于使用 Bigquery 删除具有“重复”模式的嵌套列的主要内容,如果未能解决你的问题,请参考以下文章