Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
24108bee
Unverified
提交
24108bee
authored
12月 17, 2018
作者:
Evgenij Ryazanov
提交者:
GitHub
12月 17, 2018
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #1601 from katzyn/rownum
Return BIGINT from ROWNUM(), ROW_NUMBER() and rank functions
上级
69bae116
2d3e243e
隐藏空白字符变更
内嵌
并排
正在显示
10 个修改的文件
包含
53 行增加
和
30 行删除
+53
-30
help.csv
h2/src/docsrc/help/help.csv
+3
-3
changelog.html
h2/src/docsrc/html/changelog.html
+10
-0
Prepared.java
h2/src/main/org/h2/command/Prepared.java
+7
-4
Insert.java
h2/src/main/org/h2/command/dml/Insert.java
+1
-1
Select.java
h2/src/main/org/h2/command/dml/Select.java
+3
-3
Rownum.java
h2/src/main/org/h2/expression/Rownum.java
+5
-5
WindowFunction.java
h2/src/main/org/h2/expression/analysis/WindowFunction.java
+12
-12
TableFunction.java
h2/src/main/org/h2/expression/function/TableFunction.java
+2
-1
ntile.sql
h2/src/test/org/h2/test/scripts/functions/window/ntile.sql
+9
-0
dictionary.txt
h2/src/tools/org/h2/build/doc/dictionary.txt
+1
-1
没有找到文件。
h2/src/docsrc/help/help.csv
浏览文件 @
24108bee
...
...
@@ -5139,7 +5139,7 @@ READONLY()
ROWNUM()
","
Returns the number of the current row.
This method returns a
n integer
value.
This method returns a
long
value.
It is supported for SELECT statements, as well as for DELETE and UPDATE.
The first row has the row number 1, and is calculated before ordering and grouping the result set,
but after evaluating index conditions (even when the index conditions are specified in an outer query).
...
...
@@ -5335,10 +5335,10 @@ SELECT CUME_DIST() OVER (PARTITION BY CATEGORY ORDER BY ID), * FROM TEST;
"
"Functions (Window)","NTILE","
NTILE(
int
) OVER windowNameOrSpecification
NTILE(
long
) OVER windowNameOrSpecification
","
Distributes the rows into a specified number of groups.
Number of groups should be a positive
integer
value.
Number of groups should be a positive
long
value.
NTILE returns the 1-based number of the group to which the current row belongs.
First groups will have more rows if number of rows is not divisible by number of groups.
For example, if 5 rows are distributed into 2 groups this function returns 1 for the first 3 row and 2 for the last 2 rows.
...
...
h2/src/docsrc/html/changelog.html
浏览文件 @
24108bee
...
...
@@ -21,6 +21,16 @@ Change Log
<h2>
Next Version (unreleased)
</h2>
<ul>
<li>
PR #1601: Return BIGINT from ROWNUM(), ROW_NUMBER() and rank functions
</li>
<li>
PR #1599: cleanup StringUtils.cache
</li>
<li>
PR #1598: Minor changes in parser and documentation
</li>
<li>
PR #1597: Remove SysProperties.CHECK preconditions around simple assertions
</li>
<li>
PR #1596: Improve SQL Standard compliance in LOB precision parsing
</li>
<li>
Issue #1594: DBSettings.optimizeIsNull and dead code in IndexCursor.getMax()
</li>
<li>
PR #1591: Use multi-catch java 7 language construction to simplify code
...
...
h2/src/main/org/h2/command/Prepared.java
浏览文件 @
24108bee
...
...
@@ -17,6 +17,7 @@ import org.h2.message.DbException;
import
org.h2.message.Trace
;
import
org.h2.result.ResultInterface
;
import
org.h2.table.TableView
;
import
org.h2.util.MathUtils
;
import
org.h2.util.StatementBuilder
;
import
org.h2.value.Value
;
...
...
@@ -60,7 +61,7 @@ public abstract class Prepared {
* already read, {@code >0} if object is stored and its id is not yet read.
*/
private
int
persistedObjectId
;
private
int
currentRowNumber
;
private
long
currentRowNumber
;
private
int
rowScanCount
;
/**
* Common table expressions (CTE) in queries require us to create temporary views,
...
...
@@ -356,7 +357,7 @@ public abstract class Prepared {
*
* @param rowNumber the row number
*/
public
void
setCurrentRowNumber
(
int
rowNumber
)
{
public
void
setCurrentRowNumber
(
long
rowNumber
)
{
if
((++
rowScanCount
&
127
)
==
0
)
{
checkCanceled
();
}
...
...
@@ -369,7 +370,7 @@ public abstract class Prepared {
*
* @return the row number
*/
public
int
getCurrentRowNumber
()
{
public
long
getCurrentRowNumber
()
{
return
currentRowNumber
;
}
...
...
@@ -380,7 +381,9 @@ public abstract class Prepared {
if
((
currentRowNumber
&
127
)
==
0
)
{
session
.
getDatabase
().
setProgress
(
DatabaseEventListener
.
STATE_STATEMENT_PROGRESS
,
sqlStatement
,
currentRowNumber
,
0
);
sqlStatement
,
// TODO update interface
MathUtils
.
convertLongToInt
(
currentRowNumber
),
0
);
}
}
...
...
h2/src/main/org/h2/command/dml/Insert.java
浏览文件 @
24108bee
...
...
@@ -400,7 +400,7 @@ public class Insert extends Prepared implements ResultTarget {
ArrayList
<
String
>
variableNames
=
new
ArrayList
<>(
duplicateKeyAssignmentMap
.
size
());
Expression
[]
row
=
(
currentRow
==
null
)
?
list
.
get
(
getCurrentRowNumber
()
-
1
)
Expression
[]
row
=
(
currentRow
==
null
)
?
list
.
get
(
(
int
)
getCurrentRowNumber
()
-
1
)
:
new
Expression
[
columns
.
length
];
for
(
int
i
=
0
;
i
<
columns
.
length
;
i
++)
{
String
key
=
table
.
getSchema
().
getName
()
+
"."
+
...
...
h2/src/main/org/h2/command/dml/Select.java
浏览文件 @
24108bee
...
...
@@ -438,7 +438,7 @@ public class Select extends Query {
}
private
void
gatherGroup
(
int
columnCount
,
int
stage
)
{
int
rowNumber
=
0
;
long
rowNumber
=
0
;
setCurrentRowNumber
(
0
);
int
sampleSize
=
getSampleSizeValue
(
session
);
ArrayList
<
Row
>[]
forUpdateRows
=
initForUpdateRows
();
...
...
@@ -583,7 +583,7 @@ public class Select extends Query {
limitRows
=
Long
.
MAX_VALUE
;
}
}
int
rowNumber
=
0
;
long
rowNumber
=
0
;
setCurrentRowNumber
(
0
);
Index
index
=
topTableFilter
.
getIndex
();
SearchRow
first
=
null
;
...
...
@@ -1665,7 +1665,7 @@ public class Select extends Query {
*/
private
abstract
class
LazyResultSelect
extends
LazyResult
{
int
rowNumber
;
long
rowNumber
;
int
columnCount
;
LazyResultSelect
(
Expression
[]
expressions
,
int
columnCount
)
{
...
...
h2/src/main/org/h2/expression/Rownum.java
浏览文件 @
24108bee
...
...
@@ -11,7 +11,7 @@ import org.h2.message.DbException;
import
org.h2.table.ColumnResolver
;
import
org.h2.table.TableFilter
;
import
org.h2.value.Value
;
import
org.h2.value.Value
Int
;
import
org.h2.value.Value
Long
;
/**
* Represents the ROWNUM function.
...
...
@@ -29,12 +29,12 @@ public class Rownum extends Expression {
@Override
public
Value
getValue
(
Session
session
)
{
return
Value
Int
.
get
(
prepared
.
getCurrentRowNumber
());
return
Value
Long
.
get
(
prepared
.
getCurrentRowNumber
());
}
@Override
public
int
getType
()
{
return
Value
.
INT
;
return
Value
.
LONG
;
}
@Override
...
...
@@ -59,12 +59,12 @@ public class Rownum extends Expression {
@Override
public
long
getPrecision
()
{
return
Value
Int
.
PRECISION
;
return
Value
Long
.
PRECISION
;
}
@Override
public
int
getDisplaySize
()
{
return
Value
Int
.
DISPLAY_SIZE
;
return
Value
Long
.
DISPLAY_SIZE
;
}
@Override
...
...
h2/src/main/org/h2/expression/analysis/WindowFunction.java
浏览文件 @
24108bee
...
...
@@ -18,7 +18,7 @@ import org.h2.table.ColumnResolver;
import
org.h2.table.TableFilter
;
import
org.h2.value.Value
;
import
org.h2.value.ValueDouble
;
import
org.h2.value.Value
Int
;
import
org.h2.value.Value
Long
;
import
org.h2.value.ValueNull
;
/**
...
...
@@ -184,7 +184,7 @@ public class WindowFunction extends DataAnalysisOperation {
switch
(
type
)
{
case
ROW_NUMBER:
for
(
int
i
=
0
,
size
=
ordered
.
size
();
i
<
size
;)
{
result
.
put
(
ordered
.
get
(
i
)[
rowIdColumn
].
getInt
(),
Value
Int
.
get
(++
i
));
result
.
put
(
ordered
.
get
(
i
)[
rowIdColumn
].
getInt
(),
Value
Long
.
get
(++
i
));
}
break
;
case
RANK:
...
...
@@ -231,7 +231,7 @@ public class WindowFunction extends DataAnalysisOperation {
int
nm
=
number
-
1
;
v
=
nm
==
0
?
ValueDouble
.
ZERO
:
ValueDouble
.
get
((
double
)
nm
/
(
size
-
1
));
}
else
{
v
=
Value
Int
.
get
(
number
);
v
=
Value
Long
.
get
(
number
);
}
result
.
put
(
row
[
rowIdColumn
].
getInt
(),
v
);
}
...
...
@@ -260,20 +260,20 @@ public class WindowFunction extends DataAnalysisOperation {
int
size
=
orderedData
.
size
();
for
(
int
i
=
0
;
i
<
size
;
i
++)
{
Value
[]
array
=
orderedData
.
get
(
i
);
int
buckets
=
array
[
0
].
getInt
();
long
buckets
=
array
[
0
].
getLong
();
if
(
buckets
<=
0
)
{
throw
DbException
.
getInvalidValueException
(
"number of tiles"
,
buckets
);
}
int
perTile
=
size
/
buckets
;
int
numLarger
=
size
-
perTile
*
buckets
;
int
largerGroup
=
numLarger
*
(
perTile
+
1
);
int
v
;
long
perTile
=
size
/
buckets
;
long
numLarger
=
size
-
perTile
*
buckets
;
long
largerGroup
=
numLarger
*
(
perTile
+
1
);
long
v
;
if
(
i
>=
largerGroup
)
{
v
=
(
i
-
largerGroup
)
/
perTile
+
numLarger
+
1
;
}
else
{
v
=
i
/
(
perTile
+
1
)
+
1
;
}
result
.
put
(
orderedData
.
get
(
i
)[
last
].
getInt
(),
Value
Int
.
get
(
v
));
result
.
put
(
orderedData
.
get
(
i
)[
last
].
getInt
(),
Value
Long
.
get
(
v
));
}
}
...
...
@@ -441,7 +441,7 @@ public class WindowFunction extends DataAnalysisOperation {
case
RANK:
case
DENSE_RANK:
case
NTILE:
return
Value
.
INT
;
return
Value
.
LONG
;
case
PERCENT_RANK:
case
CUME_DIST:
return
Value
.
DOUBLE
;
...
...
@@ -477,7 +477,7 @@ public class WindowFunction extends DataAnalysisOperation {
case
RANK:
case
DENSE_RANK:
case
NTILE:
return
Value
Int
.
PRECISION
;
return
Value
Long
.
PRECISION
;
case
PERCENT_RANK:
case
CUME_DIST:
return
ValueDouble
.
PRECISION
;
...
...
@@ -499,7 +499,7 @@ public class WindowFunction extends DataAnalysisOperation {
case
RANK:
case
DENSE_RANK:
case
NTILE:
return
Value
Int
.
DISPLAY_SIZE
;
return
Value
Long
.
DISPLAY_SIZE
;
case
PERCENT_RANK:
case
CUME_DIST:
return
ValueDouble
.
DISPLAY_SIZE
;
...
...
h2/src/main/org/h2/expression/function/TableFunction.java
浏览文件 @
24108bee
...
...
@@ -22,7 +22,8 @@ import org.h2.value.ValueNull;
import
org.h2.value.ValueResultSet
;
/**
* Implementation of the functions TABLE(..) and TABLE_DISTINCT(..).
* Implementation of the functions TABLE(..), TABLE_DISTINCT(..), and
* UNNEST(..).
*/
public
class
TableFunction
extends
Function
{
private
final
long
rowCount
;
...
...
h2/src/test/org/h2/test/scripts/functions/window/ntile.sql
浏览文件 @
24108bee
...
...
@@ -118,3 +118,12 @@ SELECT NTILE(X) OVER () FROM (SELECT * FROM SYSTEM_RANGE(1, 1));
SELECT
NTILE
(
X
)
OVER
(
ORDER
BY
X
RANGE
CURRENT
ROW
)
FROM
(
SELECT
*
FROM
SYSTEM_RANGE
(
1
,
1
));
>
exception
SYNTAX_ERROR_1
SELECT
NTILE
(
100000000000
)
OVER
(
ORDER
BY
X
)
FROM
(
SELECT
*
FROM
SYSTEM_RANGE
(
1
,
4
));
>
NTILE
(
100000000000
)
OVER
(
ORDER
BY
X
)
>
-------------------------------------
>
1
>
2
>
3
>
4
>
rows
:
4
h2/src/tools/org/h2/build/doc/dictionary.txt
浏览文件 @
24108bee
...
...
@@ -804,4 +804,4 @@ qualification opportunity jumping exploited unacceptable vrs duplicated
queryparser tokenized freeze factorings recompilation unenclosed rfe dsync
econd irst bcef ordinality nord unnest
analyst occupation distributive josaph aor engineer sajeewa isuru randil kevin doctor businessman artist ashan
corrupts splitted disruption unintentional octets
corrupts splitted disruption unintentional octets
preconditions
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论