diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/SelectStmt.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/SelectStmt.java index 107c7d8cefd170..2f2ebaf9e89cd8 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/SelectStmt.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/SelectStmt.java @@ -42,6 +42,7 @@ import org.apache.doris.common.TreeNode; import org.apache.doris.common.UserException; import org.apache.doris.common.util.SqlUtils; +import org.apache.doris.common.util.ToSqlContext; import org.apache.doris.qe.ConnectContext; import org.apache.doris.rewrite.ExprRewriter; import org.apache.doris.rewrite.mvrewrite.MVSelectFailedException; @@ -2143,7 +2144,9 @@ private boolean checkSortNodeEliminable(Expr expr, List sortSlotRefs) { @Override public String toSql() { if (sqlString != null) { - return sqlString; + if (ToSqlContext.get() == null || ToSqlContext.get().isNeedSlotRefId()) { + return sqlString; + } } StringBuilder strBuilder = new StringBuilder(); if (withClause != null) { diff --git a/regression-test/suites/query_p0/sql_functions/window_functions/test_window_fn.groovy b/regression-test/suites/query_p0/sql_functions/window_functions/test_window_fn.groovy index 181f597849e6cd..1cbab91a44e0f4 100644 --- a/regression-test/suites/query_p0/sql_functions/window_functions/test_window_fn.groovy +++ b/regression-test/suites/query_p0/sql_functions/window_functions/test_window_fn.groovy @@ -356,6 +356,14 @@ suite("test_window_fn") { from example_window_tb order by u_id; """ + sql """ + create view v as select row_number() over(partition by u_city order by u_salary) as wf from example_window_tb + """ + + sql """ + drop view v + """ + sql "DROP TABLE IF EXISTS example_window_tb;" }