[Fix](Planner) fix parse error of view with group_concat order by (#22196)

Problem:
    When create view with projection group_concat(xxx, xxx order by orderkey). It will failed during second parse of inline view

For example:
    it works when doing 
    "SELECT id, group_concat(`name`, "," ORDER BY id) AS test_group_column FROM  test GROUP BY id"
    but when create view it does not work
    "create view test_view as SELECT id, group_concat(`name`, "," ORDER BY id) AS test_group_column FROM  test GROUP BY id"

Reason:
    when creating view, we will doing parse again of view.toSql() to check whether it has some syntax error. And when doing toSql() to group_concat with order by, it add seperate ', ' between second parameter and order by. So when parsing again, it
would failed because it is different semantic with original statement.
    group_concat(`name`, "," ORDER BY id)  ==> group_concat(`name`, "," , ORDER BY id)

Solved:
    Change toSql of group_concat and add order by statement analyze() of group_concat in Planner cause it would work if we get order by from view statement and do not analyze and binding slot reference to it
This commit is contained in:
LiBinfeng
2023-07-31 17:20:23 +08:00
committed by GitHub
parent 4c6458aa77
commit 3a1d678ca9
5 changed files with 31 additions and 3 deletions

View File

@ -547,7 +547,12 @@ public class FunctionCallExpr extends Expr {
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")
@ -1785,6 +1790,11 @@ public class FunctionCallExpr extends Expr {
}
// 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