提交 d29ae257 authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

Fix ARRAY_AGG with ORDER BY

上级 3fc0af12
...@@ -405,6 +405,11 @@ public class Aggregate extends Expression { ...@@ -405,6 +405,11 @@ public class Aggregate extends Expression {
if (orderByList != null) { if (orderByList != null) {
sortWithOrderBy(array); sortWithOrderBy(array);
} }
if (orderByList != null) {
for (int i = 0; i < array.length; i++) {
array[i] = ((ValueArray) array[i]).getList()[0];
}
}
return ValueArray.get(array); return ValueArray.get(array);
} }
return data.getValue(session.getDatabase(), dataType, distinct); return data.getValue(session.getDatabase(), dataType, distinct);
......
...@@ -14,10 +14,9 @@ insert into test values ('1'), ('2'), ('3'), ('4'), ('5'), ('6'), ('7'), ('8'), ...@@ -14,10 +14,9 @@ insert into test values ('1'), ('2'), ('3'), ('4'), ('5'), ('6'), ('7'), ('8'),
select array_agg(v order by v asc), select array_agg(v order by v asc),
array_agg(v order by v desc) filter (where v >= '4') array_agg(v order by v desc) filter (where v >= '4')
from test where v >= '2'; from test where v >= '2';
> ARRAY_AGG(V ORDER BY V) ARRAY_AGG(V ORDER BY V DESC) FILTER (WHERE (V >= '4')) > ARRAY_AGG(V ORDER BY V) ARRAY_AGG(V ORDER BY V DESC) FILTER (WHERE (V >= '4'))
> ---------------------------------------------------------------- ------------------------------------------------------ > ------------------------ ------------------------------------------------------
------------------------------ > (2, 3, 4, 5, 6, 7, 8, 9) (9, 8, 7, 6, 5, 4)
> (2, 3, 4, 5, 6, 7, 8, 9) (9, 8, 7, 6, 5, 4)
> rows (ordered): 1 > rows (ordered): 1
create index test_idx on test(v); create index test_idx on test(v);
...@@ -25,19 +24,17 @@ create index test_idx on test(v); ...@@ -25,19 +24,17 @@ create index test_idx on test(v);
select ARRAY_AGG(v order by v asc), select ARRAY_AGG(v order by v asc),
ARRAY_AGG(v order by v desc) filter (where v >= '4') ARRAY_AGG(v order by v desc) filter (where v >= '4')
from test where v >= '2'; from test where v >= '2';
> ARRAY_AGG(V ORDER BY V) ARRAY_AGG(V ORDER BY V DESC) FILTER (WHERE (V >= '4')) > ARRAY_AGG(V ORDER BY V) ARRAY_AGG(V ORDER BY V DESC) FILTER (WHERE (V >= '4'))
> ---------------------------------------------------------------- ------------------------------------------------------ > ------------------------ ------------------------------------------------------
------------------------------ > (2, 3, 4, 5, 6, 7, 8, 9) (9, 8, 7, 6, 5, 4)
> (2, 3, 4, 5, 6, 7, 8, 9) (9, 8, 7, 6, 5, 4)
> rows (ordered): 1 > rows (ordered): 1
select ARRAY_AGG(v order by v asc), select ARRAY_AGG(v order by v asc),
ARRAY_AGG(v order by v desc) filter (where v >= '4') ARRAY_AGG(v order by v desc) filter (where v >= '4')
from test; from test;
> ARRAY_AGG(V ORDER BY V) ARRAY_AGG(V ORDER BY V DESC) FILTER (WHERE (V >= '4')) > ARRAY_AGG(V ORDER BY V) ARRAY_AGG(V ORDER BY V DESC) FILTER (WHERE (V >= '4'))
> ------------------------------------------------------------------------ ------------------------------------------------------ > --------------------------- ------------------------------------------------------
------------------------------ > (1, 2, 3, 4, 5, 6, 7, 8, 9) (9, 8, 7, 6, 5, 4)
> (1, 2, 3, 4, 5, 6, 7, 8, 9) (9, 8, 7, 6, 5, 4)
> rows (ordered): 1 > rows (ordered): 1
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论