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

Use TreeMap for window partitions

上级 674102df
...@@ -11,12 +11,12 @@ import java.util.HashMap; ...@@ -11,12 +11,12 @@ import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.TreeMap;
import org.h2.engine.Session; import org.h2.engine.Session;
import org.h2.expression.Expression; import org.h2.expression.Expression;
import org.h2.expression.analysis.DataAnalysisOperation; import org.h2.expression.analysis.DataAnalysisOperation;
import org.h2.expression.analysis.PartitionData; import org.h2.expression.analysis.PartitionData;
import org.h2.util.ValueHashMap;
import org.h2.value.Value; import org.h2.value.Value;
import org.h2.value.ValueArray; import org.h2.value.ValueArray;
...@@ -223,7 +223,7 @@ public abstract class SelectGroups { ...@@ -223,7 +223,7 @@ public abstract class SelectGroups {
/** /**
* Maps an partitioned window expression object to its data. * Maps an partitioned window expression object to its data.
*/ */
private final HashMap<DataAnalysisOperation, ValueHashMap<PartitionData>> windowPartitionData = new HashMap<>(); private final HashMap<DataAnalysisOperation, TreeMap<Value, PartitionData>> windowPartitionData = new HashMap<>();
/** /**
* The id of the current group. * The id of the current group.
...@@ -324,7 +324,7 @@ public abstract class SelectGroups { ...@@ -324,7 +324,7 @@ public abstract class SelectGroups {
if (partitionKey == null) { if (partitionKey == null) {
return windowData.get(expr); return windowData.get(expr);
} else { } else {
ValueHashMap<PartitionData> map = windowPartitionData.get(expr); TreeMap<Value, PartitionData> map = windowPartitionData.get(expr);
return map != null ? map.get(partitionKey) : null; return map != null ? map.get(partitionKey) : null;
} }
} }
...@@ -344,9 +344,9 @@ public abstract class SelectGroups { ...@@ -344,9 +344,9 @@ public abstract class SelectGroups {
Object old = windowData.put(expr, obj); Object old = windowData.put(expr, obj);
assert old == null; assert old == null;
} else { } else {
ValueHashMap<PartitionData> map = windowPartitionData.get(expr); TreeMap<Value, PartitionData> map = windowPartitionData.get(expr);
if (map == null) { if (map == null) {
map = new ValueHashMap<>(); map = new TreeMap<>(session.getDatabase().getCompareMode());
windowPartitionData.put(expr, map); windowPartitionData.put(expr, map);
} }
map.put(partitionKey, obj); map.put(partitionKey, obj);
......
...@@ -117,5 +117,13 @@ SELECT COUNT(N) FROM TEST; ...@@ -117,5 +117,13 @@ SELECT COUNT(N) FROM TEST;
SELECT COUNT(DISTINCT N) FROM TEST; SELECT COUNT(DISTINCT N) FROM TEST;
>> 1 >> 1
SELECT COUNT(N) OVER (PARTITION BY N) C FROM TEST;
> C
> -
> 0
> 2
> 2
> rows: 3
DROP TABLE TEST; DROP TABLE TEST;
> ok > ok
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论