You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by zh...@apache.org on 2021/09/25 07:26:35 UTC
[shardingsphere] branch master updated: Refactor
QueryOptimizePlannerFactory (#12708)
This is an automated email from the ASF dual-hosted git repository.
zhonghongsheng pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new e698853 Refactor QueryOptimizePlannerFactory (#12708)
e698853 is described below
commit e698853bcf78685306f8e8512c957f6c60cb94d2
Author: Liang Zhang <te...@163.com>
AuthorDate: Sat Sep 25 15:25:59 2021 +0800
Refactor QueryOptimizePlannerFactory (#12708)
---
.../TranslatableOptimizerContextFactory.java | 8 ++------
...lizer.java => QueryOptimizePlannerFactory.java} | 23 +++++++++++++++++-----
2 files changed, 20 insertions(+), 11 deletions(-)
diff --git a/shardingsphere-infra/shardingsphere-infra-optimize/src/main/java/org/apache/shardingsphere/infra/optimize/context/translatable/TranslatableOptimizerContextFactory.java b/shardingsphere-infra/shardingsphere-infra-optimize/src/main/java/org/apache/shardingsphere/infra/optimize/context/translatable/TranslatableOptimizerContextFactory.java
index 996db13..ee8b16d 100644
--- a/shardingsphere-infra/shardingsphere-infra-optimize/src/main/java/org/apache/shardingsphere/infra/optimize/context/translatable/TranslatableOptimizerContextFactory.java
+++ b/shardingsphere-infra/shardingsphere-infra-optimize/src/main/java/org/apache/shardingsphere/infra/optimize/context/translatable/TranslatableOptimizerContextFactory.java
@@ -25,9 +25,7 @@ import org.apache.calcite.config.CalciteConnectionProperty;
import org.apache.calcite.jdbc.CalciteSchema;
import org.apache.calcite.jdbc.JavaTypeFactoryImpl;
import org.apache.calcite.plan.RelOptCluster;
-import org.apache.calcite.plan.RelOptPlanner;
import org.apache.calcite.plan.RelOptTable.ViewExpander;
-import org.apache.calcite.plan.volcano.VolcanoPlanner;
import org.apache.calcite.prepare.CalciteCatalogReader;
import org.apache.calcite.rel.type.RelDataTypeFactory;
import org.apache.calcite.rex.RexBuilder;
@@ -38,7 +36,7 @@ import org.apache.calcite.sql.validate.SqlValidatorUtil;
import org.apache.calcite.sql2rel.SqlToRelConverter;
import org.apache.calcite.sql2rel.StandardConvertletTable;
import org.apache.shardingsphere.infra.database.type.DatabaseType;
-import org.apache.shardingsphere.infra.optimize.plan.PlannerInitializer;
+import org.apache.shardingsphere.infra.optimize.plan.QueryOptimizePlannerFactory;
import java.util.Collections;
import java.util.Properties;
@@ -95,8 +93,6 @@ public final class TranslatableOptimizerContextFactory {
}
private static RelOptCluster createCluster(final RelDataTypeFactory relDataTypeFactory) {
- RelOptPlanner planner = new VolcanoPlanner();
- PlannerInitializer.init(planner);
- return RelOptCluster.create(planner, new RexBuilder(relDataTypeFactory));
+ return RelOptCluster.create(QueryOptimizePlannerFactory.newInstance(), new RexBuilder(relDataTypeFactory));
}
}
diff --git a/shardingsphere-infra/shardingsphere-infra-optimize/src/main/java/org/apache/shardingsphere/infra/optimize/plan/PlannerInitializer.java b/shardingsphere-infra/shardingsphere-infra-optimize/src/main/java/org/apache/shardingsphere/infra/optimize/plan/QueryOptimizePlannerFactory.java
similarity index 73%
rename from shardingsphere-infra/shardingsphere-infra-optimize/src/main/java/org/apache/shardingsphere/infra/optimize/plan/PlannerInitializer.java
rename to shardingsphere-infra/shardingsphere-infra-optimize/src/main/java/org/apache/shardingsphere/infra/optimize/plan/QueryOptimizePlannerFactory.java
index e4f943e..f2f3145 100644
--- a/shardingsphere-infra/shardingsphere-infra-optimize/src/main/java/org/apache/shardingsphere/infra/optimize/plan/PlannerInitializer.java
+++ b/shardingsphere-infra/shardingsphere-infra-optimize/src/main/java/org/apache/shardingsphere/infra/optimize/plan/QueryOptimizePlannerFactory.java
@@ -22,19 +22,32 @@ import lombok.NoArgsConstructor;
import org.apache.calcite.adapter.enumerable.EnumerableRules;
import org.apache.calcite.plan.ConventionTraitDef;
import org.apache.calcite.plan.RelOptPlanner;
+import org.apache.calcite.plan.volcano.VolcanoPlanner;
import org.apache.calcite.rel.rules.CoreRules;
/**
- * planner initializer.
+ * Query optimize planner factory.
*/
@NoArgsConstructor(access = AccessLevel.PRIVATE)
-public final class PlannerInitializer {
+public final class QueryOptimizePlannerFactory {
/**
- * Init.
- * @param planner planner
+ * Create new instance of query optimize planner.
+ *
+ * @return new instance of query optimize planner
*/
- public static void init(final RelOptPlanner planner) {
+ public static RelOptPlanner newInstance() {
+ RelOptPlanner result = createPlanner();
+ setUpRules(result);
+ return result;
+ }
+
+ private static RelOptPlanner createPlanner() {
+ // TODO consider about HepPlanner
+ return new VolcanoPlanner();
+ }
+
+ private static void setUpRules(final RelOptPlanner planner) {
planner.addRule(CoreRules.PROJECT_TO_CALC);
planner.addRule(CoreRules.FILTER_TO_CALC);
planner.addRule(EnumerableRules.ENUMERABLE_LIMIT_RULE);