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

Parse ALL in aggregates

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