strongduanmu commented on a change in pull request #11930:
URL: https://github.com/apache/shardingsphere/pull/11930#discussion_r707855317
##########
File path:
shardingsphere-infra/shardingsphere-infra-optimize/src/main/java/org/apache/shardingsphere/infra/optimize/context/OptimizeContextFactory.java
##########
@@ -156,7 +156,7 @@ private void initProperties(final DatabaseType
databaseType) {
}
private RelOptCluster newCluster() {
- RelOptPlanner planner = new VolcanoPlanner();
+ RelOptPlanner planner = new VolcanoPlanner(null, null);
Review comment:
@wgy8283335 Why add null param?
##########
File path:
shardingsphere-infra/shardingsphere-infra-optimize/src/main/java/org/apache/shardingsphere/infra/optimize/ShardingSphereOptimizer.java
##########
@@ -49,16 +61,27 @@ public RelNode optimize(final String sql) throws
SQLParsingException {
ShardingSphereSQLParserEngine sqlParserEngine = new
ShardingSphereSQLParserEngine(DatabaseTypeRegistry.getTrunkDatabaseTypeName(context.getDatabaseType()));
SqlNode sqlNode =
SqlNodeConvertEngine.convert(sqlParserEngine.parse(sql, true));
SqlNode validNode = context.getValidator().validate(sqlNode);
+ RelDataType resultType =
context.getValidator().getValidatedNodeType(sqlNode);
RelNode logicPlan =
context.getRelConverter().convertQuery(validNode, false, true).rel;
- return optimize(logicPlan);
+ return optimize(logicPlan, resultType);
} catch (final UnsupportedOperationException ex) {
throw new ShardingSphereException(ex);
}
}
- private RelNode optimize(final RelNode logicPlan) {
+ private RelNode optimize(final RelNode logicPlan, final RelDataType
resultType) {
RelOptPlanner planner =
context.getRelConverter().getCluster().getPlanner();
- planner.setRoot(planner.changeTraits(logicPlan,
context.getRelConverter().getCluster().traitSet().replace(EnumerableConvention.INSTANCE)));
- return planner.findBestExp();
+ RelNode node = planner.changeTraits(logicPlan,
context.getRelConverter().getCluster().traitSet().replace(EnumerableConvention.INSTANCE));
+ RelRoot root = constructRoot(node, resultType);
+ FederateOptimizer optimizer = new FederateOptimizer(planner);
+ RelRoot result = optimizer.optimize(root);
+ return result.rel;
+ }
+
+ private RelRoot constructRoot(final RelNode node, final RelDataType
resultType) {
+ final RelDataType rowType = node.getRowType();
+ final List<Pair<Integer, String>> fields =
Pair.zip(ImmutableIntList.identity(rowType.getFieldCount()),
rowType.getFieldNames());
Review comment:
@wgy8283335 Can we remove this useless final modifier?
##########
File path:
shardingsphere-infra/shardingsphere-infra-optimize/src/main/java/org/apache/shardingsphere/infra/optimize/core/prepare/FederateOptimizer.java
##########
@@ -0,0 +1,53 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.infra.optimize.core.prepare;
+
+import com.google.common.collect.ImmutableList;
+import lombok.AllArgsConstructor;
+import org.apache.calcite.adapter.enumerable.EnumerableConvention;
+import org.apache.calcite.plan.RelOptPlanner;
+import org.apache.calcite.plan.RelTraitSet;
+import org.apache.calcite.rel.RelNode;
+import org.apache.calcite.rel.RelRoot;
+import org.apache.calcite.tools.Program;
+import org.apache.calcite.tools.Programs;
+
+@AllArgsConstructor
+public class FederateOptimizer {
Review comment:
@wgy8283335 Please add final for FederateOptimizer.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]