[fix](planner) failed to create view when use window function (#17815)

fix failed to create view when use window function because the view string contains slot id and which cannot be parsed.
This commit is contained in:
mch_ucchi
2023-03-24 10:58:52 +08:00
committed by GitHub
parent 22fce33fb2
commit aa3ea4beed
2 changed files with 12 additions and 1 deletions

View File

@ -42,6 +42,7 @@ import org.apache.doris.common.TableAliasGenerator;
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 @@ public class SelectStmt extends QueryStmt {
@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) {

View File

@ -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;"
}