bigquery 中具有父 ID 和嵌套子 ID 的层次结构

hierarchy with parent and nested child id in bigquery

我在 bigquery 中有一个 table 具有以下架构

Name         STRING NULLABLE    
Parent_id    STRING NULLABLE    
Child_ids    STRING REPEATED    

table 填充了以下行:

Name     Parent_id    Child_ids
A        1            [2,3]
B        2            [4]
C        3            null
D        4            null

我想查询 return 不仅 child_ids 还有他们的名字,即:

Name     Parent_id    Child_info
A        1            [(2,B),(3,C)]
B        2            [(4,D)]
C        3            null
D        4            null

你有什么想法吗?

考虑以下方法

select * except(Child_ids), 
  array(
    select as struct id, Name
    from t.Child_ids id
    join your_table
    on id = Parent_id
  ) Child_info
from your_table t;           

如果应用于您问题中的示例数据 - 输出为