gpt4 book ai didi

google-bigquery - 大查询 : select * replace from multiple nested column

转载 作者:行者123 更新时间:2023-12-02 17:10:48 26 4
gpt4 key购买 nike

我正在尝试删除嵌套在多个记录中的字段。正在关注this问题,我尝试了以下操作(删除具有路径 a.b.d 的列 d)但出现错误:Unrecognized name: b at [6:68]

WITH T AS (
SELECT * from unnest([struct(struct(struct(10 as c,'test' as d) as b,'field2' as field2) as a)])

)

select * replace ((select as struct a.* replace( (select as struct b.* except (d)) as b)) as a) from T;

最佳答案

根据我在您的问题中的理解 - 您的原始行如下

STRUCT(STRUCT(STRUCT(10 AS c,'test' AS d) AS b,'field2' AS field2) AS a) original_struct  

你需要把它送到

STRUCT(STRUCT(STRUCT(10 AS c) AS b,'field2' AS field2) AS a) original_struct 

下面是 BigQuery Standard SQL 的实现

#standardSQL
WITH t AS (
SELECT STRUCT(STRUCT(STRUCT(10 AS c,'test' AS d) AS b,'field2' AS field2) AS a) original_struct
)
SELECT
original_struct,
(
SELECT AS STRUCT (
SELECT AS STRUCT (
SELECT AS STRUCT * EXCEPT(d)
FROM UNNEST([original_struct.a.b]) b
) b,
original_struct.a.field2
) a
) new_struct
FROM t

原始结构看起来像

Row original_struct.a.b.c   original_struct.a.b.d   original_struct.a.field2    
1 10 test field2

新结构是

Row new_struct.a.b.c    new_struct.a.field2  
1 10 field2

因此,要进一步将其应用于您的特定情况 - 请参见下面的示例

#standardSQL
WITH t AS (
SELECT 1 id, 2 x, 3 y, STRUCT(STRUCT(STRUCT(10 AS c,'test' AS d) AS b,'field2' AS field2) AS a) xyz, 4 v, 5 w
)
SELECT * REPLACE (
(
SELECT AS STRUCT (
SELECT AS STRUCT (
SELECT AS STRUCT * EXCEPT(d)
FROM UNNEST([xyz.a.b]) b
) b,
xyz.a.field2
) a
) AS xyz)
FROM t

关于google-bigquery - 大查询 : select * replace from multiple nested column,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49366370/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com