提交 d6670d61 authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

Add ANY aggregate and use standard names in documentation

上级 138b31ca
...@@ -3444,26 +3444,26 @@ Aggregates are only allowed in select statements. ...@@ -3444,26 +3444,26 @@ Aggregates are only allowed in select statements.
BIT_OR(ID) BIT_OR(ID)
" "
"Functions (Aggregate)","BOOL_AND"," "Functions (Aggregate)","EVERY","
BOOL_AND(boolean) {EVERY|BOOL_AND}(boolean)
[FILTER (WHERE expression)] [OVER windowNameOrSpecification] [FILTER (WHERE expression)] [OVER windowNameOrSpecification]
"," ","
Returns true if all expressions are true. Returns true if all expressions are true.
If no rows are selected, the result is NULL. If no rows are selected, the result is NULL.
Aggregates are only allowed in select statements. Aggregates are only allowed in select statements.
"," ","
BOOL_AND(ID>10) EVERY(ID>10)
" "
"Functions (Aggregate)","BOOL_OR"," "Functions (Aggregate)","ANY","
BOOL_OR(boolean) {ANY|SOME|BOOL_OR}(boolean)
[FILTER (WHERE expression)] [OVER windowNameOrSpecification] [FILTER (WHERE expression)] [OVER windowNameOrSpecification]
"," ","
Returns true if any expression is true. Returns true if any expression is true.
If no rows are selected, the result is NULL. If no rows are selected, the result is NULL.
Aggregates are only allowed in select statements. Aggregates are only allowed in select statements.
"," ","
BOOL_OR(NAME LIKE 'W%') ANY(NAME LIKE 'W%')
" "
"Functions (Aggregate)","COUNT"," "Functions (Aggregate)","COUNT","
......
...@@ -105,14 +105,14 @@ public class Aggregate extends AbstractAggregate { ...@@ -105,14 +105,14 @@ public class Aggregate extends AbstractAggregate {
VAR_SAMP, VAR_SAMP,
/** /**
* The aggregate type for BOOL_OR(expression). * The aggregate type for ANY(expression).
*/ */
BOOL_OR, ANY,
/** /**
* The aggregate type for BOOL_AND(expression). * The aggregate type for EVERY(expression).
*/ */
BOOL_AND, EVERY,
/** /**
* The aggregate type for BOOL_OR(expression). * The aggregate type for BOOL_OR(expression).
...@@ -209,12 +209,13 @@ public class Aggregate extends AbstractAggregate { ...@@ -209,12 +209,13 @@ public class Aggregate extends AbstractAggregate {
addAggregate("VAR_SAMP", AggregateType.VAR_SAMP); addAggregate("VAR_SAMP", AggregateType.VAR_SAMP);
addAggregate("VAR", AggregateType.VAR_SAMP); addAggregate("VAR", AggregateType.VAR_SAMP);
addAggregate("VARIANCE", AggregateType.VAR_SAMP); addAggregate("VARIANCE", AggregateType.VAR_SAMP);
addAggregate("BOOL_OR", AggregateType.BOOL_OR); addAggregate("ANY", AggregateType.ANY);
// HSQLDB compatibility, but conflicts with x > EVERY(...) addAggregate("SOME", AggregateType.ANY);
addAggregate("SOME", AggregateType.BOOL_OR); // PostgreSQL compatibility
addAggregate("BOOL_AND", AggregateType.BOOL_AND); addAggregate("BOOL_OR", AggregateType.ANY);
// HSQLDB compatibility, but conflicts with x > SOME(...) addAggregate("EVERY", AggregateType.EVERY);
addAggregate("EVERY", AggregateType.BOOL_AND); // PostgreSQL compatibility
addAggregate("BOOL_AND", AggregateType.EVERY);
addAggregate("SELECTIVITY", AggregateType.SELECTIVITY); addAggregate("SELECTIVITY", AggregateType.SELECTIVITY);
addAggregate("HISTOGRAM", AggregateType.HISTOGRAM); addAggregate("HISTOGRAM", AggregateType.HISTOGRAM);
addAggregate("BIT_OR", AggregateType.BIT_OR); addAggregate("BIT_OR", AggregateType.BIT_OR);
...@@ -652,8 +653,8 @@ public class Aggregate extends AbstractAggregate { ...@@ -652,8 +653,8 @@ public class Aggregate extends AbstractAggregate {
displaySize = ValueDouble.DISPLAY_SIZE; displaySize = ValueDouble.DISPLAY_SIZE;
scale = 0; scale = 0;
break; break;
case BOOL_AND: case EVERY:
case BOOL_OR: case ANY:
dataType = Value.BOOLEAN; dataType = Value.BOOLEAN;
precision = ValueBoolean.PRECISION; precision = ValueBoolean.PRECISION;
displaySize = ValueBoolean.DISPLAY_SIZE; displaySize = ValueBoolean.DISPLAY_SIZE;
...@@ -779,11 +780,11 @@ public class Aggregate extends AbstractAggregate { ...@@ -779,11 +780,11 @@ public class Aggregate extends AbstractAggregate {
case VAR_SAMP: case VAR_SAMP:
text = "VAR_SAMP"; text = "VAR_SAMP";
break; break;
case BOOL_AND: case EVERY:
text = "BOOL_AND"; text = "EVERY";
break; break;
case BOOL_OR: case ANY:
text = "BOOL_OR"; text = "ANY";
break; break;
case BIT_AND: case BIT_AND:
text = "BIT_AND"; text = "BIT_AND";
......
...@@ -40,8 +40,8 @@ abstract class AggregateData { ...@@ -40,8 +40,8 @@ abstract class AggregateData {
case MAX: case MAX:
case BIT_OR: case BIT_OR:
case BIT_AND: case BIT_AND:
case BOOL_OR: case ANY:
case BOOL_AND: case EVERY:
return new AggregateDataDefault(aggregateType); return new AggregateDataDefault(aggregateType);
case SUM: case SUM:
case AVG: case AVG:
......
...@@ -83,7 +83,7 @@ class AggregateDataDefault extends AggregateData { ...@@ -83,7 +83,7 @@ class AggregateDataDefault extends AggregateData {
} }
break; break;
} }
case BOOL_AND: case EVERY:
v = v.convertTo(Value.BOOLEAN); v = v.convertTo(Value.BOOLEAN);
if (value == null) { if (value == null) {
value = v; value = v;
...@@ -91,7 +91,7 @@ class AggregateDataDefault extends AggregateData { ...@@ -91,7 +91,7 @@ class AggregateDataDefault extends AggregateData {
value = ValueBoolean.get(value.getBoolean() && v.getBoolean()); value = ValueBoolean.get(value.getBoolean() && v.getBoolean());
} }
break; break;
case BOOL_OR: case ANY:
v = v.convertTo(Value.BOOLEAN); v = v.convertTo(Value.BOOLEAN);
if (value == null) { if (value == null) {
value = v; value = v;
...@@ -127,8 +127,8 @@ class AggregateDataDefault extends AggregateData { ...@@ -127,8 +127,8 @@ class AggregateDataDefault extends AggregateData {
case MAX: case MAX:
case BIT_OR: case BIT_OR:
case BIT_AND: case BIT_AND:
case BOOL_OR: case ANY:
case BOOL_AND: case EVERY:
v = value; v = value;
break; break;
case AVG: case AVG:
......
...@@ -161,8 +161,8 @@ public class TestScript extends TestDb { ...@@ -161,8 +161,8 @@ public class TestScript extends TestDb {
for (String s : new String[] { "help" }) { for (String s : new String[] { "help" }) {
testScript("other/" + s + ".sql"); testScript("other/" + s + ".sql");
} }
for (String s : new String[] { "array-agg", "avg", "bit-and", "bit-or", "count", "envelope", for (String s : new String[] { "any", "array-agg", "avg", "bit-and", "bit-or", "count", "envelope",
"group-concat", "histogram", "max", "median", "min", "mode", "selectivity", "stddev-pop", "every", "group-concat", "histogram", "max", "median", "min", "mode", "selectivity", "stddev-pop",
"stddev-samp", "sum", "var-pop", "var-samp" }) { "stddev-samp", "sum", "var-pop", "var-samp" }) {
testScript("functions/aggregate/" + s + ".sql"); testScript("functions/aggregate/" + s + ".sql");
} }
......
-- Copyright 2004-2018 H2 Group. Multiple-Licensed under the MPL 2.0,
-- and the EPL 1.0 (http://h2database.com/html/license.html).
-- Initial Developer: H2 Group
--
CREATE TABLE TEST(A INT, B INT);
> ok
INSERT INTO TEST VALUES (1, 1), (1, 3), (2, 1), (2, 5), (3, 4);
> update count: 5
SELECT A, ANY(B < 2), SOME(B > 3), BOOL_OR(B = 1), ANY(B = 1) FILTER (WHERE A = 1) FROM TEST GROUP BY A;
> A ANY(B < 2) ANY(B > 3) ANY(B = 1) ANY(B = 1) FILTER (WHERE (A = 1))
> - ---------- ---------- ---------- ---------------------------------
> 1 TRUE FALSE TRUE TRUE
> 2 TRUE TRUE TRUE null
> 3 FALSE TRUE FALSE null
> rows: 3
DROP TABLE TEST;
> ok
-- Copyright 2004-2018 H2 Group. Multiple-Licensed under the MPL 2.0,
-- and the EPL 1.0 (http://h2database.com/html/license.html).
-- Initial Developer: H2 Group
--
-- Copyright 2004-2018 H2 Group. Multiple-Licensed under the MPL 2.0,
-- and the EPL 1.0 (http://h2database.com/html/license.html).
-- Initial Developer: H2 Group
--
-- Copyright 2004-2018 H2 Group. Multiple-Licensed under the MPL 2.0,
-- and the EPL 1.0 (http://h2database.com/html/license.html).
-- Initial Developer: H2 Group
--
CREATE TABLE TEST(A INT, B INT);
> ok
INSERT INTO TEST VALUES (1, 1), (1, 3), (2, 1), (2, 5), (3, 4);
> update count: 5
SELECT A, EVERY(B < 5), BOOL_AND(B > 1), EVERY(B >= 1) FILTER (WHERE A = 1) FROM TEST GROUP BY A;
> A EVERY(B < 5) EVERY(B > 1) EVERY(B >= 1) FILTER (WHERE (A = 1))
> - ------------ ------------ ------------------------------------
> 1 TRUE FALSE TRUE
> 2 FALSE FALSE null
> 3 TRUE TRUE null
> rows: 3
DROP TABLE TEST;
> ok
...@@ -6582,8 +6582,8 @@ select * from s; ...@@ -6582,8 +6582,8 @@ select * from s;
> rows: 1 > rows: 1
select some(y>10), every(y>10), min(y), max(y) from t; select some(y>10), every(y>10), min(y), max(y) from t;
> BOOL_OR(Y > 10.0) BOOL_AND(Y > 10.0) MIN(Y) MAX(Y) > ANY(Y > 10.0) EVERY(Y > 10.0) MIN(Y) MAX(Y)
> ----------------- ------------------ ------ ------ > ------------- --------------- ------ ------
> null null null null > null null null null
> rows: 1 > rows: 1
...@@ -6640,8 +6640,8 @@ stddev_pop(distinct y) s_py, stddev_samp(distinct y) s_sy, var_pop(distinct y) v ...@@ -6640,8 +6640,8 @@ stddev_pop(distinct y) s_py, stddev_samp(distinct y) s_sy, var_pop(distinct y) v
> rows: 1 > rows: 1
select some(y>10), every(y>10), min(y), max(y) from t; select some(y>10), every(y>10), min(y), max(y) from t;
> BOOL_OR(Y > 10.0) BOOL_AND(Y > 10.0) MIN(Y) MAX(Y) > ANY(Y > 10.0) EVERY(Y > 10.0) MIN(Y) MAX(Y)
> ----------------- ------------------ ------ ------ > ------------- --------------- ------ ------
> TRUE FALSE 4.0 16.0 > TRUE FALSE 4.0 16.0
> rows: 1 > rows: 1
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论