Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
0ef8cba8
提交
0ef8cba8
authored
6 年前
作者:
Evgenij Ryazanov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Do not sort window data if ORDER BY is not specified
上级
a6c409c9
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
48 行增加
和
41 行删除
+48
-41
Parser.java
h2/src/main/org/h2/command/Parser.java
+36
-34
AbstractAggregate.java
...c/main/org/h2/expression/aggregate/AbstractAggregate.java
+12
-7
没有找到文件。
h2/src/main/org/h2/command/Parser.java
浏览文件 @
0ef8cba8
...
...
@@ -3049,40 +3049,7 @@ public class Parser {
}
Window
over
=
null
;
if
(
readIf
(
"OVER"
))
{
read
(
OPEN_PAREN
);
ArrayList
<
Expression
>
partitionBy
=
null
;
if
(
readIf
(
"PARTITION"
))
{
read
(
"BY"
);
partitionBy
=
Utils
.
newSmallArrayList
();
do
{
Expression
expr
=
readExpression
();
partitionBy
.
add
(
expr
);
}
while
(
readIf
(
COMMA
));
}
ArrayList
<
SelectOrderBy
>
orderBy
=
null
;
if
(
readIf
(
ORDER
))
{
read
(
"BY"
);
orderBy
=
parseSimpleOrderList
();
}
else
if
(!
isAggregate
)
{
orderBy
=
new
ArrayList
<>(
0
);
}
WindowFrame
frame
;
if
(
aggregate
instanceof
WindowFunction
)
{
WindowFunction
w
=
(
WindowFunction
)
aggregate
;
switch
(
w
.
getFunctionType
())
{
case
FIRST_VALUE:
case
LAST_VALUE:
case
NTH_VALUE:
frame
=
readWindowFrame
();
break
;
default
:
frame
=
null
;
}
}
else
{
frame
=
readWindowFrame
();
}
read
(
CLOSE_PAREN
);
over
=
new
Window
(
partitionBy
,
orderBy
,
frame
);
over
=
readWindowSpecification
(
aggregate
);
aggregate
.
setOverCondition
(
over
);
currentSelect
.
setWindowQuery
();
}
else
if
(!
isAggregate
)
{
...
...
@@ -3092,6 +3059,41 @@ public class Parser {
}
}
private
Window
readWindowSpecification
(
AbstractAggregate
aggregate
)
{
read
(
OPEN_PAREN
);
ArrayList
<
Expression
>
partitionBy
=
null
;
if
(
readIf
(
"PARTITION"
))
{
read
(
"BY"
);
partitionBy
=
Utils
.
newSmallArrayList
();
do
{
Expression
expr
=
readExpression
();
partitionBy
.
add
(
expr
);
}
while
(
readIf
(
COMMA
));
}
ArrayList
<
SelectOrderBy
>
orderBy
=
null
;
if
(
readIf
(
ORDER
))
{
read
(
"BY"
);
orderBy
=
parseSimpleOrderList
();
}
WindowFrame
frame
;
if
(
aggregate
instanceof
WindowFunction
)
{
WindowFunction
w
=
(
WindowFunction
)
aggregate
;
switch
(
w
.
getFunctionType
())
{
case
FIRST_VALUE:
case
LAST_VALUE:
case
NTH_VALUE:
frame
=
readWindowFrame
();
break
;
default
:
frame
=
null
;
}
}
else
{
frame
=
readWindowFrame
();
}
read
(
CLOSE_PAREN
);
return
new
Window
(
partitionBy
,
orderBy
,
frame
);
}
private
WindowFrame
readWindowFrame
()
{
WindowFrameUnits
units
;
if
(
readIf
(
"ROWS"
))
{
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/expression/aggregate/AbstractAggregate.java
浏览文件 @
0ef8cba8
...
...
@@ -118,6 +118,8 @@ public abstract class AbstractAggregate extends Expression {
ArrayList
<
SelectOrderBy
>
orderBy
=
over
.
getOrderBy
();
if
(
orderBy
!=
null
)
{
overOrderBySort
=
createOrder
(
session
,
orderBy
,
getNumExpressions
());
}
else
if
(!
isAggregate
())
{
overOrderBySort
=
new
SortOrder
(
session
.
getDatabase
(),
new
int
[
getNumExpressions
()],
new
int
[
0
],
null
);
}
}
return
this
;
...
...
@@ -176,7 +178,7 @@ public abstract class AbstractAggregate extends Expression {
}
if
(
over
!=
null
)
{
ArrayList
<
SelectOrderBy
>
orderBy
=
over
.
getOrderBy
();
if
(
orderBy
!=
null
)
{
if
(
orderBy
!=
null
||
!
isAggregate
()
)
{
updateOrderedAggregate
(
session
,
groupData
,
groupRowId
,
orderBy
);
return
;
}
...
...
@@ -359,7 +361,7 @@ public abstract class AbstractAggregate extends Expression {
data
=
partition
.
getData
();
}
}
if
(
over
.
getOrderBy
()
!=
null
)
{
if
(
over
.
getOrderBy
()
!=
null
||
!
isAggregate
()
)
{
return
getOrderedResult
(
session
,
groupData
,
partition
,
data
);
}
Value
result
=
partition
.
getResult
();
...
...
@@ -384,10 +386,11 @@ public abstract class AbstractAggregate extends Expression {
private
void
updateOrderedAggregate
(
Session
session
,
SelectGroups
groupData
,
int
groupRowId
,
ArrayList
<
SelectOrderBy
>
orderBy
)
{
int
ne
=
getNumExpressions
();
int
size
=
orderBy
.
size
()
;
int
size
=
orderBy
!=
null
?
orderBy
.
size
()
:
0
;
Value
[]
array
=
new
Value
[
ne
+
size
+
1
];
rememberExpressions
(
session
,
array
);
for
(
int
i
=
0
;
i
<
size
;
i
++)
{
@SuppressWarnings
(
"null"
)
SelectOrderBy
o
=
orderBy
.
get
(
i
);
array
[
ne
++]
=
o
.
expression
.
getValue
(
session
);
}
...
...
@@ -395,7 +398,6 @@ public abstract class AbstractAggregate extends Expression {
@SuppressWarnings
(
"unchecked"
)
ArrayList
<
Value
[]>
data
=
(
ArrayList
<
Value
[]>)
getData
(
session
,
groupData
,
false
,
true
);
data
.
add
(
array
);
return
;
}
private
Value
getOrderedResult
(
Session
session
,
SelectGroups
groupData
,
PartitionData
partition
,
Object
data
)
{
...
...
@@ -404,9 +406,12 @@ public abstract class AbstractAggregate extends Expression {
result
=
new
HashMap
<>();
@SuppressWarnings
(
"unchecked"
)
ArrayList
<
Value
[]>
orderedData
=
(
ArrayList
<
Value
[]>)
data
;
int
ne
=
getNumExpressions
();
int
rowIdColumn
=
ne
+
over
.
getOrderBy
().
size
();
Collections
.
sort
(
orderedData
,
overOrderBySort
);
int
rowIdColumn
=
getNumExpressions
();
ArrayList
<
SelectOrderBy
>
orderBy
=
over
.
getOrderBy
();
if
(
orderBy
!=
null
)
{
rowIdColumn
+=
orderBy
.
size
();
Collections
.
sort
(
orderedData
,
overOrderBySort
);
}
getOrderedResultLoop
(
session
,
result
,
orderedData
,
rowIdColumn
);
partition
.
setOrderedResult
(
result
);
}
...
...
This diff is collapsed.
Click to expand it.
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论