[fix](Nereids) should only do bind relation in view analyzer (#28637)
This commit is contained in:
@ -211,11 +211,19 @@ public class CascadesContext implements ScheduleContext {
|
||||
}
|
||||
|
||||
public Analyzer newAnalyzer() {
|
||||
return new Analyzer(this);
|
||||
return newAnalyzer(false);
|
||||
}
|
||||
|
||||
public Analyzer newAnalyzer(boolean analyzeView) {
|
||||
return new Analyzer(this, analyzeView);
|
||||
}
|
||||
|
||||
public Analyzer newAnalyzer(boolean analyzeView, Optional<CustomTableResolver> customTableResolver) {
|
||||
return new Analyzer(this, analyzeView, customTableResolver);
|
||||
}
|
||||
|
||||
public Analyzer newAnalyzer(Optional<CustomTableResolver> customTableResolver) {
|
||||
return new Analyzer(this, customTableResolver);
|
||||
return newAnalyzer(false, customTableResolver);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -56,6 +56,7 @@ import java.util.Optional;
|
||||
public class Analyzer extends AbstractBatchJobExecutor {
|
||||
|
||||
public static final List<RewriteJob> DEFAULT_ANALYZE_JOBS = buildAnalyzeJobs(Optional.empty());
|
||||
public static final List<RewriteJob> DEFAULT_ANALYZE_VIEW_JOBS = buildAnalyzeViewJobs(Optional.empty());
|
||||
|
||||
private final List<RewriteJob> jobs;
|
||||
|
||||
@ -64,13 +65,37 @@ public class Analyzer extends AbstractBatchJobExecutor {
|
||||
* @param cascadesContext planner context for execute job
|
||||
*/
|
||||
public Analyzer(CascadesContext cascadesContext) {
|
||||
this(cascadesContext, Optional.empty());
|
||||
this(cascadesContext, false);
|
||||
}
|
||||
|
||||
public Analyzer(CascadesContext cascadesContext, Optional<CustomTableResolver> customTableResolver) {
|
||||
public Analyzer(CascadesContext cascadesContext, boolean analyzeView) {
|
||||
this(cascadesContext, analyzeView, Optional.empty());
|
||||
}
|
||||
|
||||
/**
|
||||
* constructor of Analyzer. For view, we only do bind relation since other analyze step will do by outer Analyzer.
|
||||
*
|
||||
* @param cascadesContext current context for analyzer
|
||||
* @param analyzeView analyze view or user sql. If true, analyzer is used for view.
|
||||
* @param customTableResolver custom resolver for outer catalog.
|
||||
*/
|
||||
public Analyzer(CascadesContext cascadesContext, boolean analyzeView,
|
||||
Optional<CustomTableResolver> customTableResolver) {
|
||||
super(cascadesContext);
|
||||
Objects.requireNonNull(customTableResolver, "customTableResolver cannot be null");
|
||||
this.jobs = !customTableResolver.isPresent() ? DEFAULT_ANALYZE_JOBS : buildAnalyzeJobs(customTableResolver);
|
||||
if (analyzeView) {
|
||||
if (customTableResolver.isPresent()) {
|
||||
this.jobs = buildAnalyzeViewJobs(customTableResolver);
|
||||
} else {
|
||||
this.jobs = DEFAULT_ANALYZE_VIEW_JOBS;
|
||||
}
|
||||
} else {
|
||||
if (customTableResolver.isPresent()) {
|
||||
this.jobs = buildAnalyzeJobs(customTableResolver);
|
||||
} else {
|
||||
this.jobs = DEFAULT_ANALYZE_JOBS;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -85,6 +110,18 @@ public class Analyzer extends AbstractBatchJobExecutor {
|
||||
execute();
|
||||
}
|
||||
|
||||
private static List<RewriteJob> buildAnalyzeViewJobs(Optional<CustomTableResolver> customTableResolver) {
|
||||
return jobs(
|
||||
topDown(new AnalyzeCTE()),
|
||||
topDown(new EliminateLogicalSelectHint()),
|
||||
bottomUp(
|
||||
new BindRelation(customTableResolver),
|
||||
new CheckPolicy(),
|
||||
new UserAuthentication()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
private static List<RewriteJob> buildAnalyzeJobs(Optional<CustomTableResolver> customTableResolver) {
|
||||
return jobs(
|
||||
// we should eliminate hint before "Subquery unnesting".
|
||||
@ -93,9 +130,9 @@ public class Analyzer extends AbstractBatchJobExecutor {
|
||||
bottomUp(
|
||||
new BindRelation(customTableResolver),
|
||||
new CheckPolicy(),
|
||||
new UserAuthentication(),
|
||||
new BindExpression()
|
||||
new UserAuthentication()
|
||||
),
|
||||
bottomUp(new BindExpression()),
|
||||
topDown(new BindSink()),
|
||||
bottomUp(new CheckAfterBind()),
|
||||
bottomUp(
|
||||
|
||||
@ -47,6 +47,7 @@ import org.apache.doris.nereids.trees.expressions.Slot;
|
||||
import org.apache.doris.nereids.trees.expressions.literal.TinyIntLiteral;
|
||||
import org.apache.doris.nereids.trees.plans.Plan;
|
||||
import org.apache.doris.nereids.trees.plans.PreAggStatus;
|
||||
import org.apache.doris.nereids.trees.plans.algebra.Relation;
|
||||
import org.apache.doris.nereids.trees.plans.logical.LogicalCTEConsumer;
|
||||
import org.apache.doris.nereids.trees.plans.logical.LogicalEsScan;
|
||||
import org.apache.doris.nereids.trees.plans.logical.LogicalFileScan;
|
||||
@ -89,7 +90,7 @@ public class BindRelation extends OneAnalysisRuleFactory {
|
||||
public Rule build() {
|
||||
return unboundRelation().thenApply(ctx -> {
|
||||
Plan plan = doBindRelation(ctx);
|
||||
if (!(plan instanceof Unbound)) {
|
||||
if (!(plan instanceof Unbound) && plan instanceof Relation) {
|
||||
// init output and allocate slot id immediately, so that the slot id increase
|
||||
// in the order in which the table appears.
|
||||
LogicalProperties logicalProperties = plan.getLogicalProperties();
|
||||
@ -268,7 +269,7 @@ public class BindRelation extends OneAnalysisRuleFactory {
|
||||
}
|
||||
CascadesContext viewContext = CascadesContext.initContext(
|
||||
parentContext.getStatementContext(), parsedViewPlan, PhysicalProperties.ANY);
|
||||
viewContext.newAnalyzer().analyze();
|
||||
viewContext.newAnalyzer(true, customTableResolver).analyze();
|
||||
// we should remove all group expression of the plan which in other memo, so the groupId would not conflict
|
||||
return viewContext.getRewritePlan();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user