我的 athena 桌上有一列,看起来像这样:
id, authors
123,[{institutions=[<more_content>], author={name="james"}}, {institutions=[<more content>], author={name="john"}}]
245,[]
765,[{institutions=[<more_content>], author={name="mike"}}, {institutions=[<more content>], author={name="peter"}}]
我喜欢这个分解表:
id, author_row_number,name
123,1,james
123,2,john
765,1,mike
765,2,peter
其中
author_row_number
是行内的索引。
我该如何在 Athena Trino 中实现这一目标
通常,此类输出针对行或字典类型显示。根据 Athena 引擎版本和实际类型,可能存在差异,但假设您有一个数组,这两个数组之一,主要技巧是使用
UNNEST
与 WITH ORDINALITY
子句结合使用(请参阅文档)。沿着这些思路(假设 ARRAY(ROW(...))
的类型和基于 Trino 的引擎 v.3,它将把行解压到单独的列中,未测试):
select id,
t.author_row_number,
t.author.name name
from table,
unnest(authors) WITH ORDINALITY as t(institutions, author, author_row_number)