Yulei-Yang commented on code in PR #33193: URL: https://github.com/apache/doris/pull/33193#discussion_r1604511918
########## fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/BindRelation.java: ########## @@ -328,13 +333,57 @@ private Plan parseAndAnalyzeHiveView( return hiveViewPlan; } + /** + * Support get column from hive view with column name like '_c0', '_c1' etc for hive. + */ + public void addHiveViewDerivedColumn(Plan hiveViewPlan) { + if (hiveViewPlan instanceof LogicalProject) { + List<NamedExpression> projects = ((LogicalProject) hiveViewPlan).getProjects(); + int counter = -1; + for (NamedExpression project : projects) { + counter++; + // only set inner name for derived column + if (project instanceof UnboundAlias) { + UnboundAlias aliasProject = (UnboundAlias) project; + if (aliasProject.getAlias().isPresent()) { + continue; + } + if (aliasProject.child() instanceof UnboundFunction) { + aliasProject.setAlias(Optional.of("_c" + counter)); + } + } + } + } + + if (hiveViewPlan instanceof LogicalAggregate) { + int counter = -1; + List<NamedExpression> expressions = ((LogicalAggregate) hiveViewPlan).getOutputExpressions(); + for (NamedExpression expression : expressions) { + counter++; + if (expression instanceof UnboundAlias) { + UnboundAlias aliasProject = (UnboundAlias) expression; + if (aliasProject.getAlias().isPresent()) { + continue; + } + aliasProject.setAlias(Optional.of("_c" + counter)); + } + } + } + + // Recursively init subquery + for (Plan subPlan : hiveViewPlan.children()) { + addHiveViewDerivedColumn(subPlan); + } + } + private Plan parseAndAnalyzeView(TableIf view, String ddlSql, CascadesContext parentContext) { parentContext.getStatementContext().addViewDdlSql(ddlSql); Optional<SqlCacheContext> sqlCacheContext = parentContext.getStatementContext().getSqlCacheContext(); if (sqlCacheContext.isPresent()) { sqlCacheContext.get().addUsedView(view, ddlSql); } LogicalPlan parsedViewPlan = new NereidsParser().parseSingle(ddlSql); + addHiveViewDerivedColumn(parsedViewPlan); Review Comment: fixed -- 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. To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org 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