From df1a691ceb6d3eceb48fd64fe01ebae661166c78 Mon Sep 17 00:00:00 2001 From: LiBinfeng <1204975323@qq.com> Date: Mon, 14 Aug 2023 11:56:33 +0800 Subject: [PATCH 1/2] [Fix](Planner) fix multi phase analysis failed in multi instance environment substitution --- .../main/java/org/apache/doris/planner/AggregationNode.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/fe/fe-core/src/main/java/org/apache/doris/planner/AggregationNode.java b/fe/fe-core/src/main/java/org/apache/doris/planner/AggregationNode.java index 685430cd5c3c86..9be1262c38ed97 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/planner/AggregationNode.java +++ b/fe/fe-core/src/main/java/org/apache/doris/planner/AggregationNode.java @@ -176,6 +176,9 @@ public void init(Analyzer analyzer) throws UserException { // to our input; our conjuncts don't get substituted because they already // refer to our output outputSmap = getCombinedChildSmap(); + if (aggInfo.isMerge()) { + aggInfo.substitute(aggInfo.getIntermediateSmap(), analyzer); + } aggInfo.substitute(outputSmap, analyzer); // assert consistent aggregate expr and slot materialization From f1768edf40814ef2ed41d08966ddcf142df3032c Mon Sep 17 00:00:00 2001 From: LiBinfeng <1204975323@qq.com> Date: Tue, 25 Jul 2023 15:16:07 +0800 Subject: [PATCH 2/2] [Fix](Planner) fix parse error of view with group_concat order by --- .../doris/analysis/FunctionCallExpr.java | 19 ++++++++++++++++--- .../group_concat/test_group_concat.out | 5 ++++- .../group_concat/test_group_concat.groovy | 7 ++++++- 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/FunctionCallExpr.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/FunctionCallExpr.java index 76c2fe825acb40..07785f47ac95d1 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/FunctionCallExpr.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/FunctionCallExpr.java @@ -544,10 +544,18 @@ private String paramsToSql() { len = len - 1; } for (int i = 0; i < len; ++i) { + if (i != 0) { + if (fnName.getFunction().equalsIgnoreCase("group_concat") + && orderByElements.size() > 0 && i == len - orderByElements.size()) { + sb.append(" "); + } else { + sb.append(", "); + } + } if (i == 1 && (fnName.getFunction().equalsIgnoreCase("aes_decrypt") - || fnName.getFunction().equalsIgnoreCase("aes_encrypt") - || fnName.getFunction().equalsIgnoreCase("sm4_decrypt") - || fnName.getFunction().equalsIgnoreCase("sm4_encrypt"))) { + || fnName.getFunction().equalsIgnoreCase("aes_encrypt") + || fnName.getFunction().equalsIgnoreCase("sm4_decrypt") + || fnName.getFunction().equalsIgnoreCase("sm4_encrypt"))) { result.add("\'***\'"); } else if (orderByElements.size() > 0 && i == len - orderByElements.size()) { result.add("ORDER BY " + children.get(i).toSql()); @@ -1577,6 +1585,11 @@ && collectChildReturnTypes()[0].isDecimalV3()) { } // rewrite return type if is nested type function analyzeNestedFunction(); + for (OrderByElement o : orderByElements) { + if (!o.getExpr().isAnalyzed) { + o.getExpr().analyzeImpl(analyzer); + } + } } // if return type is nested type, need to be determined the sub-element type diff --git a/regression-test/data/query_p0/group_concat/test_group_concat.out b/regression-test/data/query_p0/group_concat/test_group_concat.out index 0bc76e11460c97..4bbe069046b419 100644 --- a/regression-test/data/query_p0/group_concat/test_group_concat.out +++ b/regression-test/data/query_p0/group_concat/test_group_concat.out @@ -49,6 +49,9 @@ false 1 3, 21, 2, 11, 1 2 23, 222, 22, 211, 21 --- !select_group_concat_order_by -- +-- !select_group_concat_order_by1 -- +1,11,2,21,21,211,22,222,23,3 3,23,222,22,211,21,21,2,11,1 + +-- !select_group_concat_order_by2 -- 1,11,2,21,21,211,22,222,23,3 3,23,222,22,211,21,21,2,11,1 diff --git a/regression-test/suites/query_p0/group_concat/test_group_concat.groovy b/regression-test/suites/query_p0/group_concat/test_group_concat.groovy index f2d5dd35041339..bb8d5328ccdf87 100644 --- a/regression-test/suites/query_p0/group_concat/test_group_concat.groovy +++ b/regression-test/suites/query_p0/group_concat/test_group_concat.groovy @@ -62,8 +62,13 @@ suite("test_group_concat") { qt_select_group_concat_order_by_desc3 """ SELECT b1, group_concat(cast(abs(b3) as varchar) order by abs(b2) desc, b3 desc) FROM table_group_concat group by b1 order by b1 """ - qt_select_group_concat_order_by """ + qt_select_group_concat_order_by1 """ select group_concat(b3,',' order by b3 asc),group_concat(b3,',' order by b3 desc) from table_group_concat; """ + sql """create view if not exists test_view as select group_concat(b3,',' order by b3 asc),group_concat(b3,',' order by b3 desc) from table_group_concat;""" + qt_select_group_concat_order_by2 """ + select * from test_view; + """ + sql """drop view if exists test_view""" }