Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
ccacc3b8
提交
ccacc3b8
authored
9月 19, 2018
作者:
Evgenij Ryazanov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Reject invalid usages of window frames in optimize()
上级
0ef8cba8
隐藏空白字符变更
内嵌
并排
正在显示
7 个修改的文件
包含
43 行增加
和
20 行删除
+43
-20
help.csv
h2/src/docsrc/help/help.csv
+1
-1
Parser.java
h2/src/main/org/h2/command/Parser.java
+3
-17
Window.java
h2/src/main/org/h2/expression/aggregate/Window.java
+5
-2
WindowFunction.java
h2/src/main/org/h2/expression/aggregate/WindowFunction.java
+11
-0
lead.sql
h2/src/test/org/h2/test/scripts/functions/window/lead.sql
+6
-0
ntile.sql
h2/src/test/org/h2/test/scripts/functions/window/ntile.sql
+2
-0
row_number.sql
.../test/org/h2/test/scripts/functions/window/row_number.sql
+15
-0
没有找到文件。
h2/src/docsrc/help/help.csv
浏览文件 @
ccacc3b8
...
...
@@ -2555,7 +2555,7 @@ ROWS|RANGE|GROUP
[EXCLUDE {CURRENT ROW|GROUP|TIES|NO OTHERS}]
","
A window frame clause.
Is currently supported only in
aggregates and FIRST_VALUE(), LAST_VALUE(), and NTH_VALUE() window functions.
May be specified only for
aggregates and FIRST_VALUE(), LAST_VALUE(), and NTH_VALUE() window functions.
","
RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW EXCLUDE GROUP
"
...
...
h2/src/main/org/h2/command/Parser.java
浏览文件 @
ccacc3b8
...
...
@@ -3049,7 +3049,7 @@ public class Parser {
}
Window
over
=
null
;
if
(
readIf
(
"OVER"
))
{
over
=
readWindowSpecification
(
aggregate
);
over
=
readWindowSpecification
();
aggregate
.
setOverCondition
(
over
);
currentSelect
.
setWindowQuery
();
}
else
if
(!
isAggregate
)
{
...
...
@@ -3059,7 +3059,7 @@ public class Parser {
}
}
private
Window
readWindowSpecification
(
AbstractAggregate
aggregate
)
{
private
Window
readWindowSpecification
()
{
read
(
OPEN_PAREN
);
ArrayList
<
Expression
>
partitionBy
=
null
;
if
(
readIf
(
"PARTITION"
))
{
...
...
@@ -3075,21 +3075,7 @@ public class Parser {
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
();
}
WindowFrame
frame
=
readWindowFrame
();
read
(
CLOSE_PAREN
);
return
new
Window
(
partitionBy
,
orderBy
,
frame
);
}
...
...
h2/src/main/org/h2/expression/aggregate/Window.java
浏览文件 @
ccacc3b8
...
...
@@ -177,7 +177,7 @@ public final class Window {
* @see Expression#getSQL()
*/
public
String
getSQL
()
{
if
(
partitionBy
==
null
&&
orderBy
==
null
)
{
if
(
partitionBy
==
null
&&
orderBy
==
null
&&
frame
==
null
)
{
return
"OVER ()"
;
}
StringBuilder
builder
=
new
StringBuilder
().
append
(
"OVER ("
);
...
...
@@ -192,7 +192,10 @@ public final class Window {
}
appendOrderBy
(
builder
,
orderBy
);
if
(
frame
!=
null
&&
!
frame
.
isDefault
())
{
builder
.
append
(
' '
).
append
(
frame
.
getSQL
());
if
(
builder
.
charAt
(
builder
.
length
()
-
1
)
!=
'('
)
{
builder
.
append
(
' '
);
}
builder
.
append
(
frame
.
getSQL
());
}
return
builder
.
append
(
')'
).
toString
();
}
...
...
h2/src/main/org/h2/expression/aggregate/WindowFunction.java
浏览文件 @
ccacc3b8
...
...
@@ -400,6 +400,17 @@ public class WindowFunction extends AbstractAggregate {
@Override
public
Expression
optimize
(
Session
session
)
{
if
(
over
.
getWindowFrame
()
!=
null
)
{
switch
(
type
)
{
case
FIRST_VALUE:
case
LAST_VALUE:
case
NTH_VALUE:
break
;
default
:
String
sql
=
getSQL
();
throw
DbException
.
getSyntaxError
(
sql
,
sql
.
length
()
-
1
);
}
}
super
.
optimize
(
session
);
if
(
args
!=
null
)
{
for
(
int
i
=
0
;
i
<
args
.
length
;
i
++)
{
...
...
h2/src/test/org/h2/test/scripts/functions/window/lead.sql
浏览文件 @
ccacc3b8
...
...
@@ -129,5 +129,11 @@ SELECT LEAD(VALUE, -1) OVER (ORDER BY ID) FROM TEST;
SELECT
LAG
(
VALUE
,
-
1
)
OVER
(
ORDER
BY
ID
)
FROM
TEST
;
>
exception
INVALID_VALUE_2
SELECT
LEAD
(
VALUE
)
OVER
(
ORDER
BY
ID
RANGE
CURRENT
ROW
)
FROM
TEST
;
>
exception
SYNTAX_ERROR_1
SELECT
LAG
(
VALUE
)
OVER
(
ORDER
BY
ID
RANGE
CURRENT
ROW
)
FROM
TEST
;
>
exception
SYNTAX_ERROR_1
DROP
TABLE
TEST
;
>
ok
h2/src/test/org/h2/test/scripts/functions/window/ntile.sql
浏览文件 @
ccacc3b8
...
...
@@ -113,3 +113,5 @@ SELECT NTILE(X) OVER (ORDER BY X) FROM (SELECT * FROM SYSTEM_RANGE(1, 6));
>
6
>
rows
(
ordered
):
6
SELECT
NTILE
(
X
)
OVER
(
ORDER
BY
X
RANGE
CURRENT
ROW
)
FROM
(
SELECT
*
FROM
SYSTEM_RANGE
(
1
,
1
));
>
exception
SYNTAX_ERROR_1
h2/src/test/org/h2/test/scripts/functions/window/row_number.sql
浏览文件 @
ccacc3b8
...
...
@@ -100,6 +100,21 @@ SELECT
>
4
1
1
0
.
0
1
.
0
>
rows
:
4
SELECT
ROW_NUMBER
()
OVER
(
ORDER
BY
ID
RANGE
CURRENT
ROW
)
FROM
TEST
;
>
exception
SYNTAX_ERROR_1
SELECT
RANK
()
OVER
(
ORDER
BY
ID
RANGE
CURRENT
ROW
)
FROM
TEST
;
>
exception
SYNTAX_ERROR_1
SELECT
DENSE_RANK
()
OVER
(
ORDER
BY
ID
RANGE
CURRENT
ROW
)
FROM
TEST
;
>
exception
SYNTAX_ERROR_1
SELECT
PERCENT_RANK
()
OVER
(
ORDER
BY
ID
RANGE
CURRENT
ROW
)
FROM
TEST
;
>
exception
SYNTAX_ERROR_1
SELECT
CUME_DIST
()
OVER
(
ORDER
BY
ID
RANGE
CURRENT
ROW
)
FROM
TEST
;
>
exception
SYNTAX_ERROR_1
DROP
TABLE
TEST
;
>
ok
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论