提交 021c29e1 authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

Fix and test some distinct window aggregates

上级 86098d30
......@@ -129,8 +129,7 @@ class AggregateDataDefault extends AggregateData {
@Override
Value getValue(Database database, int dataType, boolean distinct) {
if (distinct) {
count = 0;
groupDistinct(database, dataType);
return getDistinct(database, dataType);
}
Value v = null;
switch (aggregateType) {
......@@ -192,14 +191,15 @@ class AggregateDataDefault extends AggregateData {
return a;
}
private void groupDistinct(Database database, int dataType) {
private Value getDistinct(Database database, int dataType) {
if (distinctValues == null) {
return;
return ValueNull.INSTANCE;
}
count = 0;
AggregateDataDefault d = new AggregateDataDefault(aggregateType);
for (Value v : distinctValues.keys()) {
add(database, dataType, false, v);
d.add(database, dataType, false, v);
}
return d.getValue(database, dataType, false);
}
}
......@@ -69,3 +69,17 @@ SELECT NR FROM (SELECT COUNT(ID) OVER (ORDER BY NAME) AS NR,
DROP TABLE TEST;
> ok
SELECT I, V, COUNT(V) OVER W C, COUNT(DISTINCT V) OVER W D FROM
VALUES (1, 1), (2, 1), (3, 1), (4, 1), (5, 2), (6, 2), (7, 3) T(I, V)
WINDOW W AS (ORDER BY I);
> I V C D
> - - - -
> 1 1 1 1
> 2 1 2 1
> 3 1 3 1
> 4 1 4 1
> 5 2 5 2
> 6 2 6 2
> 7 3 7 3
> rows (ordered): 7
......@@ -81,3 +81,17 @@ SELECT
> 7 28 28 15 36
> 8 36 36 8 36
> rows (ordered): 8
SELECT I, V, SUM(V) OVER W S, SUM(DISTINCT V) OVER W D FROM
VALUES (1, 1), (2, 1), (3, 1), (4, 1), (5, 2), (6, 2), (7, 3) T(I, V)
WINDOW W AS (ORDER BY I);
> I V S D
> - - -- -
> 1 1 1 1
> 2 1 2 1
> 3 1 3 1
> 4 1 4 1
> 5 2 6 3
> 6 2 8 3
> 7 3 11 6
> rows (ordered): 7
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论