Skip to content

Commit

Permalink
[branch-1.2] fix some function call expr toSql issue
Browse files Browse the repository at this point in the history
  • Loading branch information
morningman committed Aug 29, 2023
1 parent fd39530 commit ea0afb2
Showing 1 changed file with 20 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,14 @@ public boolean equals(Object obj) {
return false;
}
}
if (orderByElements.size() != o.orderByElements.size()) {
return false;
}
for (int i = 0; i < orderByElements.size(); i++) {
if (!orderByElements.get(i).equals(o.orderByElements.get(i))) {
return false;
}
}
return /*opcode == o.opcode && aggOp == o.aggOp &&*/ fnName.equals(o.fnName)
&& fnParams.isDistinct() == o.fnParams.isDistinct()
&& fnParams.isStar() == o.fnParams.isStar();
Expand All @@ -532,7 +540,6 @@ private String paramsToSql() {
sb.append("DISTINCT ");
}
int len = children.size();
List<String> result = Lists.newArrayList();
if (fnName.getFunction().equalsIgnoreCase("json_array")
|| fnName.getFunction().equalsIgnoreCase("json_object")) {
len = len - 1;
Expand All @@ -556,14 +563,20 @@ private String paramsToSql() {
|| fnName.getFunction().equalsIgnoreCase("aes_encrypt")
|| fnName.getFunction().equalsIgnoreCase("sm4_decrypt")
|| fnName.getFunction().equalsIgnoreCase("sm4_encrypt"))) {
result.add("\'***\'");
sb.append("\'***\'");
} else if (orderByElements.size() > 0 && i == len - orderByElements.size()) {
result.add("ORDER BY " + children.get(i).toSql());
} else {
result.add(children.get(i).toSql());
sb.append("ORDER BY");
}
sb.append(children.get(i).toSql());
if (orderByElements.size() > 0 && i >= len - orderByElements.size()) {
if (orderByElements.get(i - len + orderByElements.size()).getIsAsc()) {
sb.append(" ASC");
} else {
sb.append(" DESC");
}
}
}
sb.append(Joiner.on(", ").join(result)).append(")");
sb.append(")");
return sb.toString();
}

Expand Down Expand Up @@ -1964,3 +1977,4 @@ private void setChildren() {
orderByElements.forEach(o -> addChild(o.getExpr()));
}
}

0 comments on commit ea0afb2

Please sign in to comment.