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

Do not use ValueArray as key for PARTITION BY with 1 column

上级 85a79304
......@@ -298,7 +298,7 @@ public abstract class SelectGroups {
* a key of partition
* @return expression data or null
*/
public final PartitionData getWindowExprData(DataAnalysisOperation expr, ValueArray partitionKey) {
public final PartitionData getWindowExprData(DataAnalysisOperation expr, Value partitionKey) {
if (partitionKey == null) {
return windowData.get(expr);
} else {
......@@ -317,7 +317,7 @@ public abstract class SelectGroups {
* @param object
* window expression data to set
*/
public final void setWindowExprData(DataAnalysisOperation expr, ValueArray partitionKey, PartitionData obj) {
public final void setWindowExprData(DataAnalysisOperation expr, Value partitionKey, PartitionData obj) {
if (partitionKey == null) {
Object old = windowData.put(expr, obj);
assert old == null;
......
......@@ -21,7 +21,6 @@ import org.h2.result.SortOrder;
import org.h2.table.ColumnResolver;
import org.h2.table.TableFilter;
import org.h2.value.Value;
import org.h2.value.ValueArray;
import org.h2.value.ValueInt;
/**
......@@ -184,7 +183,7 @@ public abstract class DataAnalysisOperation extends Expression {
protected Object getWindowData(Session session, SelectGroups groupData, boolean forOrderBy) {
Object data;
ValueArray key = over.getCurrentKey(session);
Value key = over.getCurrentKey(session);
PartitionData partition = groupData.getWindowExprData(this, key);
if (partition == null) {
data = forOrderBy ? new ArrayList<>() : createAggregateData();
......@@ -258,7 +257,7 @@ public abstract class DataAnalysisOperation extends Expression {
PartitionData partition;
Object data;
boolean forOrderBy = over.getOrderBy() != null;
ValueArray key = over.getCurrentKey(session);
Value key = over.getCurrentKey(session);
partition = groupData.getWindowExprData(this, key);
if (partition == null) {
// Window aggregates with FILTER clause may have no collected values
......
......@@ -185,11 +185,14 @@ public final class Window {
* session
* @return key for the current group, or null
*/
public ValueArray getCurrentKey(Session session) {
public Value getCurrentKey(Session session) {
if (partitionBy == null) {
return null;
}
int len = partitionBy.size();
if (len == 1) {
return partitionBy.get(0).getValue(session);
} else {
Value[] keyValues = new Value[len];
// update group
for (int i = 0; i < len; i++) {
......@@ -198,6 +201,7 @@ public final class Window {
}
return ValueArray.get(keyValues);
}
}
/**
* Returns SQL representation.
......
......@@ -133,7 +133,7 @@ INSERT INTO TEST VALUES
(4, 'b', 8);
> update count: 4
SELECT ROW_NUMBER() OVER(ORDER /**/ BY TYPE) RN, TYPE, SUM(CNT) SUM FROM TEST GROUP BY TYPE;
SELECT ROW_NUMBER() OVER (ORDER /**/ BY TYPE) RN, TYPE, SUM(CNT) SUM FROM TEST GROUP BY TYPE;
> RN TYPE SUM
> -- ---- ---
> 1 a 1
......@@ -141,6 +141,16 @@ SELECT ROW_NUMBER() OVER(ORDER /**/ BY TYPE) RN, TYPE, SUM(CNT) SUM FROM TEST GR
> 3 c 4
> rows: 3
SELECT A, B, C, ROW_NUMBER() OVER (PARTITION BY A, B) N FROM
VALUES (1, 1, 1), (1, 1, 2), (1, 2, 3), (2, 1, 4) T(A, B, C);
> A B C N
> - - - -
> 1 1 1 1
> 1 1 2 2
> 1 2 3 1
> 2 1 4 1
> rows: 4
SELECT RANK () OVER () FROM TEST;
> exception SYNTAX_ERROR_2
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论