sunjincheng121 commented on a change in pull request #8007: 
[FLINK-11474][table] Add ReadableCatalog, ReadableWritableCatalog, and other …
URL: https://github.com/apache/flink/pull/8007#discussion_r273781229
 
 

 ##########
 File path: 
flink-table/flink-table-common/src/main/java/org/apache/flink/table/catalog/GenericInMemoryCatalog.java
 ##########
 @@ -0,0 +1,319 @@
+/*
+ * 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.catalog.exceptions.DatabaseAlreadyExistException;
+import org.apache.flink.table.catalog.exceptions.DatabaseNotEmptyException;
+import org.apache.flink.table.catalog.exceptions.DatabaseNotExistException;
+import org.apache.flink.table.catalog.exceptions.TableAlreadyExistException;
+import org.apache.flink.table.catalog.exceptions.TableNotExistException;
+import org.apache.flink.util.StringUtils;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+import static org.apache.flink.util.Preconditions.checkArgument;
+
+/**
+ * A generic catalog implementation that holds all meta objects in memory.
+ */
+public class GenericInMemoryCatalog implements ReadableWritableCatalog {
+
+       public static final String DEFAULT_DB = "default";
+
+       private String currentDatabase = DEFAULT_DB;
+
+       private final String catalogName;
+       private final Map<String, CatalogDatabase> databases;
+       private final Map<ObjectPath, CommonTable> tables;
+
+       public GenericInMemoryCatalog(String name) {
+               checkArgument(!StringUtils.isNullOrWhitespaceOnly(name), "name 
cannot be null or empty");
+
+               this.catalogName = name;
+               this.databases = new LinkedHashMap<>();
+               this.databases.put(DEFAULT_DB, new GenericCatalogDatabase(new 
HashMap<>()));
+               this.tables = new LinkedHashMap<>();
+       }
+
+       @Override
+       public String getCurrentDatabase() {
+               return currentDatabase;
+       }
+
+       @Override
+       public void setCurrentDatabase(String databaseName) throws 
DatabaseNotExistException {
+               
checkArgument(!StringUtils.isNullOrWhitespaceOnly(databaseName));
+
+               if (!databaseExists(databaseName)) {
+                       throw new DatabaseNotExistException(catalogName, 
databaseName);
+               }
+
+               currentDatabase = databaseName;
+       }
+
+       @Override
+       public void open() {
+
+       }
+
+       @Override
+       public void close() {
+
+       }
+
+       // ------ databases ------
 
 Review comment:
   Move // ------ databases ------ before the getCurrentDatabase method.

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