[feature](nereids) support unnest subquery in LogicalOneRowRelation (#24355)
select (select 1); before : ERROR 1105 (HY000): errCode = 2, detailMessage = Subquery is not supported in the select list. after: mysql> select (select 1); +---------------------------------------------------------------------+ | (SCALARSUBQUERY) (LogicalOneRowRelation ( projects=[1 AS `1`#0] )) | +---------------------------------------------------------------------+ | 1 | +---------------------------------------------------------------------+ 1 row in set (0.61 sec)
This commit is contained in:
@ -122,6 +122,7 @@ public enum RuleType {
|
||||
// subquery analyze
|
||||
FILTER_SUBQUERY_TO_APPLY(RuleTypeClass.REWRITE),
|
||||
PROJECT_SUBQUERY_TO_APPLY(RuleTypeClass.REWRITE),
|
||||
ONE_ROW_RELATION_SUBQUERY_TO_APPLY(RuleTypeClass.REWRITE),
|
||||
// subquery rewrite rule
|
||||
ELIMINATE_LIMIT_UNDER_APPLY(RuleTypeClass.REWRITE),
|
||||
ELIMINATE_SORT_UNDER_APPLY(RuleTypeClass.REWRITE),
|
||||
|
||||
@ -21,6 +21,7 @@ import org.apache.doris.nereids.CascadesContext;
|
||||
import org.apache.doris.nereids.StatementContext;
|
||||
import org.apache.doris.nereids.rules.Rule;
|
||||
import org.apache.doris.nereids.rules.RuleType;
|
||||
import org.apache.doris.nereids.trees.expressions.Alias;
|
||||
import org.apache.doris.nereids.trees.expressions.BinaryOperator;
|
||||
import org.apache.doris.nereids.trees.expressions.Exists;
|
||||
import org.apache.doris.nereids.trees.expressions.Expression;
|
||||
@ -37,6 +38,7 @@ import org.apache.doris.nereids.trees.plans.Plan;
|
||||
import org.apache.doris.nereids.trees.plans.algebra.Aggregate;
|
||||
import org.apache.doris.nereids.trees.plans.logical.LogicalApply;
|
||||
import org.apache.doris.nereids.trees.plans.logical.LogicalFilter;
|
||||
import org.apache.doris.nereids.trees.plans.logical.LogicalOneRowRelation;
|
||||
import org.apache.doris.nereids.trees.plans.logical.LogicalPlan;
|
||||
import org.apache.doris.nereids.trees.plans.logical.LogicalProject;
|
||||
|
||||
@ -149,7 +151,21 @@ public class SubqueryToApply implements AnalysisRuleFactory {
|
||||
}
|
||||
|
||||
return project.withProjectsAndChild(newProjects.build(), childPlan);
|
||||
}))
|
||||
})),
|
||||
RuleType.ONE_ROW_RELATION_SUBQUERY_TO_APPLY.build(logicalOneRowRelation()
|
||||
.when(ctx -> ctx.getProjects().stream()
|
||||
.anyMatch(project -> project.containsType(SubqueryExpr.class)))
|
||||
.thenApply(ctx -> {
|
||||
LogicalOneRowRelation oneRowRelation = ctx.root;
|
||||
// create a LogicalProject node with the same project lists above LogicalOneRowRelation
|
||||
// create a LogicalOneRowRelation with a dummy output column
|
||||
// so PROJECT_SUBQUERY_TO_APPLY rule can handle the subquery unnest thing
|
||||
return new LogicalProject<Plan>(oneRowRelation.getProjects(),
|
||||
oneRowRelation.withProjects(
|
||||
ImmutableList.of(new Alias(BooleanLiteral.of(true),
|
||||
ctx.statementContext.generateColumnName()))));
|
||||
}
|
||||
))
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user