diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java index a61f62d1df..0824c09c9d 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java @@ -469,6 +469,9 @@ public class LogicalPlanBuilder extends DorisParserBaseVisitor { @Override public LogicalPlan visitAliasedQuery(AliasedQueryContext ctx) { + if (ctx.tableAlias().getText().equals("")) { + throw new ParseException("Every derived table must have its own alias", ctx); + } LogicalPlan plan = withTableAlias(visitQuery(ctx.query()), ctx.tableAlias()); for (LateralViewContext lateralViewContext : ctx.lateralView()) { plan = withGenerate(plan, lateralViewContext); diff --git a/regression-test/suites/nereids_syntax_p0/sub_query_alias.groovy b/regression-test/suites/nereids_syntax_p0/sub_query_alias.groovy index 316d7af220..5a5987ec43 100644 --- a/regression-test/suites/nereids_syntax_p0/sub_query_alias.groovy +++ b/regression-test/suites/nereids_syntax_p0/sub_query_alias.groovy @@ -22,6 +22,19 @@ suite("sub_query_alias") { sql "SET enable_fallback_to_original_planner=false" + test { + sql """ select * + from ( + select * + from customer, lineorder + where customer.c_custkey = lineorder.lo_custkey + ) """ + check {result, exception, startTime, endTime -> + assertTrue(exception != null) + logger.info(exception.message) + } + } + qt_select_1 """ select t.c_custkey, t.lo_custkey from (