Refactor QueryExplainer to reduce code duplication
@@ -76,10 +76,10 @@ public class QueryExplainer
this.dataDefinitionTask = ImmutableMap.copyOf(requireNonNull(dataDefinitionTask, "dataDefinitionTask is null"));
}
- public void analyze(Session session, Statement statement, List<Expression> parameters)
+ public Analysis analyze(Session session, Statement statement, List<Expression> parameters)
{
Analyzer analyzer = new Analyzer(session, metadata, sqlParser, accessControl, Optional.of(this), parameters);
- analyzer.analyze(statement);
+ return analyzer.analyze(statement);
}
public String getPlan(Session session, Statement statement, Type planType, List<Expression> parameters)
@@ -127,9 +127,8 @@ public class QueryExplainer
private Plan getLogicalPlan(Session session, Statement statement, List<Expression> parameters)
{
// analyze statement
- Analyzer analyzer = new Analyzer(session, metadata, sqlParser, accessControl, Optional.of(this), parameters);
+ Analysis analysis = analyze(session, statement, parameters);
- Analysis analysis = analyzer.analyze(statement);
PlanNodeIdAllocator idAllocator = new PlanNodeIdAllocator();
// plan statement
@@ -139,16 +138,7 @@ public class QueryExplainer
private SubPlan getDistributedPlan(Session session, Statement statement, List<Expression> parameters)
{
- // analyze statement
- Analyzer analyzer = new Analyzer(session, metadata, sqlParser, accessControl, Optional.of(this), parameters);
-
- Analysis analysis = analyzer.analyze(statement);
- PlanNodeIdAllocator idAllocator = new PlanNodeIdAllocator();
-
- // plan statement
- LogicalPlanner logicalPlanner = new LogicalPlanner(session, planOptimizers, idAllocator, metadata, sqlParser);
- Plan plan = logicalPlanner.plan(analysis);
-
+ Plan plan = getLogicalPlan(session, statement, parameters);
return PlanFragmenter.createSubPlans(session, metadata, plan);
}
}
