From ea0afb2a788edf55e6cdf3ffcd569d57db6243d1 Mon Sep 17 00:00:00 2001 From: morningman Date: Tue, 29 Aug 2023 16:02:18 +0800 Subject: [PATCH] [branch-1.2] fix some function call expr toSql issue --- .../doris/analysis/FunctionCallExpr.java | 26 ++++++++++++++----- 1 file changed, 20 insertions(+), 6 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 10b1f9e46d1c4c..09dc26a67f263b 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 @@ -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(); @@ -532,7 +540,6 @@ private String paramsToSql() { sb.append("DISTINCT "); } int len = children.size(); - List result = Lists.newArrayList(); if (fnName.getFunction().equalsIgnoreCase("json_array") || fnName.getFunction().equalsIgnoreCase("json_object")) { len = len - 1; @@ -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(); } @@ -1964,3 +1977,4 @@ private void setChildren() { orderByElements.forEach(o -> addChild(o.getExpr())); } } +