在 Bigquery 中,如何将字符串的结构转换为列

发布于 2025-01-10 09:26:11 字数 687 浏览 0 评论 0原文

因此,在表中,根据 Image 有 3 列,第三列是 Record(Struct),包含 2 个新旧结构。这些结构内部有列和值。

我可以通过这个 -change.old.name 访问每个最后一列,但我想将它们转换为普通列并用它创建另一个表?

尝试取消嵌套但不起作用,因为它不是数组。

数据结构图像

更新:

终于排序了。应该通过选择所有嵌套数据来选择和转换所有列,并将别名设置为我们想要的方式或用下划线替换点。然后用它创建一个表。

    create table abc 
as 
select 
ID
,Created_on
,Change.old.add as Change_old_add
,Change.old.name as Change_old_name
,Change.old.count_people as Change_old_count_people
,Change.new.add as Change_new_add
,Change.new.name as Change_new_name
,Change.new.count_people as Change_new_count_people
FROM `project.Table`

So, In the table, there are 3 columns as per Image , 3rd one is Record(Struct), conntaing 2 structs old and new. Inside those structs there are columns and values.

I can access each final column by this -change.old.name , But I want to convert them as normal columns and create another taable with that ?

tried unnest but doesn't work as it's not array.

Data structure image

UPDATE :

Finally got it sorted. Should select and convert all columns by selecting all of the nested data and set the alias as how we want or replace dot with an underscore. Then create a table with that.

    create table abc 
as 
select 
ID
,Created_on
,Change.old.add as Change_old_add
,Change.old.name as Change_old_name
,Change.old.count_people as Change_old_count_people
,Change.new.add as Change_new_add
,Change.new.name as Change_new_name
,Change.new.count_people as Change_new_count_people
FROM `project.Table`

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

漫漫岁月 2025-01-17 09:26:11

终于整理好了。应该通过选择所有嵌套数据来选择和转换所有列,并将别名设置为我们想要的方式或用下划线替换点。然后用它创建一个表。

 create table abc 
as 
select 
ID
,Created_on
,Change.old.add as Change_old_add
,Change.old.name as Change_old_name
,Change.old.count_people as Change_old_count_people
,Change.new.add as Change_new_add
,Change.new.name as Change_new_name
,Change.new.count_people as Change_new_count_people
FROM `project.Table`

Finally got it sorted. Should select and convert all columns by selecting all of the nested data and set the alias as how we want or replace dot with an underscore. Then create a table with that.

 create table abc 
as 
select 
ID
,Created_on
,Change.old.add as Change_old_add
,Change.old.name as Change_old_name
,Change.old.count_people as Change_old_count_people
,Change.new.add as Change_new_add
,Change.new.name as Change_new_name
,Change.new.count_people as Change_new_count_people
FROM `project.Table`
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文