提交 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.
BIT_OR(ID)
"
"Functions (Aggregate)","BOOL_AND","
BOOL_AND(boolean)
"Functions (Aggregate)","EVERY","
{EVERY|BOOL_AND}(boolean)
[FILTER (WHERE expression)] [OVER windowNameOrSpecification]
","
Returns true if all expressions are true.
If no rows are selected, the result is NULL.
Aggregates are only allowed in select statements.
","
BOOL_AND(ID>10)
EVERY(ID>10)
"
"Functions (Aggregate)","BOOL_OR","
BOOL_OR(boolean)
"Functions (Aggregate)","ANY","
{ANY|SOME|BOOL_OR}(boolean)
[FILTER (WHERE expression)] [OVER windowNameOrSpecification]
","
Returns true if any expression is true.
If no rows are selected, the result is NULL.
Aggregates are only allowed in select statements.
","
BOOL_OR(NAME LIKE 'W%')
ANY(NAME LIKE 'W%')
"
"Functions (Aggregate)","COUNT","
......
......@@ -105,14 +105,14 @@ public class Aggregate extends AbstractAggregate {
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).
......@@ -209,12 +209,13 @@ public class Aggregate extends AbstractAggregate {
addAggregate("VAR_SAMP", AggregateType.VAR_SAMP);
addAggregate("VAR", AggregateType.VAR_SAMP);
addAggregate("VARIANCE", AggregateType.VAR_SAMP);
addAggregate("BOOL_OR", AggregateType.BOOL_OR);
// HSQLDB compatibility, but conflicts with x > EVERY(...)
addAggregate("SOME", AggregateType.BOOL_OR);
addAggregate("BOOL_AND", AggregateType.BOOL_AND);
// HSQLDB compatibility, but conflicts with x > SOME(...)
addAggregate("EVERY", AggregateType.BOOL_AND);
addAggregate("ANY", AggregateType.ANY);
addAggregate("SOME", AggregateType.ANY);
// PostgreSQL compatibility
addAggregate("BOOL_OR", AggregateType.ANY);
addAggregate("EVERY", AggregateType.EVERY);
// PostgreSQL compatibility
addAggregate("BOOL_AND", AggregateType.EVERY);
addAggregate("SELECTIVITY", AggregateType.SELECTIVITY);
addAggregate("HISTOGRAM", AggregateType.HISTOGRAM);
addAggregate("BIT_OR", AggregateType.BIT_OR);
......@@ -652,8 +653,8 @@ public class Aggregate extends AbstractAggregate {
displaySize = ValueDouble.DISPLAY_SIZE;
scale = 0;
break;
case BOOL_AND:
case BOOL_OR:
case EVERY:
case ANY:
dataType = Value.BOOLEAN;
precision = ValueBoolean.PRECISION;
displaySize = ValueBoolean.DISPLAY_SIZE;
......@@ -779,11 +780,11 @@ public class Aggregate extends AbstractAggregate {
case VAR_SAMP:
text = "VAR_SAMP";
break;
case BOOL_AND:
text = "BOOL_AND";
case EVERY:
text = "EVERY";
break;
case BOOL_OR:
text = "BOOL_OR";
case ANY:
text = "ANY";
break;
case BIT_AND:
text = "BIT_AND";
......
......@@ -40,8 +40,8 @@ abstract class AggregateData {
case MAX:
case BIT_OR:
case BIT_AND:
case BOOL_OR:
case BOOL_AND:
case ANY:
case EVERY:
return new AggregateDataDefault(aggregateType);
case SUM:
case AVG:
......
......@@ -83,7 +83,7 @@ class AggregateDataDefault extends AggregateData {
}
break;
}
case BOOL_AND:
case EVERY:
v = v.convertTo(Value.BOOLEAN);
if (value == null) {
value = v;
......@@ -91,7 +91,7 @@ class AggregateDataDefault extends AggregateData {
value = ValueBoolean.get(value.getBoolean() && v.getBoolean());
}
break;
case BOOL_OR:
case ANY:
v = v.convertTo(Value.BOOLEAN);
if (value == null) {
value = v;
......@@ -127,8 +127,8 @@ class AggregateDataDefault extends AggregateData {
case MAX:
case BIT_OR:
case BIT_AND:
case BOOL_OR:
case BOOL_AND:
case ANY:
case EVERY:
v = value;
break;
case AVG:
......
......@@ -161,8 +161,8 @@ public class TestScript extends TestDb {
for (String s : new String[] { "help" }) {
testScript("other/" + s + ".sql");
}
for (String s : new String[] { "array-agg", "avg", "bit-and", "bit-or", "count", "envelope",
"group-concat", "histogram", "max", "median", "min", "mode", "selectivity", "stddev-pop",
for (String s : new String[] { "any", "array-agg", "avg", "bit-and", "bit-or", "count", "envelope",
"every", "group-concat", "histogram", "max", "median", "min", "mode", "selectivity", "stddev-pop",
"stddev-samp", "sum", "var-pop", "var-samp" }) {
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;
> rows: 1
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
> rows: 1
......@@ -6640,8 +6640,8 @@ stddev_pop(distinct y) s_py, stddev_samp(distinct y) s_sy, var_pop(distinct y) v
> rows: 1
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
> rows: 1
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论