xy720 commented on a change in pull request #3378: URL: https://github.com/apache/incubator-doris/pull/3378#discussion_r412851569
########## File path: fe/src/main/java/org/apache/doris/analysis/BaseViewStmt.java ########## @@ -109,33 +112,37 @@ protected void createColumnAndViewDefs(Analyzer analyzer) throws AnalysisExcepti } // format view def string - originalViewDef = viewDefStmt.toSql(); + String lowerCaseOriginSql = getOriginSql().toLowerCase(); + + originalViewDef = lowerCaseOriginSql.substring(lowerCaseOriginSql.indexOf(KW_AS) + 3); + LOG.debug("origin view def sql is {}", originalViewDef); if (cols == null) { inlineViewDef = originalViewDef; + LOG.debug("inline view def sql is {}", inlineViewDef); return; } Analyzer tmpAnalyzer = new Analyzer(analyzer); List<String> colNames = cols.stream().map(c -> c.getColName()).collect(Collectors.toList()); cloneStmt.substituteSelectList(tmpAnalyzer, colNames); - inlineViewDef = cloneStmt.toSql(); - -// StringBuilder sb = new StringBuilder(); -// sb.append("SELECT "); -// for (int i = 0; i < finalCols.size(); ++i) { -// if (i != 0) { -// sb.append(", "); -// } -// String colRef = viewDefStmt.getColLabels().get(i); -// if (!colRef.startsWith("`")) { -// colRef = "`" + colRef + "`"; -// } -// String colAlias = finalCols.get(i).getName(); -// sb.append(String.format("`%s`.%s AS `%s`", tableName.getTbl(), colRef, colAlias)); -// } -// sb.append(String.format(" FROM (%s) %s", originalViewDef, tableName.getTbl())); -// inlineViewDef = sb.toString(); + + StringBuilder sb = new StringBuilder(); + sb.append("SELECT "); + for (int i = 0; i < colNames.size(); ++i) { + if (i != 0) { + sb.append(", "); + } + String colRef = viewDefStmt.getColLabels().get(i); + if (!colRef.startsWith("`")) { + colRef = "`" + colRef + "`"; + } + String colAlias = colNames.get(i); + sb.append(String.format("`%s`.%s AS `%s`", tableName.getTbl(), colRef, colAlias)); Review comment: It is work for function call? For example, if user input: "create view test_view (h1, h2) as select function(a, b), col2 from testTbl" will become "select function(a, b) as h1, col2 as h2 from (select function(a, b), col2 from testTbl)" ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org