Changeset: 22ed846b388f for MonetDB URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=22ed846b388f Modified Files: sql/server/rel_select.c sql/test/group-concat/Tests/groupconcat01.sql sql/test/group-concat/Tests/groupconcat01.stable.out sql/test/group-concat/Tests/groupconcat05.sql sql/test/group-concat/Tests/groupconcat05.stable.out Branch: Aug2018 Log Message:
Fixed type checking for group_concat aggregation function. As this aggregate is implemented for strings only, a proper cast should be made for other types. diffs (207 lines): diff --git a/sql/server/rel_select.c b/sql/server/rel_select.c --- a/sql/server/rel_select.c +++ b/sql/server/rel_select.c @@ -3632,10 +3632,20 @@ static sql_exp * if (!a && list_length(exps) > 1) { sql_subtype *t1 = exp_subtype(exps->h->data); a = sql_bind_member_aggr(sql->sa, s, aname, exp_subtype(exps->h->data), list_length(exps)); - - if (list_length(exps) != 2 || (!EC_NUMBER(t1->type->eclass) || !a || subtype_cmp( + bool is_group_concat = (!a && strcmp(s->base.name, "sys") == 0 && strcmp(aname, "group_concat") == 0); + + if (list_length(exps) != 2 || (!EC_NUMBER(t1->type->eclass) || !a || is_group_concat || subtype_cmp( &((sql_arg*)a->aggr->ops->h->data)->type, &((sql_arg*)a->aggr->ops->h->next->data)->type) != 0) ) { + if(!a && is_group_concat) { + sql_subtype *tstr = sql_bind_localtype("str"); + list *sargs = sa_list(sql->sa); + if (list_length(exps) >= 1) + append(sargs, tstr); + if (list_length(exps) == 2) + append(sargs, tstr); + a = sql_bind_aggr_(sql->sa, s, aname, sargs); + } if (a) { node *n, *op = a->aggr->ops->h; list *nexps = sa_list(sql->sa); @@ -3651,7 +3661,7 @@ static sql_exp * } if (a && list_length(nexps)) /* count(col) has |exps| != |nexps| */ exps = nexps; - } + } } else { sql_exp *l = exps->h->data, *ol = l; sql_exp *r = exps->h->next->data, *or = r; diff --git a/sql/test/group-concat/Tests/groupconcat01.sql b/sql/test/group-concat/Tests/groupconcat01.sql --- a/sql/test/group-concat/Tests/groupconcat01.sql +++ b/sql/test/group-concat/Tests/groupconcat01.sql @@ -18,5 +18,6 @@ select a, group_concat(b) from testme gr insert into testme values (5, ''), (4, 'nothing'), (5, ''), (3, ''); select a, group_concat(b) from testme group by a; +select a, group_concat(a) from testme group by a; rollback; diff --git a/sql/test/group-concat/Tests/groupconcat01.stable.out b/sql/test/group-concat/Tests/groupconcat01.stable.out --- a/sql/test/group-concat/Tests/groupconcat01.stable.out +++ b/sql/test/group-concat/Tests/groupconcat01.stable.out @@ -128,6 +128,16 @@ Ready. [ 3, NULL ] [ 4, NULL ] [ 5, "," ] +#select a, group_concat(a) from testme group by a; +% sys.testme, sys.L3 # table_name +% a, L3 # name +% int, clob # type +% 1, 13 # length +[ 1, "1,1,1,1" ] +[ 2, "2,2,2,2" ] +[ 3, "3,3,3,3,3,3,3" ] +[ 4, "4,4,4" ] +[ 5, "5,5" ] #rollback; # 14:11:33 > diff --git a/sql/test/group-concat/Tests/groupconcat05.sql b/sql/test/group-concat/Tests/groupconcat05.sql --- a/sql/test/group-concat/Tests/groupconcat05.sql +++ b/sql/test/group-concat/Tests/groupconcat05.sql @@ -22,5 +22,10 @@ select a, group_concat(b, 'XyZ\n') from select a, group_concat(b, NULL) from testmore group by a; select group_concat(b, NULL) from testmore; +select group_concat(a, NULL) from testmore; +select group_concat(a, a) from testmore; +select group_concat(a, 8) from testmore; +select group_concat(a, b) from testmore; +select group_concat(b, a) from testmore; rollback; diff --git a/sql/test/group-concat/Tests/groupconcat05.stable.out b/sql/test/group-concat/Tests/groupconcat05.stable.out --- a/sql/test/group-concat/Tests/groupconcat05.stable.out +++ b/sql/test/group-concat/Tests/groupconcat05.stable.out @@ -29,13 +29,13 @@ Ready. #insert into testmore values (1, 'another'), (1, 'testing'), (1, 'todo'); [ 3 ] #select a, group_concat(b, '!') from testmore group by a; -% sys.testmore, sys.L4 # table_name +% sys.testmore, sys.L3 # table_name % a, L3 # name % int, clob # type % 1, 20 # length [ 1, "another!testing!todo" ] #select group_concat(b, '!') from testmore; -% sys.L4 # table_name +% sys.L3 # table_name % L3 # name % clob # type % 20 # length @@ -43,7 +43,7 @@ Ready. #insert into testmore values (2, 'lets'), (3, 'get'), (2, 'harder'); [ 3 ] #select a, group_concat(b, '---') from testmore group by a; -% sys.testmore, sys.L4 # table_name +% sys.testmore, sys.L3 # table_name % a, L3 # name % int, clob # type % 1, 24 # length @@ -51,7 +51,7 @@ Ready. [ 2, "lets---harder" ] [ 3, "get" ] #select group_concat(b, '---') from testmore; -% sys.L4 # table_name +% sys.L3 # table_name % L3 # name % clob # type % 46 # length @@ -59,7 +59,7 @@ Ready. #insert into testmore values (3, 'even'), (2, 'more'), (1, ''); [ 3 ] #select a, group_concat(b, '') from testmore group by a; -% sys.testmore, sys.L4 # table_name +% sys.testmore, sys.L3 # table_name % a, L3 # name % int, clob # type % 1, 18 # length @@ -67,13 +67,13 @@ Ready. [ 2, "letshardermore" ] [ 3, "geteven" ] #select group_concat(b, '') from testmore; -% sys.L4 # table_name +% sys.L3 # table_name % L3 # name % clob # type % 39 # length [ "anothertestingtodoletsgetharderevenmore" ] #select a, group_concat(b, '-') from testmore group by a; -% sys.testmore, sys.L4 # table_name +% sys.testmore, sys.L3 # table_name % a, L3 # name % int, clob # type % 1, 21 # length @@ -81,7 +81,7 @@ Ready. [ 2, "lets-harder-more" ] [ 3, "get-even" ] #select a, group_concat(b) from testmore group by a; -% sys.testmore, sys.L4 # table_name +% sys.testmore, sys.L3 # table_name % a, L3 # name % int, clob # type % 1, 21 # length @@ -91,7 +91,7 @@ Ready. #insert into testmore values (3, 'even'), (2, NULL), (1, ''); [ 3 ] #select a, group_concat(b, 'XyZ\n') from testmore group by a; -% sys.testmore, sys.L4 # table_name +% sys.testmore, sys.L3 # table_name % a, L3 # name % int, clob # type % 1, 34 # length @@ -99,7 +99,7 @@ Ready. [ 2, NULL ] [ 3, "getXyZ\nevenXyZ\neven" ] #select a, group_concat(b, NULL) from testmore group by a; -% sys.testmore, sys.L4 # table_name +% sys.testmore, sys.L3 # table_name % a, L3 # name % int, clob # type % 1, 0 # length @@ -107,7 +107,37 @@ Ready. [ 2, NULL ] [ 3, NULL ] #select group_concat(b, NULL) from testmore; -% sys.L4 # table_name +% sys.L3 # table_name +% L3 # name +% clob # type +% 0 # length +[ NULL ] +#select group_concat(a, NULL) from testmore; +% sys.L3 # table_name +% L3 # name +% clob # type +% 0 # length +[ NULL ] +#select group_concat(a, a) from testmore; +% sys.L3 # table_name +% L3 # name +% clob # type +% 23 # length +[ "11111121312131211131211" ] +#select group_concat(a, 8) from testmore; +% sys.L3 # table_name +% L3 # name +% clob # type +% 23 # length +[ "18181828382838281838281" ] +#select group_concat(a, b) from testmore; +% sys.L3 # table_name +% L3 # name +% clob # type +% 89 # length +[ "1another1another1another2another3another2another3another2another1another3another2another1" ] +#select group_concat(b, a) from testmore; +% sys.L3 # table_name % L3 # name % clob # type % 0 # length _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list