924060929 commented on code in PR #38104: URL: https://github.com/apache/doris/pull/38104#discussion_r1686139805
########## fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/BindExpression.java: ########## @@ -531,6 +536,33 @@ private LogicalJoin<Plan, Plan> bindJoin(MatchingContext<LogicalJoin<Plan, Plan> join.children(), null); } + // Recursive method to check for duplicate table names or aliases + private void checkPlan(Plan plan, Set<String> tableNames) throws AnalysisException { + if (plan instanceof LogicalSubQueryAlias) { + LogicalSubQueryAlias subQueryAlias = (LogicalSubQueryAlias) plan; + String alias = subQueryAlias.getAlias(); + + if (!tableNames.add(alias)) { + throw new AnalysisException("Not unique table/alias: '" + alias + "'"); + } + + } else if (plan instanceof LogicalCatalogRelation) { + LogicalCatalogRelation relation = (LogicalCatalogRelation) plan; + String tableName = relation.getTable().getName(); + + + if (!tableNames.add(tableName)) { + throw new AnalysisException("Not unique table/alias: '" + tableName + "'"); + } + } else { + // Recursively check the children of the current plan + for (Plan child : plan.children()) { + checkPlan(child, tableNames); + } + } + } + + Review Comment: how about refactor to ```java private void checkConflictAlias(Plan plan, Set<String> tableNames, boolean isTopLevel) { Set<String> existsTableNames = Sets.newLinkedHashSet(); Consumer<String> checkAlias = tableAliasName -> { if (!existsTableNames.add(tableAliasName)) { throw new AnalysisException("Not unique table/alias: '" + tableAliasName + "'"); } }; boolean stopCheckChildren = true; plan.foreach(p -> { if (p instanceof LogicalSubQueryAlias) { checkAlias.accept(((LogicalSubQueryAlias<?>) p).getAlias()); return stopCheckChildren; } else if (p instanceof LogicalCatalogRelation) { TableIf table = ((LogicalCatalogRelation) p).getTable(); checkAlias.accept(table.getName()); return stopCheckChildren; } else { return !stopCheckChildren; } }); } ``` -- 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