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

Fix window version of MODE()

上级 1ab2ebb2
......@@ -199,7 +199,7 @@ public class Aggregate extends AbstractAggregate {
}
break;
case MODE:
v = orderByList.get(0).expression.getValue(session);
v = remembered != null ? remembered[0] : orderByList.get(0).expression.getValue(session);
break;
default:
// Use argument as is
......
......@@ -52,15 +52,35 @@ SELECT MODE(V ORDER BY V DESC) FROM TEST;
SELECT MODE(V ORDER BY V + 1) FROM TEST;
> exception IDENTICAL_EXPRESSIONS_SHOULD_BE_USED
SELECT MODE() WITHIN GROUP(ORDER BY V) FROM TEST;
SELECT MODE() WITHIN GROUP (ORDER BY V) FROM TEST;
>> 1
SELECT MODE() WITHIN GROUP(ORDER BY V ASC) FROM TEST;
SELECT MODE() WITHIN GROUP (ORDER BY V ASC) FROM TEST;
>> 1
SELECT MODE() WITHIN GROUP(ORDER BY V DESC) FROM TEST;
SELECT MODE() WITHIN GROUP (ORDER BY V DESC) FROM TEST;
>> 3
SELECT
MODE() WITHIN GROUP (ORDER BY V) OVER () MA,
MODE() WITHIN GROUP (ORDER BY V DESC) OVER () MD,
MODE() WITHIN GROUP (ORDER BY V) OVER (ORDER BY V) MWA,
MODE() WITHIN GROUP (ORDER BY V DESC) OVER (ORDER BY V) MWD,
V FROM TEST;
> MA MD MWA MWD V
> -- -- ---- ---- ----
> 1 3 1 1 1
> 1 3 1 1 1
> 1 3 1 1 1
> 1 3 1 2 2
> 1 3 1 2 2
> 1 3 1 2 2
> 1 3 1 3 3
> 1 3 1 3 3
> 1 3 1 3 3
> 1 3 null null null
> rows: 10
DROP TABLE TEST;
> ok
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论