twalthr commented on a change in pull request #8404: [FLINK-11476][table] 
Create CatalogManager to manage multiple catalogs
URL: https://github.com/apache/flink/pull/8404#discussion_r283650634
 
 

 ##########
 File path: 
flink-table/flink-table-planner/src/main/java/org/apache/flink/table/planner/PlanningConfigurationBuilder.java
 ##########
 @@ -0,0 +1,202 @@
+/*
+ * 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.flink.table.planner;
+
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.table.api.TableConfig;
+import org.apache.flink.table.calcite.CalciteConfig;
+import org.apache.flink.table.calcite.FlinkRelBuilder;
+import org.apache.flink.table.calcite.FlinkRelBuilderFactory;
+import org.apache.flink.table.calcite.FlinkRelOptClusterFactory;
+import org.apache.flink.table.calcite.FlinkTypeFactory;
+import org.apache.flink.table.calcite.FlinkTypeSystem;
+import org.apache.flink.table.codegen.ExpressionReducer;
+import org.apache.flink.table.expressions.ExpressionBridge;
+import org.apache.flink.table.expressions.PlannerExpression;
+import org.apache.flink.table.plan.TableOperationConverter;
+import org.apache.flink.table.plan.cost.DataSetCostFactory;
+import org.apache.flink.table.util.JavaScalaConversionUtil;
+import org.apache.flink.table.validate.FunctionCatalog;
+
+import org.apache.calcite.config.Lex;
+import org.apache.calcite.jdbc.CalciteSchema;
+import org.apache.calcite.plan.Context;
+import org.apache.calcite.plan.Contexts;
+import org.apache.calcite.plan.ConventionTraitDef;
+import org.apache.calcite.plan.RelOptCluster;
+import org.apache.calcite.plan.RelOptCostFactory;
+import org.apache.calcite.plan.RelOptPlanner;
+import org.apache.calcite.plan.RelOptSchema;
+import org.apache.calcite.plan.volcano.VolcanoPlanner;
+import org.apache.calcite.prepare.CalciteCatalogReader;
+import org.apache.calcite.rel.type.RelDataTypeSystem;
+import org.apache.calcite.rex.RexBuilder;
+import org.apache.calcite.schema.SchemaPlus;
+import org.apache.calcite.sql.SqlOperatorTable;
+import org.apache.calcite.sql.parser.SqlParser;
+import org.apache.calcite.sql.util.ChainedSqlOperatorTable;
+import org.apache.calcite.sql2rel.SqlToRelConverter;
+import org.apache.calcite.tools.FrameworkConfig;
+import org.apache.calcite.tools.Frameworks;
+
+import java.util.List;
+
+/**
+ * Utility class to create {@link org.apache.calcite.tools.RelBuilder} or 
{@link FrameworkConfig} used to create
+ * a corresponding {@link org.apache.calcite.tools.Planner}. It tries to 
separate static elements in a
+ * {@link org.apache.flink.table.api.TableEnvironment} like: root schema, cost 
factory, type system etc.
+ * from a dynamic properties like e.g. default path to look for objects in the 
schema.
+ */
+@Internal
+public class PlanningConfigurationBuilder {
+       private static final RelOptCostFactory COST_FACTORY = new 
DataSetCostFactory();
+       private static final RelDataTypeSystem TYPE_SYSTEM = new 
FlinkTypeSystem();
+       private static final FlinkTypeFactory TYPE_FACTORY = new 
FlinkTypeFactory(TYPE_SYSTEM);
+       private final RelOptPlanner planner;
+       private final ExpressionBridge<PlannerExpression> expressionBridge;
+       private final Context context;
+       private final TableConfig tableConfig;
+       private final FunctionCatalog functionCatalog;
+       private CalciteSchema rootSchema;
+
+       public PlanningConfigurationBuilder(
+               TableConfig tableConfig,
+               FunctionCatalog functionCatalog,
+               CalciteSchema rootSchema,
+               ExpressionBridge<PlannerExpression> expressionBridge) {
+               this.tableConfig = tableConfig;
+               this.functionCatalog = functionCatalog;
+
+               // create context instances with Flink type factory
+               this.context = Contexts.of(
+                       new 
TableOperationConverter.ToRelConverterSupplier(expressionBridge)
+               );
+
+               this.planner = new VolcanoPlanner(COST_FACTORY, context);
+               planner.setExecutor(new ExpressionReducer(tableConfig));
+               planner.addRelTraitDef(ConventionTraitDef.INSTANCE);
+
+               this.expressionBridge = expressionBridge;
+
+               this.rootSchema = rootSchema;
+       }
+
+       /**
+        * Creates a configured {@link FlinkRelBuilder} for a planning session.
+        *
+        * @param defaultSchema the default schema to look for first during 
planning.
+        * @return configured rel builder
+        */
+       public FlinkRelBuilder createRelBuilder(List<String> defaultSchema) {
+               RelOptCluster cluster = 
FlinkRelOptClusterFactory.create(planner, new RexBuilder(TYPE_FACTORY));
+               RelOptSchema relOptSchema = new CalciteCatalogReader(
+                       rootSchema,
+                       defaultSchema,
+                       TYPE_FACTORY,
+                       
CalciteConfig.connectionConfig(getSqlParserConfig(calciteConfig(tableConfig))));
+
+               return new FlinkRelBuilder(context, cluster, relOptSchema, 
expressionBridge);
+       }
+
+       /** Returns the Calcite [[org.apache.calcite.plan.RelOptPlanner]] of 
this TableEnvironment. */
 
 Review comment:
   Update comment here and below to Java.

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to