【以下的问题经过翻译处理】 似乎Athena不支持在ARRAY_AGG函数中使用ORDER BY语句。以下是一个示例。
WITH dataset AS (
SELECT 1 AS breakdown_id, 1 AS history_order, 'OPEN' AS action
UNION ALL
SELECT 1 AS breakdown_id, 2 AS history_order, 'IN_PROGRESS' AS action
UNION ALL
SELECT 1 AS breakdown_id, 3 AS history_order, 'CLOSED' AS action
UNION ALL
SELECT 2 AS breakdown_id, 1 AS history_order, 'OPEN' AS action
UNION ALL
SELECT 2 AS breakdown_id, 2 AS history_order, 'IN_PROGRESS' AS action
UNION ALL
SELECT 3 AS breakdown_id, 1 AS history_order, 'OPEN' AS action
UNION ALL
SELECT 3 AS breakdown_id, 2 AS history_order, 'IN_PROGRESS' AS action
UNION ALL
SELECT 3 AS breakdown_id, 3 AS history_order, 'WAITING_FOR_INPUT' AS action
)
SELECT breakdown_id
, ARRAY_AGG(action) AS actions
FROM dataset
GROUP BY breakdown_id
如果运行以下查询,记录将按预期聚合成数组。
然而,数组的元素需要按照history_order列指定的顺序排列。不幸的是,将ORDER BY添加到ARRAY_AGG函数中会导致无任何结果返回。
这是一个缺陷还是特性?更重要的是,是否有其他方法可以按history_order排序获取数组?