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

Fix and test some distinct window aggregates

上级 86098d30
...@@ -129,8 +129,7 @@ class AggregateDataDefault extends AggregateData { ...@@ -129,8 +129,7 @@ class AggregateDataDefault extends AggregateData {
@Override @Override
Value getValue(Database database, int dataType, boolean distinct) { Value getValue(Database database, int dataType, boolean distinct) {
if (distinct) { if (distinct) {
count = 0; return getDistinct(database, dataType);
groupDistinct(database, dataType);
} }
Value v = null; Value v = null;
switch (aggregateType) { switch (aggregateType) {
...@@ -192,14 +191,15 @@ class AggregateDataDefault extends AggregateData { ...@@ -192,14 +191,15 @@ class AggregateDataDefault extends AggregateData {
return a; return a;
} }
private void groupDistinct(Database database, int dataType) { private Value getDistinct(Database database, int dataType) {
if (distinctValues == null) { if (distinctValues == null) {
return; return ValueNull.INSTANCE;
} }
count = 0; AggregateDataDefault d = new AggregateDataDefault(aggregateType);
for (Value v : distinctValues.keys()) { 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, ...@@ -69,3 +69,17 @@ SELECT NR FROM (SELECT COUNT(ID) OVER (ORDER BY NAME) AS NR,
DROP TABLE TEST; DROP TABLE TEST;
> ok > 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 ...@@ -81,3 +81,17 @@ SELECT
> 7 28 28 15 36 > 7 28 28 15 36
> 8 36 36 8 36 > 8 36 36 8 36
> rows (ordered): 8 > 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 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论