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

Fix hypothetical set functions with filter that removes all rows

上级 54dc0836
......@@ -42,6 +42,7 @@ import org.h2.value.Value;
import org.h2.value.ValueArray;
import org.h2.value.ValueBoolean;
import org.h2.value.ValueDouble;
import org.h2.value.ValueInt;
import org.h2.value.ValueLong;
import org.h2.value.ValueNull;
import org.h2.value.ValueRow;
......@@ -453,6 +454,19 @@ public class Aggregate extends AbstractAggregate {
private Value getHypotheticalSet(Session session, AggregateData data) {
AggregateDataCollecting collectingData = (AggregateDataCollecting) data;
Value arg = collectingData.getSharedArgument();
if (arg == null) {
switch (aggregateType) {
case RANK:
case DENSE_RANK:
return ValueInt.get(1);
case PERCENT_RANK:
return ValueDouble.ZERO;
case CUME_DIST:
return ValueDouble.ONE;
default:
throw DbException.getUnsupportedException("aggregateType=" + aggregateType);
}
}
collectingData.add(session.getDatabase(), arg);
Value[] array = collectingData.getArray();
Comparator<Value> sort = orderBySort.getRowValueComparator();
......
......@@ -90,19 +90,31 @@ SELECT
RANK(1) WITHIN GROUP (ORDER BY V) OVER (ORDER BY V) R1,
RANK(3) WITHIN GROUP (ORDER BY V) OVER (ORDER BY V) R3,
RANK(7) WITHIN GROUP (ORDER BY V) OVER (ORDER BY V) R7,
RANK(7) WITHIN GROUP (ORDER BY V) FILTER (WHERE V <> 2) OVER (ORDER BY V) F7,
V
FROM TEST ORDER BY V;
> R1 R3 R7 V
> -- -- -- -
> 1 2 2 1
> 1 3 3 2
> 1 3 5 3
> 1 3 5 3
> 1 3 6 4
> 1 3 7 5
> 1 3 8 6
> R1 R3 R7 F7 V
> -- -- -- -- -
> 1 2 2 2 1
> 1 3 3 2 2
> 1 3 5 4 3
> 1 3 5 4 3
> 1 3 6 5 4
> 1 3 7 6 5
> 1 3 8 7 6
> rows (ordered): 7
SELECT
RANK(1) WITHIN GROUP (ORDER BY V) FILTER (WHERE FALSE) R,
DENSE_RANK(1) WITHIN GROUP (ORDER BY V) FILTER (WHERE FALSE) D,
PERCENT_RANK(1) WITHIN GROUP (ORDER BY V) FILTER (WHERE FALSE) P,
CUME_DIST(1) WITHIN GROUP (ORDER BY V) FILTER (WHERE FALSE) C
FROM VALUES (1) T(V);
> R D P C
> - - --- ---
> 1 1 0.0 1.0
> rows: 1
SELECT RANK(1) WITHIN GROUP (ORDER BY V, V) FROM TEST;
> exception SYNTAX_ERROR_2
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论