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 7b003264c993b1b..c6f594f20794bab 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 @@ -307,6 +307,7 @@ import org.apache.doris.nereids.trees.plans.LimitPhase; import org.apache.doris.nereids.trees.plans.Plan; import org.apache.doris.nereids.trees.plans.algebra.Aggregate; +import org.apache.doris.nereids.trees.plans.algebra.OneRowRelation; import org.apache.doris.nereids.trees.plans.algebra.SetOperation.Qualifier; import org.apache.doris.nereids.trees.plans.commands.AlterMTMVCommand; import org.apache.doris.nereids.trees.plans.commands.Command; @@ -2414,6 +2415,9 @@ private LogicalPlan withSelectQuerySpecification( } return new LogicalHaving<>(ExpressionUtils.extractConjunctionToSet( getExpression((havingClause.get().booleanExpression()))), project); + } else if (inputRelation instanceof OneRowRelation) { + // If OneRowRelation should not add project, because slot will be wrong when analyze + return withHaving(aggregate, havingClause); } else { LogicalPlan having = withHaving(aggregate, havingClause); return withProjection(having, selectColumnCtx, aggClause, isDistinct); diff --git a/regression-test/data/query_p0/sql_functions/conditional_functions/test_if_cast.out b/regression-test/data/query_p0/sql_functions/conditional_functions/test_if_cast.out index cf64c4da4ac13b0..1fb288a7636df57 100644 --- a/regression-test/data/query_p0/sql_functions/conditional_functions/test_if_cast.out +++ b/regression-test/data/query_p0/sql_functions/conditional_functions/test_if_cast.out @@ -15,5 +15,5 @@ ["1970-01-01"] -- !select -- -[null] +[NULL] diff --git a/regression-test/suites/nereids_syntax_p0/bind_priority.groovy b/regression-test/suites/nereids_syntax_p0/bind_priority.groovy index 536dcddf06cf904..072587ed28eee45 100644 --- a/regression-test/suites/nereids_syntax_p0/bind_priority.groovy +++ b/regression-test/suites/nereids_syntax_p0/bind_priority.groovy @@ -116,7 +116,7 @@ suite("bind_priority") { test{ sql "SELECT a,2 as a FROM (SELECT '1' as a) b HAVING a=1" - exception "a is ambiguous: a#0, a#1." + exception "a is ambiguous: a#1, a#2." } sql "drop table if exists duplicate_slot";