Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
b3f9834d
提交
b3f9834d
authored
1月 14, 2019
作者:
Evgenij Ryazanov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Remember expression index in window frame bound
上级
05ea7099
全部展开
显示空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
79 行增加
和
90 行删除
+79
-90
AbstractAggregate.java
...c/main/org/h2/expression/aggregate/AbstractAggregate.java
+17
-19
DataAnalysisOperation.java
...ain/org/h2/expression/analysis/DataAnalysisOperation.java
+10
-17
WindowFrame.java
h2/src/main/org/h2/expression/analysis/WindowFrame.java
+25
-47
WindowFrameBound.java
h2/src/main/org/h2/expression/analysis/WindowFrameBound.java
+21
-0
WindowFunction.java
h2/src/main/org/h2/expression/analysis/WindowFunction.java
+6
-7
没有找到文件。
h2/src/main/org/h2/expression/aggregate/AbstractAggregate.java
浏览文件 @
b3f9834d
...
...
@@ -95,13 +95,12 @@ public abstract class AbstractAggregate extends DataAnalysisOperation {
boolean
grouped
=
frame
==
null
||
frame
.
getUnits
()
!=
WindowFrameUnits
.
ROWS
&&
frame
.
getExclusion
().
isGroupOrNoOthers
();
if
(
frame
==
null
)
{
aggregateFastPartition
(
session
,
result
,
ordered
,
-
1
,
rowIdColumn
,
grouped
);
aggregateFastPartition
(
session
,
result
,
ordered
,
rowIdColumn
,
grouped
);
return
;
}
int
frameParametersOffset
=
getWindowFrameParametersOffset
();
boolean
variableBounds
=
frame
.
isVariableBounds
();
if
(
variableBounds
)
{
variableBounds
=
checkVariableBounds
(
frame
,
ordered
,
frameParametersOffset
);
variableBounds
=
checkVariableBounds
(
frame
,
ordered
);
}
if
(
variableBounds
)
{
grouped
=
false
;
...
...
@@ -113,12 +112,12 @@ public abstract class AbstractAggregate extends DataAnalysisOperation {
if
(
unboundedFollowing
)
{
aggregateWholePartition
(
session
,
result
,
ordered
,
rowIdColumn
);
}
else
{
aggregateFastPartition
(
session
,
result
,
ordered
,
frameParametersOffset
,
rowIdColumn
,
grouped
);
aggregateFastPartition
(
session
,
result
,
ordered
,
rowIdColumn
,
grouped
);
}
return
;
}
if
(
unboundedFollowing
)
{
aggregateFastPartitionInReverse
(
session
,
result
,
ordered
,
frameParametersOffset
,
rowIdColumn
,
grouped
);
aggregateFastPartitionInReverse
(
session
,
result
,
ordered
,
rowIdColumn
,
grouped
);
return
;
}
}
...
...
@@ -126,8 +125,8 @@ public abstract class AbstractAggregate extends DataAnalysisOperation {
int
size
=
ordered
.
size
();
for
(
int
i
=
0
;
i
<
size
;)
{
Object
aggregateData
=
createAggregateData
();
for
(
Iterator
<
Value
[]>
iter
=
WindowFrame
.
iterator
(
over
,
session
,
ordered
,
getOverOrderBySort
(),
f
rameParametersOffset
,
i
,
f
alse
);
iter
.
hasNext
();)
{
for
(
Iterator
<
Value
[]>
iter
=
WindowFrame
.
iterator
(
over
,
session
,
ordered
,
getOverOrderBySort
(),
i
,
false
);
iter
.
hasNext
();)
{
updateFromExpressions
(
session
,
aggregateData
,
iter
.
next
());
}
Value
r
=
getAggregatedValue
(
session
,
aggregateData
);
...
...
@@ -135,20 +134,21 @@ public abstract class AbstractAggregate extends DataAnalysisOperation {
}
}
private
static
boolean
checkVariableBounds
(
WindowFrame
frame
,
ArrayList
<
Value
[]>
ordered
,
int
frameParametersOffset
)
{
private
static
boolean
checkVariableBounds
(
WindowFrame
frame
,
ArrayList
<
Value
[]>
ordered
)
{
int
size
=
ordered
.
size
();
int
offset
=
frameParametersOffset
;
if
(
frame
.
getStarting
().
isVariable
())
{
WindowFrameBound
bound
=
frame
.
getStarting
();
if
(
bound
.
isVariable
())
{
int
offset
=
bound
.
getExpressionIndex
();
Value
v
=
ordered
.
get
(
0
)[
offset
];
for
(
int
i
=
1
;
i
<
size
;
i
++)
{
if
(!
v
.
equals
(
ordered
.
get
(
i
)[
offset
]))
{
return
true
;
}
}
offset
++;
}
if
(
frame
.
getFollowing
()
!=
null
&&
frame
.
getFollowing
().
isVariable
())
{
bound
=
frame
.
getFollowing
();
if
(
bound
!=
null
&&
bound
.
isVariable
())
{
int
offset
=
bound
.
getExpressionIndex
();
Value
v
=
ordered
.
get
(
0
)[
offset
];
for
(
int
i
=
1
;
i
<
size
;
i
++)
{
if
(!
v
.
equals
(
ordered
.
get
(
i
)[
offset
]))
{
...
...
@@ -160,14 +160,13 @@ public abstract class AbstractAggregate extends DataAnalysisOperation {
}
private
void
aggregateFastPartition
(
Session
session
,
HashMap
<
Integer
,
Value
>
result
,
ArrayList
<
Value
[]>
ordered
,
int
frameParametersOffset
,
int
rowIdColumn
,
boolean
grouped
)
{
int
rowIdColumn
,
boolean
grouped
)
{
Object
aggregateData
=
createAggregateData
();
int
size
=
ordered
.
size
();
int
lastIncludedRow
=
-
1
;
Value
r
=
null
;
for
(
int
i
=
0
;
i
<
size
;)
{
int
newLast
=
WindowFrame
.
getEndIndex
(
over
,
session
,
ordered
,
frameParametersOffset
,
getOverOrderBySort
(),
i
);
int
newLast
=
WindowFrame
.
getEndIndex
(
over
,
session
,
ordered
,
getOverOrderBySort
(),
i
);
assert
newLast
>=
lastIncludedRow
;
if
(
newLast
>
lastIncludedRow
)
{
for
(
int
j
=
lastIncludedRow
+
1
;
j
<=
newLast
;
j
++)
{
...
...
@@ -183,13 +182,12 @@ public abstract class AbstractAggregate extends DataAnalysisOperation {
}
private
void
aggregateFastPartitionInReverse
(
Session
session
,
HashMap
<
Integer
,
Value
>
result
,
ArrayList
<
Value
[]>
ordered
,
int
frameParametersOffset
,
int
rowIdColumn
,
boolean
grouped
)
{
ArrayList
<
Value
[]>
ordered
,
int
rowIdColumn
,
boolean
grouped
)
{
Object
aggregateData
=
createAggregateData
();
int
firstIncludedRow
=
ordered
.
size
();
Value
r
=
null
;
for
(
int
i
=
firstIncludedRow
-
1
;
i
>=
0
;)
{
int
newLast
=
over
.
getWindowFrame
().
getStartIndex
(
session
,
ordered
,
frameParametersOffset
,
getOverOrderBySort
(),
i
);
int
newLast
=
over
.
getWindowFrame
().
getStartIndex
(
session
,
ordered
,
getOverOrderBySort
(),
i
);
assert
newLast
<=
firstIncludedRow
;
if
(
newLast
<
firstIncludedRow
)
{
for
(
int
j
=
firstIncludedRow
-
1
;
j
>=
newLast
;
j
--)
{
...
...
h2/src/main/org/h2/expression/analysis/DataAnalysisOperation.java
浏览文件 @
b3f9834d
...
...
@@ -161,12 +161,19 @@ public abstract class DataAnalysisOperation extends Expression {
}
WindowFrame
frame
=
over
.
getWindowFrame
();
if
(
frame
!=
null
)
{
int
index
=
getNumExpressions
();
if
(
orderBy
!=
null
)
{
index
+=
orderBy
.
size
();
}
int
n
=
0
;
if
(
frame
.
getStarting
().
isVariable
())
{
WindowFrameBound
bound
=
frame
.
getStarting
();
if
(
bound
.
isVariable
())
{
bound
.
setExpressionIndex
(
index
);
n
++;
}
WindowFrameBound
following
=
frame
.
getFollowing
();
if
(
following
!=
null
&&
following
.
isVariable
())
{
bound
=
frame
.
getFollowing
();
if
(
bound
!=
null
&&
bound
.
isVariable
())
{
bound
.
setExpressionIndex
(
index
+
n
);
n
++;
}
numFrameExpressions
=
n
;
...
...
@@ -358,20 +365,6 @@ public abstract class DataAnalysisOperation extends Expression {
:
getWindowResult
(
session
,
groupData
);
}
/**
* Returns offset of window frame parameters.
*
* @return offset of window frame parameters
*/
protected
final
int
getWindowFrameParametersOffset
()
{
int
frameParametersOffset
=
getNumExpressions
();
ArrayList
<
SelectOrderBy
>
orderBy
=
over
.
getOrderBy
();
if
(
orderBy
!=
null
)
{
frameParametersOffset
+=
orderBy
.
size
();
}
return
frameParametersOffset
;
}
/**
* Returns result of this window function or window aggregate. This method
* is not used for plain aggregates.
...
...
h2/src/main/org/h2/expression/analysis/WindowFrame.java
浏览文件 @
b3f9834d
差异被折叠。
点击展开。
h2/src/main/org/h2/expression/analysis/WindowFrameBound.java
浏览文件 @
b3f9834d
...
...
@@ -20,6 +20,8 @@ public class WindowFrameBound {
private
boolean
isVariable
;
private
int
expressionIndex
=
-
1
;
/**
* Creates new instance of window frame bound.
*
...
...
@@ -65,6 +67,25 @@ public class WindowFrameBound {
return
isVariable
;
}
/**
* Returns the index of preserved expression.
*
* @return the index of preserved expression, or -1
*/
public
int
getExpressionIndex
()
{
return
expressionIndex
;
}
/**
* Sets the index of preserved expression.
*
* @param expressionIndex
* the index to set
*/
void
setExpressionIndex
(
int
expressionIndex
)
{
this
.
expressionIndex
=
expressionIndex
;
}
/**
* Map the columns of the resolver to expression columns.
*
...
...
h2/src/main/org/h2/expression/analysis/WindowFunction.java
浏览文件 @
b3f9834d
...
...
@@ -349,19 +349,18 @@ public class WindowFunction extends DataAnalysisOperation {
private
void
getNth
(
Session
session
,
HashMap
<
Integer
,
Value
>
result
,
ArrayList
<
Value
[]>
ordered
,
int
rowIdColumn
)
{
int
size
=
ordered
.
size
();
int
frameParametersOffset
=
getWindowFrameParametersOffset
();
for
(
int
i
=
0
;
i
<
size
;
i
++)
{
Value
[]
row
=
ordered
.
get
(
i
);
int
rowId
=
row
[
rowIdColumn
].
getInt
();
Value
v
;
switch
(
type
)
{
case
FIRST_VALUE:
v
=
getNthValue
(
WindowFrame
.
iterator
(
over
,
session
,
ordered
,
getOverOrderBySort
(),
frameParametersOffset
,
i
,
false
),
0
,
ignoreNulls
);
v
=
getNthValue
(
WindowFrame
.
iterator
(
over
,
session
,
ordered
,
getOverOrderBySort
(),
i
,
false
),
0
,
ignoreNulls
);
break
;
case
LAST_VALUE:
v
=
getNthValue
(
WindowFrame
.
iterator
(
over
,
session
,
ordered
,
getOverOrderBySort
(),
frameParametersOffset
,
i
,
true
),
0
,
ignoreNulls
);
v
=
getNthValue
(
WindowFrame
.
iterator
(
over
,
session
,
ordered
,
getOverOrderBySort
(),
i
,
true
),
0
,
ignoreNulls
);
break
;
case
NTH_VALUE:
{
int
n
=
row
[
1
].
getInt
();
...
...
@@ -369,8 +368,8 @@ public class WindowFunction extends DataAnalysisOperation {
throw
DbException
.
getInvalidValueException
(
"nth row"
,
n
);
}
n
--;
Iterator
<
Value
[]>
iter
=
WindowFrame
.
iterator
(
over
,
session
,
ordered
,
getOverOrderBySort
(),
fr
ameParametersOffset
,
i
,
fr
omLast
);
Iterator
<
Value
[]>
iter
=
WindowFrame
.
iterator
(
over
,
session
,
ordered
,
getOverOrderBySort
(),
i
,
fromLast
);
v
=
getNthValue
(
iter
,
n
,
ignoreNulls
);
break
;
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论