Skip to content

Commit

Permalink
[Fix](Planner) fix parse error of view with group_concat order by
Browse files Browse the repository at this point in the history
  • Loading branch information
LiBinfeng-01 committed Jul 26, 2023
1 parent ea2a7a8 commit 7ca6de2
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,12 @@ private String paramsToSql() {

for (int i = 0; i < len; ++i) {
if (i != 0) {
sb.append(", ");
if (fnName.getFunction().equalsIgnoreCase("group_concat")
&& orderByElements.size() > 0 && i == len - orderByElements.size()) {
sb.append(" ");
} else {
sb.append(", ");
}
}
if (ConnectContext.get() != null && ConnectContext.get().getState().isQuery() && i == 1
&& (fnName.getFunction().equalsIgnoreCase("aes_decrypt")
Expand Down Expand Up @@ -807,6 +812,16 @@ private void analyzeBuiltinAggFunction(Analyzer analyzer) throws AnalysisExcepti
"group_concat don't support using distinct with order by together: " + this.toSql());
}

// if (!orderByElements.isEmpty()) {
// getOrderByElements().forEach(o -> {
// try {
// o.getExpr().analyze(analyzer);
// } catch (AnalysisException e) {
// throw new RuntimeException(e);
// }
// });
// }

return;
}
if (fnName.getFunction().equalsIgnoreCase("field")) {
Expand Down Expand Up @@ -1777,6 +1792,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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,7 @@ false
1 3,21,2,11,1
2 23,222,22,211,21

-- !select_group_concat_order_by_desc4 --
1 3,21,2,11,1
2 23,222,22,211,21

Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,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

Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,10 @@ 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
"""

sql """create view if not exists test_view as 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_desc4 """
select * from test_view;
"""
sql """drop view if exists test_view"""
}
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,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"""
}

0 comments on commit 7ca6de2

Please sign in to comment.