提交 9042e61e authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

Parse ALL in aggregates

上级 7d843c06
......@@ -3418,7 +3418,7 @@ INTERVAL MINUTE TO SECOND
"
"Functions (Aggregate)","AVG","
AVG ( [ DISTINCT ] { numeric } )
AVG ( [ DISTINCT|ALL ] { numeric } )
[FILTER (WHERE expression)] [OVER windowNameOrSpecification]
","
The average (mean) value.
......@@ -3474,7 +3474,7 @@ ANY(NAME LIKE 'W%')
"
"Functions (Aggregate)","COUNT","
COUNT( { * | { [ DISTINCT ] expression } } )
COUNT( { * | { [ DISTINCT|ALL ] expression } } )
[FILTER (WHERE expression)] [OVER windowNameOrSpecification]
","
The count of all row, or of the non-null values.
......@@ -3486,7 +3486,7 @@ COUNT(*)
"
"Functions (Aggregate)","GROUP_CONCAT","
GROUP_CONCAT ( [ DISTINCT ] string
GROUP_CONCAT ( [ DISTINCT|ALL ] string
[ ORDER BY { expression [ ASC | DESC ] } [,...] ]
[ SEPARATOR expression ] )
[FILTER (WHERE expression)] [OVER windowNameOrSpecification]
......@@ -3501,7 +3501,7 @@ GROUP_CONCAT(NAME ORDER BY ID SEPARATOR ', ')
"
"Functions (Aggregate)","ARRAY_AGG","
ARRAY_AGG ( [ DISTINCT ] string
ARRAY_AGG ( [ DISTINCT|ALL ] string
[ ORDER BY { expression [ ASC | DESC ] } [,...] ] )
[FILTER (WHERE expression)] [OVER windowNameOrSpecification]
","
......@@ -3538,7 +3538,7 @@ MIN(NAME)
"
"Functions (Aggregate)","SUM","
SUM( [ DISTINCT ] { numeric } )
SUM( [ DISTINCT|ALL ] { numeric } )
[FILTER (WHERE expression)] [OVER windowNameOrSpecification]
","
The sum of all values.
......@@ -3564,7 +3564,7 @@ SELECT SELECTIVITY(FIRSTNAME), SELECTIVITY(NAME) FROM TEST WHERE ROWNUM()<20000
"
"Functions (Aggregate)","STDDEV_POP","
STDDEV_POP( [ DISTINCT ] numeric )
STDDEV_POP( [ DISTINCT|ALL ] numeric )
[FILTER (WHERE expression)] [OVER windowNameOrSpecification]
","
The population standard deviation.
......@@ -3576,7 +3576,7 @@ STDDEV_POP(X)
"
"Functions (Aggregate)","STDDEV_SAMP","
STDDEV_SAMP( [ DISTINCT ] numeric )
STDDEV_SAMP( [ DISTINCT|ALL ] numeric )
[FILTER (WHERE expression)] [OVER windowNameOrSpecification]
","
The sample standard deviation.
......@@ -3588,7 +3588,7 @@ STDDEV(X)
"
"Functions (Aggregate)","VAR_POP","
VAR_POP( [ DISTINCT ] numeric )
VAR_POP( [ DISTINCT|ALL ] numeric )
[FILTER (WHERE expression)] [OVER windowNameOrSpecification]
","
The population variance (square of the population standard deviation).
......@@ -3600,7 +3600,7 @@ VAR_POP(X)
"
"Functions (Aggregate)","VAR_SAMP","
VAR_SAMP( [ DISTINCT ] numeric )
VAR_SAMP( [ DISTINCT|ALL ] numeric )
[FILTER (WHERE expression)] [OVER windowNameOrSpecification]
","
The sample variance (square of the sample standard deviation).
......@@ -3612,7 +3612,7 @@ VAR_SAMP(X)
"
"Functions (Aggregate)","MEDIAN","
MEDIAN( [ DISTINCT ] value )
MEDIAN( [ DISTINCT|ALL ] value )
[FILTER (WHERE expression)] [OVER windowNameOrSpecification]
","
The value separating the higher half of a values from the lower half.
......
......@@ -2949,7 +2949,7 @@ public class Parser {
if (readIf(ASTERISK)) {
r = new Aggregate(AggregateType.COUNT_ALL, null, currentSelect, false);
} else {
boolean distinct = readIf(DISTINCT);
boolean distinct = readDistinctAgg();
Expression on = readExpression();
if (on instanceof Wildcard && !distinct) {
// PostgreSQL compatibility: count(t.*)
......@@ -2960,7 +2960,7 @@ public class Parser {
}
break;
case GROUP_CONCAT: {
boolean distinct = readIf(DISTINCT);
boolean distinct = readDistinctAgg();
if (equalsToken("GROUP_CONCAT", aggregateName)) {
r = new Aggregate(AggregateType.GROUP_CONCAT, readExpression(), currentSelect, distinct);
if (readIf(ORDER)) {
......@@ -2985,7 +2985,7 @@ public class Parser {
break;
}
case ARRAY_AGG: {
boolean distinct = readIf(DISTINCT);
boolean distinct = readDistinctAgg();
r = new Aggregate(AggregateType.ARRAY_AGG, readExpression(), currentSelect, distinct);
if (readIf(ORDER)) {
read("BY");
......@@ -3020,7 +3020,7 @@ public class Parser {
break;
}
default:
boolean distinct = readIf(DISTINCT);
boolean distinct = readDistinctAgg();
r = new Aggregate(aggregateType, readExpression(), currentSelect, distinct);
break;
}
......@@ -3078,7 +3078,7 @@ public class Parser {
}
private JavaAggregate readJavaAggregate(UserAggregate aggregate) {
boolean distinct = readIf(DISTINCT);
boolean distinct = readDistinctAgg();
ArrayList<Expression> params = Utils.newSmallArrayList();
do {
params.add(readExpression());
......@@ -3089,6 +3089,14 @@ public class Parser {
return agg;
}
private boolean readDistinctAgg() {
if (readIf(DISTINCT)) {
return true;
}
readIf(ALL);
return false;
}
private void readFilterAndOver(AbstractAggregate aggregate) {
if (readIf("FILTER")) {
read(OPEN_PAREN);
......
......@@ -26,6 +26,15 @@ select sum(v), sum(v) filter (where v >= 4) from test where v <= 10;
> 55 49
> rows: 1
insert into test values (1), (2), (8);
> update count: 3
select sum(v), sum(all v), sum(distinct v) from test;
> SUM(V) SUM(V) SUM(DISTINCT V)
> ------ ------ ---------------
> 89 89 78
> rows: 1
drop table test;
> ok
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论