dawidwys 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_r283915654
 
 

 ##########
 File path: 
flink-table/flink-table-planner/src/main/java/org/apache/flink/table/catalog/DatabaseCalciteSchema.java
 ##########
 @@ -0,0 +1,126 @@
+/*
+ * 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.catalog;
+
+import org.apache.flink.table.api.TableException;
+import org.apache.flink.table.catalog.exceptions.CatalogException;
+import org.apache.flink.table.catalog.exceptions.DatabaseNotExistException;
+
+import org.apache.calcite.linq4j.tree.Expression;
+import org.apache.calcite.rel.type.RelProtoDataType;
+import org.apache.calcite.schema.Function;
+import org.apache.calcite.schema.Schema;
+import org.apache.calcite.schema.SchemaPlus;
+import org.apache.calcite.schema.SchemaVersion;
+import org.apache.calcite.schema.Schemas;
+import org.apache.calcite.schema.Table;
+
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * A mapping between Flink catalog's database and Calcite's schema.
+ * Tables are registered as tables in the schema.
+ */
+class DatabaseCalciteSchema implements Schema {
+       private final String dbName;
+       private final Catalog catalog;
+
+       public DatabaseCalciteSchema(String dbName, Catalog catalog) {
+               this.dbName = dbName;
+               this.catalog = catalog;
+       }
+
+       @Override
+       public Table getTable(String tableName) {
+
+               ObjectPath tablePath = new ObjectPath(dbName, tableName);
+
+               try {
+                       if (!catalog.tableExists(tablePath)) {
+                               return null;
+                       }
+
+                       CatalogBaseTable table = catalog.getTable(tablePath);
+
+                       if (table instanceof CalciteCatalogTable) {
+                               return ((CalciteCatalogTable) table).getTable();
+                       } else {
+                               throw new TableException("Unsupported table 
type: " + table);
+                       }
+               } catch (Exception e) {
+                       throw new TableException("Could not find table: " + 
tableName, e);
 
 Review comment:
   Actually we should never end up here with `TableNotExistException` as we are 
checking `catalog.tableExist()` before. That's why I went with `TableExceptin` 
here.
   
   I added appropriate comment there.

----------------------------------------------------------------
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:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to