[Fix](planner)fix create view ignore order by info bug. (#18197)

This commit is contained in:
mch_ucchi
2023-03-30 20:17:46 +08:00
committed by GitHub
parent ce79ff947a
commit fefc0d6814
3 changed files with 107 additions and 8 deletions

View File

@ -57,6 +57,7 @@ import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@ -2223,13 +2224,7 @@ public class SelectStmt extends QueryStmt {
// Order By clause
if (orderByElements != null) {
strBuilder.append(" ORDER BY ");
for (int i = 0; i < orderByElements.size(); ++i) {
strBuilder.append(orderByElements.get(i).getExpr().toSql());
if (sortInfo != null) {
strBuilder.append((sortInfo.getIsAscOrder().get(i)) ? " ASC" : " DESC");
}
strBuilder.append((i + 1 != orderByElements.size()) ? ", " : "");
}
strBuilder.append(StringUtils.join(orderByElements, ", "));
}
// Limit clause.
if (hasLimitClause()) {

View File

@ -191,7 +191,7 @@ public class CreateViewTest {
Assert.assertEquals(
"WITH test1_cte(w1, w2) AS (SELECT `k1`, `k2` FROM `default_cluster:test`.`tbl1`) "
+ "SELECT `w1` AS `c1`, sum(`w2`) AS `c2` FROM `test1_cte` WHERE `w1` > 10 GROUP BY `w1` "
+ "ORDER BY `w1` ASC",
+ "ORDER BY `w1` ASC NULLS FIRST",
alter1.getInlineViewDef());
}
}