Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
5a5a4050
Unverified
提交
5a5a4050
authored
2月 06, 2019
作者:
Evgenij Ryazanov
提交者:
GitHub
2月 06, 2019
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #1725 from katzyn/aggregate
Add partial implementation of standard LISTAGG aggregate function
上级
664f3bb9
9e2994a8
显示空白字符变更
内嵌
并排
正在显示
9 个修改的文件
包含
214 行增加
和
77 行删除
+214
-77
help.csv
h2/src/docsrc/help/help.csv
+20
-14
Parser.java
h2/src/main/org/h2/command/Parser.java
+28
-12
Aggregate.java
h2/src/main/org/h2/expression/aggregate/Aggregate.java
+24
-33
AggregateData.java
h2/src/main/org/h2/expression/aggregate/AggregateData.java
+1
-1
AggregateType.java
h2/src/main/org/h2/expression/aggregate/AggregateType.java
+5
-5
TestScript.java
h2/src/test/org/h2/test/scripts/TestScript.java
+1
-1
listagg.sql
.../test/org/h2/test/scripts/functions/aggregate/listagg.sql
+124
-0
testScript.sql
h2/src/test/org/h2/test/scripts/testScript.sql
+10
-10
dictionary.txt
h2/src/tools/org/h2/build/doc/dictionary.txt
+1
-1
没有找到文件。
h2/src/docsrc/help/help.csv
浏览文件 @
5a5a4050
...
@@ -2671,6 +2671,14 @@ columns with the same name.
...
@@ -2671,6 +2671,14 @@ columns with the same name.
TEST AS T LEFT JOIN TEST AS T1 ON T.ID = T1.ID
TEST AS T LEFT JOIN TEST AS T1 ON T.ID = T1.ID
"
"
"Other Grammar","Within group specification","
WITHIN GROUP (ORDER BY {expression [ASC|DESC]} [,...])
","
Group specification for ordered set functions.
","
WITHIN GROUP (ORDER BY ID DESC)
"
"Other Grammar","Wildcard expression","
"Other Grammar","Wildcard expression","
{* | tableAlias.*} [EXCEPT ([tableAlias.]columnName, [,...])]
{* | tableAlias.*} [EXCEPT ([tableAlias.]columnName, [,...])]
","
","
...
@@ -3582,10 +3590,12 @@ Aggregates are only allowed in select statements.
...
@@ -3582,10 +3590,12 @@ Aggregates are only allowed in select statements.
COUNT(*)
COUNT(*)
"
"
"Functions (Aggregate)","GROUP_CONCAT","
"Functions (Aggregate)","LISTAGG","
GROUP_CONCAT ( [ DISTINCT|ALL ] string
{ LISTAGG ( [ DISTINCT|ALL ] string [, separatorString] [ ON OVERFLOW ERROR ] )
[ ORDER BY { expression [ ASC | DESC ] } [,...] ]
withinGroupSpecification }
[ SEPARATOR expression ] )
| { GROUP_CONCAT ( [ DISTINCT|ALL ] string
[ ORDER BY { expression [ ASC | DESC ] } [,...] ]
[ SEPARATOR separatorString ] ) }
[FILTER (WHERE expression)] [OVER windowNameOrSpecification]
[FILTER (WHERE expression)] [OVER windowNameOrSpecification]
","
","
Concatenates strings with a separator.
Concatenates strings with a separator.
...
@@ -3593,14 +3603,10 @@ Separator must be the same for all rows in the same group.
...
@@ -3593,14 +3603,10 @@ Separator must be the same for all rows in the same group.
The default separator is a ',' (without space).
The default separator is a ',' (without space).
This method returns a string.
This method returns a string.
If no rows are selected, the result is NULL.
If no rows are selected, the result is NULL.
If ORDER BY is not specified order of strings is not determined.
When this aggregate is used with OVER clause that contains ORDER BY subclause
it does not enforce exact order of strings.
This aggregate needs additional own ORDER BY clause to make it deterministic.
Aggregates are only allowed in select statements.
Aggregates are only allowed in select statements.
","
","
GROUP_CONCAT(NAME ORDER BY ID SEPARATOR ', '
)
LISTAGG(NAME, ', ') WITHIN GROUP (ORDER BY ID
)
GROUP_CONCAT(ID ORDER BY ID SEPARATOR ', '
) OVER (ORDER BY ID)
LISTAGG(ID, ', ') WITHIN GROUP (ORDER BY ID
) OVER (ORDER BY ID)
"
"
"Functions (Aggregate)","ARRAY_AGG","
"Functions (Aggregate)","ARRAY_AGG","
...
@@ -3721,7 +3727,7 @@ VAR_SAMP(X)
...
@@ -3721,7 +3727,7 @@ VAR_SAMP(X)
"Functions (Aggregate)","RANK aggregate","
"Functions (Aggregate)","RANK aggregate","
RANK(value [,...])
RANK(value [,...])
WITHIN GROUP (ORDER BY {expression [ASC|DESC]} [,...])
withinGroupSpecification
[FILTER (WHERE expression)] [OVER windowNameOrSpecification]
[FILTER (WHERE expression)] [OVER windowNameOrSpecification]
","
","
Returns the rank of the hypothetical row in specified collection of rows.
Returns the rank of the hypothetical row in specified collection of rows.
...
@@ -3734,7 +3740,7 @@ SELECT RANK(5) WITHIN GROUP (ORDER BY V) FROM TEST;
...
@@ -3734,7 +3740,7 @@ SELECT RANK(5) WITHIN GROUP (ORDER BY V) FROM TEST;
"Functions (Aggregate)","DENSE_RANK aggregate","
"Functions (Aggregate)","DENSE_RANK aggregate","
DENSE_RANK(value [,...])
DENSE_RANK(value [,...])
WITHIN GROUP (ORDER BY {expression [ASC|DESC]} [,...])
withinGroupSpecification
[FILTER (WHERE expression)] [OVER windowNameOrSpecification]
[FILTER (WHERE expression)] [OVER windowNameOrSpecification]
","
","
Returns the dense rank of the hypothetical row in specified collection of rows.
Returns the dense rank of the hypothetical row in specified collection of rows.
...
@@ -3747,7 +3753,7 @@ SELECT DENSE_RANK(5) WITHIN GROUP (ORDER BY V) FROM TEST;
...
@@ -3747,7 +3753,7 @@ SELECT DENSE_RANK(5) WITHIN GROUP (ORDER BY V) FROM TEST;
"Functions (Aggregate)","PERCENT_RANK aggregate","
"Functions (Aggregate)","PERCENT_RANK aggregate","
PERCENT_RANK(value [,...])
PERCENT_RANK(value [,...])
WITHIN GROUP (ORDER BY {expression [ASC|DESC]} [,...])
withinGroupSpecification
[FILTER (WHERE expression)] [OVER windowNameOrSpecification]
[FILTER (WHERE expression)] [OVER windowNameOrSpecification]
","
","
Returns the relative rank of the hypothetical row in specified collection of rows.
Returns the relative rank of the hypothetical row in specified collection of rows.
...
@@ -3759,7 +3765,7 @@ SELECT PERCENT_RANK(5) WITHIN GROUP (ORDER BY V) FROM TEST;
...
@@ -3759,7 +3765,7 @@ SELECT PERCENT_RANK(5) WITHIN GROUP (ORDER BY V) FROM TEST;
"Functions (Aggregate)","CUME_DIST aggregate","
"Functions (Aggregate)","CUME_DIST aggregate","
CUME_DIST(value [,...])
CUME_DIST(value [,...])
WITHIN GROUP (ORDER BY {expression [ASC|DESC]} [,...])
withinGroupSpecification
[FILTER (WHERE expression)] [OVER windowNameOrSpecification]
[FILTER (WHERE expression)] [OVER windowNameOrSpecification]
","
","
Returns the relative rank of the hypothetical row in specified collection of rows.
Returns the relative rank of the hypothetical row in specified collection of rows.
...
...
h2/src/main/org/h2/command/Parser.java
浏览文件 @
5a5a4050
...
@@ -3060,7 +3060,7 @@ public class Parser {
...
@@ -3060,7 +3060,7 @@ public class Parser {
}
}
}
}
break
;
break
;
case
GROUP_CONCAT
:
{
case
LISTAGG
:
{
boolean
distinct
=
readDistinctAgg
();
boolean
distinct
=
readDistinctAgg
();
Expression
arg
=
readExpression
(),
separator
=
null
;
Expression
arg
=
readExpression
(),
separator
=
null
;
ArrayList
<
SelectOrderBy
>
orderByList
=
null
;
ArrayList
<
SelectOrderBy
>
orderByList
=
null
;
...
@@ -3072,7 +3072,7 @@ public class Parser {
...
@@ -3072,7 +3072,7 @@ public class Parser {
read
(
"BY"
);
read
(
"BY"
);
orderByList
=
parseSimpleOrderList
();
orderByList
=
parseSimpleOrderList
();
}
}
}
else
{
}
else
if
(
equalsToken
(
"GROUP_CONCAT"
,
aggregateName
))
{
if
(
readIf
(
ORDER
))
{
if
(
readIf
(
ORDER
))
{
read
(
"BY"
);
read
(
"BY"
);
orderByList
=
parseSimpleOrderList
();
orderByList
=
parseSimpleOrderList
();
...
@@ -3080,13 +3080,28 @@ public class Parser {
...
@@ -3080,13 +3080,28 @@ public class Parser {
if
(
readIf
(
"SEPARATOR"
))
{
if
(
readIf
(
"SEPARATOR"
))
{
separator
=
readExpression
();
separator
=
readExpression
();
}
}
}
else
{
if
(
readIf
(
COMMA
))
{
separator
=
readExpression
();
}
if
(
readIf
(
ON
))
{
read
(
"OVERFLOW"
);
read
(
"ERROR"
);
}
}
}
r
=
new
Aggregate
(
AggregateType
.
GROUP_CONCAT
,
Expression
[]
args
=
separator
==
null
?
new
Expression
[]
{
arg
}
:
new
Expression
[]
{
arg
,
separator
};
separator
==
null
?
new
Expression
[]
{
arg
}
:
new
Expression
[]
{
arg
,
separator
},
int
index
=
lastParseIndex
;
currentSelect
,
distinct
);
read
(
CLOSE_PAREN
);
if
(
orderByList
==
null
&&
isToken
(
"WITHIN"
))
{
r
=
readWithinGroup
(
aggregateType
,
args
,
distinct
,
false
);
}
else
{
parseIndex
=
index
;
read
();
r
=
new
Aggregate
(
AggregateType
.
LISTAGG
,
args
,
currentSelect
,
distinct
);
if
(
orderByList
!=
null
)
{
if
(
orderByList
!=
null
)
{
r
.
setOrderByList
(
orderByList
);
r
.
setOrderByList
(
orderByList
);
}
}
}
break
;
break
;
}
}
case
ARRAY_AGG:
{
case
ARRAY_AGG:
{
...
@@ -3109,19 +3124,19 @@ public class Parser {
...
@@ -3109,19 +3124,19 @@ public class Parser {
do
{
do
{
expressions
.
add
(
readExpression
());
expressions
.
add
(
readExpression
());
}
while
(
readIfMore
(
true
));
}
while
(
readIfMore
(
true
));
r
=
readWithinGroup
(
aggregateType
,
expressions
.
toArray
(
new
Expression
[
0
]),
true
);
r
=
readWithinGroup
(
aggregateType
,
expressions
.
toArray
(
new
Expression
[
0
]),
false
,
true
);
break
;
break
;
}
}
case
PERCENTILE_CONT:
case
PERCENTILE_CONT:
case
PERCENTILE_DISC:
{
case
PERCENTILE_DISC:
{
Expression
num
=
readExpression
();
Expression
num
=
readExpression
();
read
(
CLOSE_PAREN
);
read
(
CLOSE_PAREN
);
r
=
readWithinGroup
(
aggregateType
,
new
Expression
[]
{
num
},
false
);
r
=
readWithinGroup
(
aggregateType
,
new
Expression
[]
{
num
},
false
,
false
);
break
;
break
;
}
}
case
MODE:
{
case
MODE:
{
if
(
readIf
(
CLOSE_PAREN
))
{
if
(
readIf
(
CLOSE_PAREN
))
{
r
=
readWithinGroup
(
AggregateType
.
MODE
,
new
Expression
[
0
],
false
);
r
=
readWithinGroup
(
AggregateType
.
MODE
,
new
Expression
[
0
],
false
,
false
);
}
else
{
}
else
{
Expression
expr
=
readExpression
();
Expression
expr
=
readExpression
();
r
=
new
Aggregate
(
aggregateType
,
new
Expression
[
0
],
currentSelect
,
false
);
r
=
new
Aggregate
(
aggregateType
,
new
Expression
[
0
],
currentSelect
,
false
);
...
@@ -3150,13 +3165,14 @@ public class Parser {
...
@@ -3150,13 +3165,14 @@ public class Parser {
return
r
;
return
r
;
}
}
private
Aggregate
readWithinGroup
(
AggregateType
aggregateType
,
Expression
[]
args
,
boolean
forHypotheticalSet
)
{
private
Aggregate
readWithinGroup
(
AggregateType
aggregateType
,
Expression
[]
args
,
boolean
distinct
,
boolean
forHypotheticalSet
)
{
read
(
"WITHIN"
);
read
(
"WITHIN"
);
read
(
GROUP
);
read
(
GROUP
);
read
(
OPEN_PAREN
);
read
(
OPEN_PAREN
);
read
(
ORDER
);
read
(
ORDER
);
read
(
"BY"
);
read
(
"BY"
);
Aggregate
r
=
new
Aggregate
(
aggregateType
,
args
,
currentSelect
,
false
);
Aggregate
r
=
new
Aggregate
(
aggregateType
,
args
,
currentSelect
,
distinct
);
if
(
forHypotheticalSet
)
{
if
(
forHypotheticalSet
)
{
int
count
=
args
.
length
;
int
count
=
args
.
length
;
ArrayList
<
SelectOrderBy
>
orderList
=
new
ArrayList
<>(
count
);
ArrayList
<
SelectOrderBy
>
orderList
=
new
ArrayList
<>(
count
);
...
...
h2/src/main/org/h2/expression/aggregate/Aggregate.java
浏览文件 @
5a5a4050
...
@@ -89,9 +89,11 @@ public class Aggregate extends AbstractAggregate {
...
@@ -89,9 +89,11 @@ public class Aggregate extends AbstractAggregate {
addAggregate
(
"MIN"
,
AggregateType
.
MIN
);
addAggregate
(
"MIN"
,
AggregateType
.
MIN
);
addAggregate
(
"MAX"
,
AggregateType
.
MAX
);
addAggregate
(
"MAX"
,
AggregateType
.
MAX
);
addAggregate
(
"AVG"
,
AggregateType
.
AVG
);
addAggregate
(
"AVG"
,
AggregateType
.
AVG
);
addAggregate
(
"GROUP_CONCAT"
,
AggregateType
.
GROUP_CONCAT
);
addAggregate
(
"LISTAGG"
,
AggregateType
.
LISTAGG
);
// MySQL compatibility: group_concat(expression, delimiter)
addAggregate
(
"GROUP_CONCAT"
,
AggregateType
.
LISTAGG
);
// PostgreSQL compatibility: string_agg(expression, delimiter)
// PostgreSQL compatibility: string_agg(expression, delimiter)
addAggregate
(
"STRING_AGG"
,
AggregateType
.
GROUP_CONCAT
);
addAggregate
(
"STRING_AGG"
,
AggregateType
.
LISTAGG
);
addAggregate
(
"STDDEV_SAMP"
,
AggregateType
.
STDDEV_SAMP
);
addAggregate
(
"STDDEV_SAMP"
,
AggregateType
.
STDDEV_SAMP
);
addAggregate
(
"STDDEV"
,
AggregateType
.
STDDEV_SAMP
);
addAggregate
(
"STDDEV"
,
AggregateType
.
STDDEV_SAMP
);
addAggregate
(
"STDDEV_POP"
,
AggregateType
.
STDDEV_POP
);
addAggregate
(
"STDDEV_POP"
,
AggregateType
.
STDDEV_POP
);
...
@@ -188,7 +190,7 @@ public class Aggregate extends AbstractAggregate {
...
@@ -188,7 +190,7 @@ public class Aggregate extends AbstractAggregate {
private
void
updateData
(
Session
session
,
AggregateData
data
,
Value
v
,
Value
[]
remembered
)
{
private
void
updateData
(
Session
session
,
AggregateData
data
,
Value
v
,
Value
[]
remembered
)
{
switch
(
aggregateType
)
{
switch
(
aggregateType
)
{
case
GROUP_CONCAT
:
case
LISTAGG
:
if
(
v
!=
ValueNull
.
INSTANCE
)
{
if
(
v
!=
ValueNull
.
INSTANCE
)
{
v
=
updateCollecting
(
session
,
v
.
convertTo
(
Value
.
STRING
),
remembered
);
v
=
updateCollecting
(
session
,
v
.
convertTo
(
Value
.
STRING
),
remembered
);
}
}
...
@@ -393,8 +395,8 @@ public class Aggregate extends AbstractAggregate {
...
@@ -393,8 +395,8 @@ public class Aggregate extends AbstractAggregate {
break
;
break
;
case
HISTOGRAM:
case
HISTOGRAM:
return
getHistogram
(
session
,
data
);
return
getHistogram
(
session
,
data
);
case
GROUP_CONCAT
:
case
LISTAGG
:
return
get
GroupConcat
(
session
,
data
);
return
get
Listagg
(
session
,
data
);
case
ARRAY_AGG:
{
case
ARRAY_AGG:
{
Value
[]
array
=
((
AggregateDataCollecting
)
data
).
getArray
();
Value
[]
array
=
((
AggregateDataCollecting
)
data
).
getArray
();
if
(
array
==
null
)
{
if
(
array
==
null
)
{
...
@@ -521,7 +523,7 @@ public class Aggregate extends AbstractAggregate {
...
@@ -521,7 +523,7 @@ public class Aggregate extends AbstractAggregate {
throw
DbException
.
throwInternalError
();
throw
DbException
.
throwInternalError
();
}
}
private
Value
get
GroupConcat
(
Session
session
,
AggregateData
data
)
{
private
Value
get
Listagg
(
Session
session
,
AggregateData
data
)
{
AggregateDataCollecting
collectingData
=
(
AggregateDataCollecting
)
data
;
AggregateDataCollecting
collectingData
=
(
AggregateDataCollecting
)
data
;
Value
[]
array
=
collectingData
.
getArray
();
Value
[]
array
=
collectingData
.
getArray
();
if
(
array
==
null
)
{
if
(
array
==
null
)
{
...
@@ -638,7 +640,7 @@ public class Aggregate extends AbstractAggregate {
...
@@ -638,7 +640,7 @@ public class Aggregate extends AbstractAggregate {
int
offset
;
int
offset
;
switch
(
aggregateType
)
{
switch
(
aggregateType
)
{
case
ARRAY_AGG:
case
ARRAY_AGG:
case
GROUP_CONCAT
:
case
LISTAGG
:
offset
=
1
;
offset
=
1
;
break
;
break
;
default
:
default
:
...
@@ -647,7 +649,7 @@ public class Aggregate extends AbstractAggregate {
...
@@ -647,7 +649,7 @@ public class Aggregate extends AbstractAggregate {
orderBySort
=
createOrder
(
session
,
orderByList
,
offset
);
orderBySort
=
createOrder
(
session
,
orderByList
,
offset
);
}
}
switch
(
aggregateType
)
{
switch
(
aggregateType
)
{
case
GROUP_CONCAT
:
case
LISTAGG
:
type
=
TypeInfo
.
TYPE_STRING
;
type
=
TypeInfo
.
TYPE_STRING
;
break
;
break
;
case
COUNT_ALL:
case
COUNT_ALL:
...
@@ -746,21 +748,6 @@ public class Aggregate extends AbstractAggregate {
...
@@ -746,21 +748,6 @@ public class Aggregate extends AbstractAggregate {
super
.
setEvaluatable
(
tableFilter
,
b
);
super
.
setEvaluatable
(
tableFilter
,
b
);
}
}
private
StringBuilder
getSQLGroupConcat
(
StringBuilder
builder
)
{
builder
.
append
(
"GROUP_CONCAT("
);
if
(
distinct
)
{
builder
.
append
(
"DISTINCT "
);
}
args
[
0
].
getSQL
(
builder
);
Window
.
appendOrderBy
(
builder
,
orderByList
);
if
(
args
.
length
>=
2
)
{
builder
.
append
(
" SEPARATOR "
);
args
[
1
].
getSQL
(
builder
);
}
builder
.
append
(
')'
);
return
appendTailConditions
(
builder
);
}
private
StringBuilder
getSQLArrayAggregate
(
StringBuilder
builder
)
{
private
StringBuilder
getSQLArrayAggregate
(
StringBuilder
builder
)
{
builder
.
append
(
"ARRAY_AGG("
);
builder
.
append
(
"ARRAY_AGG("
);
if
(
distinct
)
{
if
(
distinct
)
{
...
@@ -776,8 +763,6 @@ public class Aggregate extends AbstractAggregate {
...
@@ -776,8 +763,6 @@ public class Aggregate extends AbstractAggregate {
public
StringBuilder
getSQL
(
StringBuilder
builder
)
{
public
StringBuilder
getSQL
(
StringBuilder
builder
)
{
String
text
;
String
text
;
switch
(
aggregateType
)
{
switch
(
aggregateType
)
{
case
GROUP_CONCAT:
return
getSQLGroupConcat
(
builder
);
case
COUNT_ALL:
case
COUNT_ALL:
return
appendTailConditions
(
builder
.
append
(
"COUNT(*)"
));
return
appendTailConditions
(
builder
.
append
(
"COUNT(*)"
));
case
COUNT:
case
COUNT:
...
@@ -846,6 +831,9 @@ public class Aggregate extends AbstractAggregate {
...
@@ -846,6 +831,9 @@ public class Aggregate extends AbstractAggregate {
case
MEDIAN:
case
MEDIAN:
text
=
"MEDIAN"
;
text
=
"MEDIAN"
;
break
;
break
;
case
LISTAGG:
text
=
"LISTAGG"
;
break
;
case
ARRAY_AGG:
case
ARRAY_AGG:
return
getSQLArrayAggregate
(
builder
);
return
getSQLArrayAggregate
(
builder
);
case
MODE:
case
MODE:
...
@@ -860,10 +848,14 @@ public class Aggregate extends AbstractAggregate {
...
@@ -860,10 +848,14 @@ public class Aggregate extends AbstractAggregate {
builder
.
append
(
text
);
builder
.
append
(
text
);
if
(
distinct
)
{
if
(
distinct
)
{
builder
.
append
(
"(DISTINCT "
);
builder
.
append
(
"(DISTINCT "
);
args
[
0
].
getSQL
(
builder
).
append
(
')'
);
}
else
{
}
else
{
builder
.
append
(
'('
);
builder
.
append
(
'('
);
for
(
Expression
arg
:
args
)
{
}
for
(
int
i
=
0
;
i
<
args
.
length
;
i
++)
{
if
(
i
>
0
)
{
builder
.
append
(
", "
);
}
Expression
arg
=
args
[
i
];
if
(
arg
instanceof
Subquery
)
{
if
(
arg
instanceof
Subquery
)
{
arg
.
getSQL
(
builder
);
arg
.
getSQL
(
builder
);
}
else
{
}
else
{
...
@@ -871,7 +863,6 @@ public class Aggregate extends AbstractAggregate {
...
@@ -871,7 +863,6 @@ public class Aggregate extends AbstractAggregate {
}
}
}
}
builder
.
append
(
')'
);
builder
.
append
(
')'
);
}
if
(
orderByList
!=
null
)
{
if
(
orderByList
!=
null
)
{
builder
.
append
(
" WITHIN GROUP ("
);
builder
.
append
(
" WITHIN GROUP ("
);
Window
.
appendOrderBy
(
builder
,
orderByList
);
Window
.
appendOrderBy
(
builder
,
orderByList
);
...
...
h2/src/main/org/h2/expression/aggregate/AggregateData.java
浏览文件 @
5a5a4050
...
@@ -32,7 +32,7 @@ abstract class AggregateData {
...
@@ -32,7 +32,7 @@ abstract class AggregateData {
return
new
AggregateDataCount
(
false
);
return
new
AggregateDataCount
(
false
);
}
}
break
;
break
;
case
GROUP_CONCAT
:
case
LISTAGG
:
case
ARRAY_AGG:
case
ARRAY_AGG:
case
RANK:
case
RANK:
case
DENSE_RANK:
case
DENSE_RANK:
...
...
h2/src/main/org/h2/expression/aggregate/AggregateType.java
浏览文件 @
5a5a4050
...
@@ -20,11 +20,6 @@ public enum AggregateType {
...
@@ -20,11 +20,6 @@ public enum AggregateType {
*/
*/
COUNT
,
COUNT
,
/**
* The aggregate type for GROUP_CONCAT(...).
*/
GROUP_CONCAT
,
/**
/**
* The aggregate type for SUM(expression).
* The aggregate type for SUM(expression).
*/
*/
...
@@ -130,6 +125,11 @@ public enum AggregateType {
...
@@ -130,6 +125,11 @@ public enum AggregateType {
*/
*/
MEDIAN
,
MEDIAN
,
/**
* The aggregate type for LISTAGG(...).
*/
LISTAGG
,
/**
/**
* The aggregate type for ARRAY_AGG(expression).
* The aggregate type for ARRAY_AGG(expression).
*/
*/
...
...
h2/src/test/org/h2/test/scripts/TestScript.java
浏览文件 @
5a5a4050
...
@@ -165,7 +165,7 @@ public class TestScript extends TestDb {
...
@@ -165,7 +165,7 @@ public class TestScript extends TestDb {
testScript
(
"other/"
+
s
+
".sql"
);
testScript
(
"other/"
+
s
+
".sql"
);
}
}
for
(
String
s
:
new
String
[]
{
"any"
,
"array-agg"
,
"avg"
,
"bit-and"
,
"bit-or"
,
"count"
,
"envelope"
,
for
(
String
s
:
new
String
[]
{
"any"
,
"array-agg"
,
"avg"
,
"bit-and"
,
"bit-or"
,
"count"
,
"envelope"
,
"every"
,
"
group-concat"
,
"histogram
"
,
"max"
,
"min"
,
"mode"
,
"percentile"
,
"rank"
,
"selectivity"
,
"every"
,
"
histogram"
,
"listagg
"
,
"max"
,
"min"
,
"mode"
,
"percentile"
,
"rank"
,
"selectivity"
,
"stddev-pop"
,
"stddev-samp"
,
"sum"
,
"var-pop"
,
"var-samp"
})
{
"stddev-pop"
,
"stddev-samp"
,
"sum"
,
"var-pop"
,
"var-samp"
})
{
testScript
(
"functions/aggregate/"
+
s
+
".sql"
);
testScript
(
"functions/aggregate/"
+
s
+
".sql"
);
}
}
...
...
h2/src/test/org/h2/test/scripts/functions/aggregate/
group-concat
.sql
→
h2/src/test/org/h2/test/scripts/functions/aggregate/
listagg
.sql
浏览文件 @
5a5a4050
...
@@ -11,11 +11,19 @@ create table test(v varchar);
...
@@ -11,11 +11,19 @@ create table test(v varchar);
insert
into
test
values
(
'1'
),
(
'2'
),
(
'3'
),
(
'4'
),
(
'5'
),
(
'6'
),
(
'7'
),
(
'8'
),
(
'9'
);
insert
into
test
values
(
'1'
),
(
'2'
),
(
'3'
),
(
'4'
),
(
'5'
),
(
'6'
),
(
'7'
),
(
'8'
),
(
'9'
);
>
update
count
:
9
>
update
count
:
9
select
listagg
(
v
,
'-'
)
within
group
(
order
by
v
asc
),
listagg
(
v
,
'-'
)
within
group
(
order
by
v
desc
)
filter
(
where
v
>=
'4'
)
from
test
where
v
>=
'2'
;
>
LISTAGG
(
V
,
'-'
)
WITHIN
GROUP
(
ORDER
BY
V
)
LISTAGG
(
V
,
'-'
)
WITHIN
GROUP
(
ORDER
BY
V
DESC
)
FILTER
(
WHERE
(
V
>=
'4'
))
>
----------------------------------------- ------------------------------------------------------------------------
>
2
-
3
-
4
-
5
-
6
-
7
-
8
-
9
9
-
8
-
7
-
6
-
5
-
4
>
rows
:
1
select
group_concat
(
v
order
by
v
asc
separator
'-'
),
select
group_concat
(
v
order
by
v
asc
separator
'-'
),
group_concat
(
v
order
by
v
desc
separator
'-'
)
filter
(
where
v
>=
'4'
)
group_concat
(
v
order
by
v
desc
separator
'-'
)
filter
(
where
v
>=
'4'
)
from
test
where
v
>=
'2'
;
from
test
where
v
>=
'2'
;
>
GROUP_CONCAT
(
V
ORDER
BY
V
SEPARATOR
'-'
)
GROUP_CONCAT
(
V
ORDER
BY
V
DESC
SEPARATOR
'-'
)
FILTER
(
WHERE
(
V
>=
'4'
))
>
LISTAGG
(
V
,
'-'
)
WITHIN
GROUP
(
ORDER
BY
V
)
LISTAGG
(
V
,
'-'
)
WITHIN
GROUP
(
ORDER
BY
V
DESC
)
FILTER
(
WHERE
(
V
>=
'4'
))
>
----------------------------------------
-----------------------------------------------------------------------
>
----------------------------------------
- -
-----------------------------------------------------------------------
>
2
-
3
-
4
-
5
-
6
-
7
-
8
-
9
9
-
8
-
7
-
6
-
5
-
4
>
2
-
3
-
4
-
5
-
6
-
7
-
8
-
9
9
-
8
-
7
-
6
-
5
-
4
>
rows
:
1
>
rows
:
1
...
@@ -25,16 +33,16 @@ create index test_idx on test(v);
...
@@ -25,16 +33,16 @@ create index test_idx on test(v);
select
group_concat
(
v
order
by
v
asc
separator
'-'
),
select
group_concat
(
v
order
by
v
asc
separator
'-'
),
group_concat
(
v
order
by
v
desc
separator
'-'
)
filter
(
where
v
>=
'4'
)
group_concat
(
v
order
by
v
desc
separator
'-'
)
filter
(
where
v
>=
'4'
)
from
test
where
v
>=
'2'
;
from
test
where
v
>=
'2'
;
>
GROUP_CONCAT
(
V
ORDER
BY
V
SEPARATOR
'-'
)
GROUP_CONCAT
(
V
ORDER
BY
V
DESC
SEPARATOR
'-'
)
FILTER
(
WHERE
(
V
>=
'4'
))
>
LISTAGG
(
V
,
'-'
)
WITHIN
GROUP
(
ORDER
BY
V
)
LISTAGG
(
V
,
'-'
)
WITHIN
GROUP
(
ORDER
BY
V
DESC
)
FILTER
(
WHERE
(
V
>=
'4'
))
>
----------------------------------------
-----------------------------------------------------------------------
>
----------------------------------------
- -
-----------------------------------------------------------------------
>
2
-
3
-
4
-
5
-
6
-
7
-
8
-
9
9
-
8
-
7
-
6
-
5
-
4
>
2
-
3
-
4
-
5
-
6
-
7
-
8
-
9
9
-
8
-
7
-
6
-
5
-
4
>
rows
:
1
>
rows
:
1
select
group_concat
(
v
order
by
v
asc
separator
'-'
),
select
group_concat
(
v
order
by
v
asc
separator
'-'
),
group_concat
(
v
order
by
v
desc
separator
'-'
)
filter
(
where
v
>=
'4'
)
group_concat
(
v
order
by
v
desc
separator
'-'
)
filter
(
where
v
>=
'4'
)
from
test
;
from
test
;
>
GROUP_CONCAT
(
V
ORDER
BY
V
SEPARATOR
'-'
)
GROUP_CONCAT
(
V
ORDER
BY
V
DESC
SEPARATOR
'-'
)
FILTER
(
WHERE
(
V
>=
'4'
))
>
LISTAGG
(
V
,
'-'
)
WITHIN
GROUP
(
ORDER
BY
V
)
LISTAGG
(
V
,
'-'
)
WITHIN
GROUP
(
ORDER
BY
V
DESC
)
FILTER
(
WHERE
(
V
>=
'4'
))
>
----------------------------------------
-----------------------------------------------------------------------
>
----------------------------------------
- -
-----------------------------------------------------------------------
>
1
-
2
-
3
-
4
-
5
-
6
-
7
-
8
-
9
9
-
8
-
7
-
6
-
5
-
4
>
1
-
2
-
3
-
4
-
5
-
6
-
7
-
8
-
9
9
-
8
-
7
-
6
-
5
-
4
>
rows
:
1
>
rows
:
1
...
@@ -48,20 +56,20 @@ insert into test(v) values (7), (2), (8), (3), (7), (3), (9), (-1);
...
@@ -48,20 +56,20 @@ insert into test(v) values (7), (2), (8), (3), (7), (3), (9), (-1);
>
update
count
:
8
>
update
count
:
8
select
group_concat
(
v
)
from
test
;
select
group_concat
(
v
)
from
test
;
>
GROUP_CONCAT
(
V
)
>
LISTAGG
(
V
)
>
----------------
>
----------------
>
7
,
2
,
8
,
3
,
7
,
3
,
9
,
-
1
>
7
,
2
,
8
,
3
,
7
,
3
,
9
,
-
1
>
rows
:
1
>
rows
:
1
select
group_concat
(
distinct
v
)
from
test
;
select
group_concat
(
distinct
v
)
from
test
;
>
GROUP_CONCAT
(
DISTINCT
V
)
>
LISTAGG
(
DISTINCT
V
)
>
-------------------
-----
>
-------------------
>
-
1
,
2
,
3
,
7
,
8
,
9
>
-
1
,
2
,
3
,
7
,
8
,
9
>
rows
:
1
>
rows
:
1
select
group_concat
(
distinct
v
order
by
v
desc
)
from
test
;
select
group_concat
(
distinct
v
order
by
v
desc
)
from
test
;
>
GROUP_CONCAT
(
DISTINCT
V
ORDER
BY
V
DESC
)
>
LISTAGG
(
DISTINCT
V
)
WITHIN
GROUP
(
ORDER
BY
V
DESC
)
>
----------------------------------------
>
----------------------------------------
----------
>
9
,
8
,
7
,
3
,
2
,
-
1
>
9
,
8
,
7
,
3
,
2
,
-
1
>
rows
:
1
>
rows
:
1
...
@@ -71,17 +79,17 @@ drop table test;
...
@@ -71,17 +79,17 @@ drop table test;
create
table
test
(
g
varchar
,
v
int
)
as
values
(
'-'
,
1
),
(
'-'
,
2
),
(
'-'
,
3
),
(
'|'
,
4
),
(
'|'
,
5
),
(
'|'
,
6
),
(
'*'
,
null
);
create
table
test
(
g
varchar
,
v
int
)
as
values
(
'-'
,
1
),
(
'-'
,
2
),
(
'-'
,
3
),
(
'|'
,
4
),
(
'|'
,
5
),
(
'|'
,
6
),
(
'*'
,
null
);
>
ok
>
ok
select
g
,
group_concat
(
v
separator
g
)
from
test
group
by
g
;
select
g
,
listagg
(
v
,
g
)
from
test
group
by
g
;
>
G
GROUP_CONCAT
(
V
SEPARATOR
G
)
>
G
LISTAGG
(
V
,
G
)
>
-
-------------
--------------
>
-
-------------
>
*
null
>
*
null
>
-
1
-
2
-
3
>
-
1
-
2
-
3
>
|
4
|
5
|
6
>
|
4
|
5
|
6
>
rows
:
3
>
rows
:
3
select
g
,
group_concat
(
v
separator
g
)
over
(
partition
by
g
)
from
test
order
by
v
;
select
g
,
listagg
(
v
,
g
)
over
(
partition
by
g
)
from
test
order
by
v
;
>
G
GROUP_CONCAT
(
V
SEPARATOR
G
)
OVER
(
PARTITION
BY
G
)
>
G
LISTAGG
(
V
,
G
)
OVER
(
PARTITION
BY
G
)
>
-
-----------------------------------
--------------
>
-
-----------------------------------
>
*
null
>
*
null
>
-
1
-
2
-
3
>
-
1
-
2
-
3
>
-
1
-
2
-
3
>
-
1
-
2
-
3
...
@@ -91,6 +99,24 @@ select g, group_concat(v separator g) over (partition by g) from test order by v
...
@@ -91,6 +99,24 @@ select g, group_concat(v separator g) over (partition by g) from test order by v
>
|
4
|
5
|
6
>
|
4
|
5
|
6
>
rows
(
ordered
):
7
>
rows
(
ordered
):
7
select
g
,
listagg
(
v
,
g
on
overflow
error
)
within
group
(
order
by
v
)
filter
(
where
v
<>
2
)
over
(
partition
by
g
)
from
test
order
by
v
;
>
G
LISTAGG
(
V
,
G
)
WITHIN
GROUP
(
ORDER
BY
V
)
FILTER
(
WHERE
(
V
<>
2
))
OVER
(
PARTITION
BY
G
)
>
-
-------------------------------------------------------------------------------------
>
*
null
>
-
1
-
3
>
-
1
-
3
>
-
1
-
3
>
|
4
|
5
|
6
>
|
4
|
5
|
6
>
|
4
|
5
|
6
>
rows
(
ordered
):
7
select
listagg
(
distinct
v
,
'-'
)
from
test
;
>
LISTAGG
(
DISTINCT
V
,
'-'
)
>
------------------------
>
1
-
2
-
3
-
4
-
5
-
6
>
rows
:
1
select
g
,
group_concat
(
v
separator
v
)
from
test
group
by
g
;
select
g
,
group_concat
(
v
separator
v
)
from
test
group
by
g
;
>
exception
INVALID_VALUE_2
>
exception
INVALID_VALUE_2
...
...
h2/src/test/org/h2/test/scripts/testScript.sql
浏览文件 @
5a5a4050
...
@@ -3898,8 +3898,8 @@ SELECT * FROM TEST;
...
@@ -3898,8 +3898,8 @@ SELECT * FROM TEST;
> rows: 0
> rows: 0
SELECT GROUP_CONCAT(ID) FROM TEST;
SELECT GROUP_CONCAT(ID) FROM TEST;
>
GROUP_CONCAT
(ID)
>
LISTAGG
(ID)
> -----------
-----
> -----------
> null
> null
> rows: 1
> rows: 1
...
@@ -3930,8 +3930,8 @@ INSERT INTO TEST VALUES(2, 'World');
...
@@ -3930,8 +3930,8 @@ INSERT INTO TEST VALUES(2, 'World');
> update count: 1
> update count: 1
SELECT group_concat(name) FROM TEST group by id;
SELECT group_concat(name) FROM TEST group by id;
>
GROUP_CONCAT
(NAME)
>
LISTAGG
(NAME)
> -------------
-----
> -------------
> Hello
> Hello
> World
> World
> rows: 2
> rows: 2
...
@@ -6666,8 +6666,8 @@ INSERT INTO TEST VALUES(?, ?, ?);
...
@@ -6666,8 +6666,8 @@ INSERT INTO TEST VALUES(?, ?, ?);
>
update
count
:
9
>
update
count
:
9
SELECT
IFNULL
(
NAME
,
''
)
||
': '
||
GROUP_CONCAT
(
VALUE
ORDER
BY
NAME
,
VALUE
DESC
SEPARATOR
', '
)
FROM
TEST
GROUP
BY
NAME
ORDER
BY
1
;
SELECT
IFNULL
(
NAME
,
''
)
||
': '
||
GROUP_CONCAT
(
VALUE
ORDER
BY
NAME
,
VALUE
DESC
SEPARATOR
', '
)
FROM
TEST
GROUP
BY
NAME
ORDER
BY
1
;
>
(
IFNULL
(
NAME
,
''
)
||
': '
)
||
GROUP_CONCAT
(
VALUE
ORDER
BY
NAME
,
VALUE
DESC
SEPARATOR
', '
)
>
(
IFNULL
(
NAME
,
''
)
||
': '
)
||
LISTAGG
(
VALUE
,
', '
)
WITHIN
GROUP
(
ORDER
BY
NAME
,
VALUE
DESC
)
>
------------------------------------------------------------------------------------------
>
------------------------------------------------------------------------------------------
-
>
:
3
.
10
,
-
10
.
00
>
:
3
.
10
,
-
10
.
00
>
Apples
:
1
.
50
,
1
.
20
,
1
.
10
>
Apples
:
1
.
50
,
1
.
20
,
1
.
10
>
Bananas
:
2
.
50
>
Bananas
:
2
.
50
...
@@ -6676,14 +6676,14 @@ SELECT IFNULL(NAME, '') || ': ' || GROUP_CONCAT(VALUE ORDER BY NAME, VALUE DESC
...
@@ -6676,14 +6676,14 @@ SELECT IFNULL(NAME, '') || ': ' || GROUP_CONCAT(VALUE ORDER BY NAME, VALUE DESC
>
rows
(
ordered
):
5
>
rows
(
ordered
):
5
SELECT
GROUP_CONCAT
(
ID
ORDER
BY
ID
)
FROM
TEST
;
SELECT
GROUP_CONCAT
(
ID
ORDER
BY
ID
)
FROM
TEST
;
>
GROUP_CONCAT
(
ID
ORDER
BY
ID
)
>
LISTAGG
(
ID
)
WITHIN
GROUP
(
ORDER
BY
ID
)
>
----------------------------
>
----------------------------
----------
>
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
>
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
>
rows
:
1
>
rows
:
1
SELECT
STRING_AGG
(
ID
,
';'
)
FROM
TEST
;
SELECT
STRING_AGG
(
ID
,
';'
)
FROM
TEST
;
>
GROUP_CONCAT
(
ID
SEPARATOR
';'
)
>
LISTAGG
(
ID
,
';'
)
>
-----------------
-------------
>
-----------------
>
1
;
2
;
3
;
4
;
5
;
6
;
7
;
8
;
9
>
1
;
2
;
3
;
4
;
5
;
6
;
7
;
8
;
9
>
rows
:
1
>
rows
:
1
...
...
h2/src/tools/org/h2/build/doc/dictionary.txt
浏览文件 @
5a5a4050
...
@@ -806,4 +806,4 @@ econd irst bcef ordinality nord unnest
...
@@ -806,4 +806,4 @@ econd irst bcef ordinality nord unnest
analyst occupation distributive josaph aor engineer sajeewa isuru randil kevin doctor businessman artist ashan
analyst occupation distributive josaph aor engineer sajeewa isuru randil kevin doctor businessman artist ashan
corrupts splitted disruption unintentional octets preconditions predicates subq objectweb insn opcodes
corrupts splitted disruption unintentional octets preconditions predicates subq objectweb insn opcodes
preserves masking holder unboxing avert iae transformed subtle reevaluate exclusions subclause ftbl rgr
preserves masking holder unboxing avert iae transformed subtle reevaluate exclusions subclause ftbl rgr
presorted inclusion contexts aax mwd percentile cont interpolate mwa hypothetical regproc childed
presorted inclusion contexts aax mwd percentile cont interpolate mwa hypothetical regproc childed
listagg
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论