在 Presto 中取消嵌套结构数组
Unnest array of structure in Presto
我有以下 json 格式的数据
create table events (
id_user bigint,
experiments ARRAY <
STRUCT <
id: BIGINT,
impressed: BOOLEAN,
variantId: BIGINT
>
>
)
describe events
returns:
columns | types
id_user | bigint
experiments | array(row(id bigint, impressed boolean, variantid bigint))
我想使用以下命令取消嵌套数组结构
select CAST(ROW(array[experiments]) AS ROW(id BIGINT, impressed boolean, variantid bigint)) as test
from events
然后 returns 出现以下错误:
失败:fromType 和 toType 的大小必须匹配
当我在数组中输入虚拟数据时,命令运行顺利。
问题是什么以及我如何克服它?
presto returns the following error: failed: the size of fromType and toType must match
这个:
ROW(array[experiments])
用一个字段构造一个 ROW
,类型为“array
of row
”
I want to unnest the array
如果你想要 unnest
数组,你需要这样的东西:
SELECT *
FROM events
LEFT JOIN UNNEST(experiments) AS t(experiment) ON true
(对于较旧的 Presto 版本,请使用 CROSS JOIN
而不是 LEFT JOIN .. ON true
;请注意,这会改变语义)
我有以下 json 格式的数据
create table events (
id_user bigint,
experiments ARRAY <
STRUCT <
id: BIGINT,
impressed: BOOLEAN,
variantId: BIGINT
>
>
)
describe events
returns:
columns | types
id_user | bigint
experiments | array(row(id bigint, impressed boolean, variantid bigint))
我想使用以下命令取消嵌套数组结构
select CAST(ROW(array[experiments]) AS ROW(id BIGINT, impressed boolean, variantid bigint)) as test
from events
然后 returns 出现以下错误: 失败:fromType 和 toType 的大小必须匹配
当我在数组中输入虚拟数据时,命令运行顺利。
问题是什么以及我如何克服它?
presto returns the following error: failed: the size of fromType and toType must match
这个:
ROW(array[experiments])
用一个字段构造一个 ROW
,类型为“array
of row
”
I want to unnest the array
如果你想要 unnest
数组,你需要这样的东西:
SELECT *
FROM events
LEFT JOIN UNNEST(experiments) AS t(experiment) ON true
(对于较旧的 Presto 版本,请使用 CROSS JOIN
而不是 LEFT JOIN .. ON true
;请注意,这会改变语义)