mirror of https://github.com/citusdata/citus.git
Merge pull request #2030 from citusdata/bool_agg
Add support for bool and bit aggregatespull/2008/head
commit
8e2c72c054
|
@ -2351,8 +2351,7 @@ WorkerAggregateExpressionList(Aggref *originalAggregate,
|
|||
else
|
||||
{
|
||||
/*
|
||||
* All other aggregates are sent as they are to the worker nodes. These
|
||||
* aggregate functions include sum, count, min, max, and array_agg.
|
||||
* All other aggregates are sent as they are to the worker nodes.
|
||||
*/
|
||||
Aggref *workerAggregate = copyObject(originalAggregate);
|
||||
workerAggregateList = lappend(workerAggregateList, workerAggregate);
|
||||
|
|
|
@ -61,7 +61,12 @@ typedef enum
|
|||
AGGREGATE_JSONB_AGG = 7,
|
||||
AGGREGATE_JSONB_OBJECT_AGG = 8,
|
||||
AGGREGATE_JSON_AGG = 9,
|
||||
AGGREGATE_JSON_OBJECT_AGG = 10
|
||||
AGGREGATE_JSON_OBJECT_AGG = 10,
|
||||
AGGREGATE_BIT_AND = 11,
|
||||
AGGREGATE_BIT_OR = 12,
|
||||
AGGREGATE_BOOL_AND = 13,
|
||||
AGGREGATE_BOOL_OR = 14,
|
||||
AGGREGATE_EVERY = 15
|
||||
} AggregateType;
|
||||
|
||||
|
||||
|
@ -105,7 +110,8 @@ static const char *const AggregateNames[] = {
|
|||
"invalid", "avg", "min", "max",
|
||||
"sum", "count", "array_agg",
|
||||
"jsonb_agg", "jsonb_object_agg",
|
||||
"json_agg", "json_object_agg"
|
||||
"json_agg", "json_object_agg",
|
||||
"bit_and", "bit_or", "bool_and", "bool_or", "every"
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,55 @@
|
|||
-- Tests for boolean aggregates in multi-shard queries
|
||||
CREATE SCHEMA bool_agg;
|
||||
SET search_path TO bool_agg;
|
||||
CREATE TABLE bool_test (id int, val int, flag bool, kind int);
|
||||
SELECT create_distributed_table('bool_agg.bool_test','id');
|
||||
create_distributed_table
|
||||
--------------------------
|
||||
|
||||
(1 row)
|
||||
|
||||
INSERT INTO bool_test VALUES (1, 1, true, 99), (2, 2, false, 99), (2, 3, true, 88);
|
||||
-- mix of true and false
|
||||
SELECT bool_and(flag), bool_or(flag), every(flag) FROM bool_test;
|
||||
bool_and | bool_or | every
|
||||
----------+---------+-------
|
||||
f | t | f
|
||||
(1 row)
|
||||
|
||||
SELECT kind, bool_and(flag), bool_or(flag), every(flag) FROM bool_test GROUP BY kind ORDER BY 2;
|
||||
kind | bool_and | bool_or | every
|
||||
------+----------+---------+-------
|
||||
99 | f | t | f
|
||||
88 | t | t | t
|
||||
(2 rows)
|
||||
|
||||
-- expressions in aggregate
|
||||
SELECT bool_or(val > 2 OR id < 2), bool_and(val < 3) FROM bool_test;
|
||||
bool_or | bool_and
|
||||
---------+----------
|
||||
t | f
|
||||
(1 row)
|
||||
|
||||
SELECT kind, bool_or(val > 2 OR id < 2), bool_and(val < 3) FROM bool_test GROUP BY kind ORDER BY 3;
|
||||
kind | bool_or | bool_and
|
||||
------+---------+----------
|
||||
88 | t | f
|
||||
99 | t | t
|
||||
(2 rows)
|
||||
|
||||
-- 1 & 3, 1 | 3
|
||||
SELECT bit_and(val), bit_or(val) FROM bool_test WHERE flag;
|
||||
bit_and | bit_or
|
||||
---------+--------
|
||||
1 | 3
|
||||
(1 row)
|
||||
|
||||
SELECT flag, bit_and(val), bit_or(val) FROM bool_test GROUP BY flag ORDER BY flag;
|
||||
flag | bit_and | bit_or
|
||||
------+---------+--------
|
||||
f | 2 | 2
|
||||
t | 1 | 3
|
||||
(2 rows)
|
||||
|
||||
DROP SCHEMA bool_agg CASCADE;
|
||||
NOTICE: drop cascades to table bool_test
|
|
@ -60,10 +60,7 @@ test: multi_agg_distinct multi_agg_approximate_distinct multi_limit_clause_appro
|
|||
test: multi_reference_table
|
||||
test: multi_average_expression multi_working_columns multi_having_pushdown
|
||||
test: multi_array_agg multi_limit_clause multi_orderby_limit_pushdown
|
||||
test: multi_jsonb_agg
|
||||
test: multi_jsonb_object_agg
|
||||
test: multi_json_agg
|
||||
test: multi_json_object_agg
|
||||
test: multi_jsonb_agg multi_jsonb_object_agg multi_json_agg multi_json_object_agg bool_agg
|
||||
test: multi_agg_type_conversion multi_count_type_conversion
|
||||
test: multi_partition_pruning
|
||||
test: multi_join_pruning multi_hash_pruning
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
-- Tests for boolean aggregates in multi-shard queries
|
||||
CREATE SCHEMA bool_agg;
|
||||
SET search_path TO bool_agg;
|
||||
|
||||
CREATE TABLE bool_test (id int, val int, flag bool, kind int);
|
||||
SELECT create_distributed_table('bool_agg.bool_test','id');
|
||||
INSERT INTO bool_test VALUES (1, 1, true, 99), (2, 2, false, 99), (2, 3, true, 88);
|
||||
|
||||
-- mix of true and false
|
||||
SELECT bool_and(flag), bool_or(flag), every(flag) FROM bool_test;
|
||||
SELECT kind, bool_and(flag), bool_or(flag), every(flag) FROM bool_test GROUP BY kind ORDER BY 2;
|
||||
|
||||
-- expressions in aggregate
|
||||
SELECT bool_or(val > 2 OR id < 2), bool_and(val < 3) FROM bool_test;
|
||||
SELECT kind, bool_or(val > 2 OR id < 2), bool_and(val < 3) FROM bool_test GROUP BY kind ORDER BY 3;
|
||||
|
||||
-- 1 & 3, 1 | 3
|
||||
SELECT bit_and(val), bit_or(val) FROM bool_test WHERE flag;
|
||||
SELECT flag, bit_and(val), bit_or(val) FROM bool_test GROUP BY flag ORDER BY flag;
|
||||
|
||||
DROP SCHEMA bool_agg CASCADE;
|
Loading…
Reference in New Issue