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 33f11c4687fa05..7b003264c993b1 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 @@ -987,22 +987,22 @@ public LogicalPlan visitRegularQuerySpecification(RegularQuerySpecificationConte return ParserUtils.withOrigin(ctx, () -> { SelectClauseContext selectCtx = ctx.selectClause(); LogicalPlan selectPlan; + LogicalPlan relation; if (ctx.fromClause() == null) { SelectColumnClauseContext columnCtx = selectCtx.selectColumnClause(); if (columnCtx.EXCEPT() != null) { throw new ParseException("select-except cannot be used in one row relation", selectCtx); } - selectPlan = withOneRowRelation(columnCtx); + relation = withOneRowRelation(columnCtx); } else { - LogicalPlan relation = visitFromClause(ctx.fromClause()); - selectPlan = withSelectQuerySpecification( - ctx, relation, - selectCtx, - Optional.ofNullable(ctx.whereClause()), - Optional.ofNullable(ctx.aggClause()), - Optional.ofNullable(ctx.havingClause()) - ); + relation = visitFromClause(ctx.fromClause()); } + selectPlan = withSelectQuerySpecification( + ctx, relation, + selectCtx, + Optional.ofNullable(ctx.whereClause()), + Optional.ofNullable(ctx.aggClause()), + Optional.ofNullable(ctx.havingClause())); selectPlan = withQueryOrganization(selectPlan, ctx.queryOrganization()); return withSelectHint(selectPlan, selectCtx.selectHint()); }); diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/BindExpression.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/BindExpression.java index 2608a554fc94d0..b5afe0d006693d 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/BindExpression.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/BindExpression.java @@ -445,6 +445,12 @@ protected boolean condition(Rule rule, Plan plan) { LogicalCTEAnchor cteAnchor = sort.child(); return bindSort(sort, cteAnchor, ctx.cascadesContext); }) + ), RuleType.BINDING_SORT_SLOT.build( + logicalSort(logicalOneRowRelation()).thenApply(ctx -> { + LogicalSort sort = ctx.root; + LogicalOneRowRelation oneRowRelation = sort.child(); + return bindSort(sort, oneRowRelation, ctx.cascadesContext); + }) ), RuleType.BINDING_SORT_SET_OPERATION_SLOT.build( logicalSort(logicalSetOperation()).thenApply(ctx -> { diff --git a/regression-test/data/nereids_p0/select_no_from/sql/withGroupOrderHaving.out b/regression-test/data/nereids_p0/select_no_from/sql/withGroupOrderHaving.out new file mode 100644 index 00000000000000..636cae7e3f00c1 --- /dev/null +++ b/regression-test/data/nereids_p0/select_no_from/sql/withGroupOrderHaving.out @@ -0,0 +1,10 @@ +-- This file is automatically generated. You should know what you did if you want to edit this +-- !withGroupOrderHaving -- +0 + +-- !withGroupOrderHaving_2 -- +10 3 + +-- !withGroupOrderHaving_3 -- +1 1 2 1.0 1 + diff --git a/regression-test/data/nereids_p0/select_no_from/sql/withWhereClause.out b/regression-test/data/nereids_p0/select_no_from/sql/withWhereClause.out new file mode 100644 index 00000000000000..0b6d028a244fba --- /dev/null +++ b/regression-test/data/nereids_p0/select_no_from/sql/withWhereClause.out @@ -0,0 +1,7 @@ +-- This file is automatically generated. You should know what you did if you want to edit this +-- !withWhereClause -- +0 + +-- !withWhereClause_2 -- +1 + diff --git a/regression-test/data/nereids_p0/select_no_from/sql/withWhereFalse.out b/regression-test/data/nereids_p0/select_no_from/sql/withWhereFalse.out new file mode 100644 index 00000000000000..bd030d90fae128 --- /dev/null +++ b/regression-test/data/nereids_p0/select_no_from/sql/withWhereFalse.out @@ -0,0 +1,7 @@ +-- This file is automatically generated. You should know what you did if you want to edit this +-- !withWhereFalse -- +0 + +-- !withWhereFalse_2 -- +0 1 + diff --git a/regression-test/data/query_p0/select_no_from/sql/withGroupOrderHaving.out b/regression-test/data/query_p0/select_no_from/sql/withGroupOrderHaving.out new file mode 100644 index 00000000000000..636cae7e3f00c1 --- /dev/null +++ b/regression-test/data/query_p0/select_no_from/sql/withGroupOrderHaving.out @@ -0,0 +1,10 @@ +-- This file is automatically generated. You should know what you did if you want to edit this +-- !withGroupOrderHaving -- +0 + +-- !withGroupOrderHaving_2 -- +10 3 + +-- !withGroupOrderHaving_3 -- +1 1 2 1.0 1 + diff --git a/regression-test/data/query_p0/select_no_from/sql/withWhereClause.out b/regression-test/data/query_p0/select_no_from/sql/withWhereClause.out new file mode 100644 index 00000000000000..0b6d028a244fba --- /dev/null +++ b/regression-test/data/query_p0/select_no_from/sql/withWhereClause.out @@ -0,0 +1,7 @@ +-- This file is automatically generated. You should know what you did if you want to edit this +-- !withWhereClause -- +0 + +-- !withWhereClause_2 -- +1 + diff --git a/regression-test/data/query_p0/select_no_from/sql/withWhereFalse.out b/regression-test/data/query_p0/select_no_from/sql/withWhereFalse.out new file mode 100644 index 00000000000000..bd030d90fae128 --- /dev/null +++ b/regression-test/data/query_p0/select_no_from/sql/withWhereFalse.out @@ -0,0 +1,7 @@ +-- This file is automatically generated. You should know what you did if you want to edit this +-- !withWhereFalse -- +0 + +-- !withWhereFalse_2 -- +0 1 + diff --git a/regression-test/suites/nereids_p0/select_no_from/sql/withGroupOrderHaving.sql b/regression-test/suites/nereids_p0/select_no_from/sql/withGroupOrderHaving.sql index 679d822040237a..868e42d59abd5c 100644 --- a/regression-test/suites/nereids_p0/select_no_from/sql/withGroupOrderHaving.sql +++ b/regression-test/suites/nereids_p0/select_no_from/sql/withGroupOrderHaving.sql @@ -1,4 +1,8 @@ -/* -- database: presto; groups: no_from -SELECT MIN(10), 3 as col1 GROUP BY 2 HAVING 6 > 5 ORDER BY 1 -*/ +SET enable_nereids_planner = TRUE; +SELECT MIN(10), 3 as col1 GROUP BY 2 HAVING 6 > 5 ORDER BY 1; +SELECT 1 AS a, COUNT(*), SUM(2), AVG(1), RANK() OVER() AS w_rank +WHERE 1 = 1 +GROUP BY a, w_rank +HAVING COUNT(*) IN (1, 2) AND w_rank = 1 +ORDER BY a; \ No newline at end of file diff --git a/regression-test/suites/nereids_p0/select_no_from/sql/withWhereClause.sql b/regression-test/suites/nereids_p0/select_no_from/sql/withWhereClause.sql index 3798fa8d56ec0e..12b501a55999be 100644 --- a/regression-test/suites/nereids_p0/select_no_from/sql/withWhereClause.sql +++ b/regression-test/suites/nereids_p0/select_no_from/sql/withWhereClause.sql @@ -1,4 +1,3 @@ -/* -- database: presto; groups: no_from -SELECT 1 WHERE TRUE AND 2=2 -*/ +SET enable_nereids_planner = TRUE; +SELECT 1 WHERE TRUE AND 2=2; diff --git a/regression-test/suites/nereids_p0/select_no_from/sql/withWhereFalse.sql b/regression-test/suites/nereids_p0/select_no_from/sql/withWhereFalse.sql index c4096c2811a50a..3ffe3058851bb6 100644 --- a/regression-test/suites/nereids_p0/select_no_from/sql/withWhereFalse.sql +++ b/regression-test/suites/nereids_p0/select_no_from/sql/withWhereFalse.sql @@ -1,4 +1,3 @@ -/* -- database: presto; groups: no_from -SELECT COUNT(*), 1 WHERE FALSE -*/ +SET enable_nereids_planner = TRUE; +SELECT COUNT(*), 1 WHERE FALSE; diff --git a/regression-test/suites/query_p0/select_no_from/sql/withGroupOrderHaving.sql b/regression-test/suites/query_p0/select_no_from/sql/withGroupOrderHaving.sql index 679d822040237a..868e42d59abd5c 100644 --- a/regression-test/suites/query_p0/select_no_from/sql/withGroupOrderHaving.sql +++ b/regression-test/suites/query_p0/select_no_from/sql/withGroupOrderHaving.sql @@ -1,4 +1,8 @@ -/* -- database: presto; groups: no_from -SELECT MIN(10), 3 as col1 GROUP BY 2 HAVING 6 > 5 ORDER BY 1 -*/ +SET enable_nereids_planner = TRUE; +SELECT MIN(10), 3 as col1 GROUP BY 2 HAVING 6 > 5 ORDER BY 1; +SELECT 1 AS a, COUNT(*), SUM(2), AVG(1), RANK() OVER() AS w_rank +WHERE 1 = 1 +GROUP BY a, w_rank +HAVING COUNT(*) IN (1, 2) AND w_rank = 1 +ORDER BY a; \ No newline at end of file diff --git a/regression-test/suites/query_p0/select_no_from/sql/withWhereClause.sql b/regression-test/suites/query_p0/select_no_from/sql/withWhereClause.sql index 3798fa8d56ec0e..2f413308dfe9bb 100644 --- a/regression-test/suites/query_p0/select_no_from/sql/withWhereClause.sql +++ b/regression-test/suites/query_p0/select_no_from/sql/withWhereClause.sql @@ -1,4 +1,3 @@ -/* -- database: presto; groups: no_from -SELECT 1 WHERE TRUE AND 2=2 -*/ +SET enable_nereids_planner = TRUE; +SELECT 1 WHERE TRUE AND 2=2; \ No newline at end of file diff --git a/regression-test/suites/query_p0/select_no_from/sql/withWhereFalse.sql b/regression-test/suites/query_p0/select_no_from/sql/withWhereFalse.sql index c4096c2811a50a..774532dc0d2759 100644 --- a/regression-test/suites/query_p0/select_no_from/sql/withWhereFalse.sql +++ b/regression-test/suites/query_p0/select_no_from/sql/withWhereFalse.sql @@ -1,4 +1,3 @@ -/* -- database: presto; groups: no_from -SELECT COUNT(*), 1 WHERE FALSE -*/ +SET enable_nereids_planner = TRUE; +SELECT COUNT(*), 1 WHERE FALSE; \ No newline at end of file