From a2b1e631c0ab473fa732cdab7b02b5c7eb264581 Mon Sep 17 00:00:00 2001 From: wuyuechuan Date: Mon, 24 Jun 2024 10:53:27 +0800 Subject: [PATCH] =?UTF-8?q?bugfix:=E8=8E=B7=E5=8F=96=E5=B8=A6group=5Fconca?= =?UTF-8?q?t=E8=87=AA=E5=AE=9A=E4=B9=89=E8=81=9A=E9=9B=86=E5=87=BD?= =?UTF-8?q?=E6=95=B0=E5=88=9B=E5=BB=BA=E7=9A=84=E8=A7=86=E5=9B=BE=E5=AE=9A?= =?UTF-8?q?=E4=B9=89=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 3 +- src/common/backend/utils/adt/ruleutils.cpp | 6 ++-- .../expected/single_node_create_aggregate.out | 30 +++++++++++++++++++ .../sql/single_node_create_aggregate.sql | 22 ++++++++++++++ 4 files changed, 57 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 6877e8f64..d68d7dc98 100644 --- a/.gitignore +++ b/.gitignore @@ -21,4 +21,5 @@ objfiles.txt /config.status /ereport.txt -/build/script/version.cfg \ No newline at end of file +/build/script/version.cfg +/cmake_build \ No newline at end of file diff --git a/src/common/backend/utils/adt/ruleutils.cpp b/src/common/backend/utils/adt/ruleutils.cpp index dc25b3c8f..a971423e1 100644 --- a/src/common/backend/utils/adt/ruleutils.cpp +++ b/src/common/backend/utils/adt/ruleutils.cpp @@ -10831,7 +10831,7 @@ static void get_agg_expr(Aggref* aggref, deparse_context* context) #endif /* PGXC */ char* funcname = generate_function_name(aggref->aggfnoid, nargs, NIL, argtypes, aggref->aggvariadic, &use_variadic); appendStringInfo(buf, "%s(%s", funcname, (aggref->aggdistinct != NIL) ? "DISTINCT " : ""); - + bool isGroupCatAggFunc = aggref->aggfnoid == GROUPCONCATFUNCOID; if (AGGKIND_IS_ORDERED_SET(aggref->aggkind)) { /* * Ordered-set aggregates do not use "*" syntax and we needn't @@ -10854,7 +10854,7 @@ static void get_agg_expr(Aggref* aggref, deparse_context* context) int narg = 0; int start = 0; /* the first argument of group_concat() is separator, skip it */ - if (pg_strcasecmp(funcname, "group_concat") == 0) { + if (isGroupCatAggFunc) { init = init->next; narg++; start++; @@ -10884,7 +10884,7 @@ static void get_agg_expr(Aggref* aggref, deparse_context* context) } } - if (pg_strcasecmp(funcname, "group_concat") == 0) { + if (isGroupCatAggFunc) { appendStringInfoString(buf, " SEPARATOR "); Const* con = (Const*)(((TargetEntry*)lfirst(list_head(aggref->args)))->expr); get_rule_separator(con, buf); diff --git a/src/test/regress/expected/single_node_create_aggregate.out b/src/test/regress/expected/single_node_create_aggregate.out index ad1459419..9f669a074 100644 --- a/src/test/regress/expected/single_node_create_aggregate.out +++ b/src/test/regress/expected/single_node_create_aggregate.out @@ -59,3 +59,33 @@ create aggregate aggfns(integer,integer,text) ( sfunc = aggfns_trans, stype = aggtype[], initcond = '{}' ); +create schema view_test_create_group_concat; +set current_schema = 'view_test_create_group_concat'; +CREATE TABLE t1(a INT, b INT); +CREATE FUNCTION _group_concat(text, text) RETURNS text + LANGUAGE sql IMMUTABLE + AS $_$ +SELECT CASE + WHEN $2 IS NULL THEN $1 + WHEN $1 IS NULL THEN $2 + ELSE $1 || ', ' || $2 +END +$_$; +CREATE AGGREGATE group_concat(text) ( + SFUNC = _group_concat, + STYPE = text +); +CREATE VIEW v4_4_2 AS SELECT group_concat(a::text) a FROM t1; +select pg_get_viewdef('v4_4_2'); + pg_get_viewdef +--------------------------------------------------------------- + SELECT group_concat((t1.a)::text SEPARATOR ',') AS a FROM t1; +(1 row) + +reset current_schema; +drop schema view_test_create_group_concat cascade; +NOTICE: drop cascades to 4 other objects +DETAIL: drop cascades to table view_test_create_group_concat.t1 +drop cascades to function view_test_create_group_concat._group_concat(text,text) +drop cascades to function view_test_create_group_concat.group_concat(text) +drop cascades to view view_test_create_group_concat.v4_4_2 diff --git a/src/test/regress/sql/single_node_create_aggregate.sql b/src/test/regress/sql/single_node_create_aggregate.sql index 84f9a4f1e..1e8118ac1 100644 --- a/src/test/regress/sql/single_node_create_aggregate.sql +++ b/src/test/regress/sql/single_node_create_aggregate.sql @@ -71,3 +71,25 @@ create aggregate aggfns(integer,integer,text) ( sfunc = aggfns_trans, stype = aggtype[], initcond = '{}' ); + +create schema view_test_create_group_concat; +set current_schema = 'view_test_create_group_concat'; +CREATE TABLE t1(a INT, b INT); +CREATE FUNCTION _group_concat(text, text) RETURNS text + LANGUAGE sql IMMUTABLE + AS $_$ +SELECT CASE + WHEN $2 IS NULL THEN $1 + WHEN $1 IS NULL THEN $2 + ELSE $1 || ', ' || $2 +END +$_$; +CREATE AGGREGATE group_concat(text) ( + SFUNC = _group_concat, + STYPE = text +); + +CREATE VIEW v4_4_2 AS SELECT group_concat(a::text) a FROM t1; +select pg_get_viewdef('v4_4_2'); +reset current_schema; +drop schema view_test_create_group_concat cascade; \ No newline at end of file