JingsongLi commented on code in PR #2298:
URL: https://github.com/apache/incubator-paimon/pull/2298#discussion_r1392367782


##########
paimon-flink/paimon-flink-common/src/main/java/org/apache/paimon/flink/FlinkExternalCatalog.java:
##########
@@ -0,0 +1,488 @@
+/*
+ * 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.paimon.flink;
+
+import org.apache.paimon.fs.FileIO;
+import org.apache.paimon.fs.FileStatus;
+import org.apache.paimon.fs.Path;
+import org.apache.paimon.utils.JsonSerdeUtil;
+import org.apache.paimon.utils.StringUtils;
+
+import 
org.apache.paimon.shade.jackson2.com.fasterxml.jackson.core.type.TypeReference;
+import 
org.apache.paimon.shade.jackson2.com.fasterxml.jackson.databind.ObjectMapper;
+
+import org.apache.flink.table.api.TableSchema;
+import org.apache.flink.table.catalog.AbstractCatalog;
+import org.apache.flink.table.catalog.CatalogBaseTable;
+import org.apache.flink.table.catalog.CatalogDatabase;
+import org.apache.flink.table.catalog.CatalogFunction;
+import org.apache.flink.table.catalog.CatalogPartition;
+import org.apache.flink.table.catalog.CatalogPartitionSpec;
+import org.apache.flink.table.catalog.CatalogTable;
+import org.apache.flink.table.catalog.Column;
+import org.apache.flink.table.catalog.ObjectPath;
+import org.apache.flink.table.catalog.ResolvedCatalogTable;
+import org.apache.flink.table.catalog.ResolvedSchema;
+import org.apache.flink.table.catalog.UniqueConstraint;
+import org.apache.flink.table.catalog.exceptions.CatalogException;
+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.FunctionAlreadyExistException;
+import org.apache.flink.table.catalog.exceptions.FunctionNotExistException;
+import 
org.apache.flink.table.catalog.exceptions.PartitionAlreadyExistsException;
+import org.apache.flink.table.catalog.exceptions.PartitionNotExistException;
+import org.apache.flink.table.catalog.exceptions.PartitionSpecInvalidException;
+import org.apache.flink.table.catalog.exceptions.TableAlreadyExistException;
+import org.apache.flink.table.catalog.exceptions.TableNotExistException;
+import org.apache.flink.table.catalog.exceptions.TableNotPartitionedException;
+import org.apache.flink.table.catalog.exceptions.TablePartitionedException;
+import org.apache.flink.table.catalog.stats.CatalogColumnStatistics;
+import org.apache.flink.table.catalog.stats.CatalogTableStatistics;
+import org.apache.flink.table.descriptors.DescriptorProperties;
+import org.apache.flink.table.expressions.Expression;
+
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+import static org.apache.flink.table.factories.FactoryUtil.CONNECTOR;
+
+/** Catalog for persisting external tables. */
+public class FlinkExternalCatalog extends AbstractCatalog {
+
+    private final FlinkCatalog paimon;
+    private final String warehousePath;
+
+    private static final String EXTERNAL_TABLE_STORE_PATH = "TABLE";
+    private static final String EXTERNAL_FUNCTION_STORE_PATH = "FUNCTION";
+    private final FileIO fileIO;
+    private final String systemDbDir;
+
+    private final String externalFunctionDir;
+
+    private final String externalTableDir;
+
+    public FlinkExternalCatalog(FlinkCatalog paimon, FileIO fileIO, String 
warehousePath) {
+        super(paimon.getName(), paimon.getDefaultDatabase());
+        this.paimon = paimon;
+        this.fileIO = fileIO;
+        this.warehousePath = warehousePath;
+        this.systemDbDir =
+                this.warehousePath + Path.SEPARATOR + 
"FLINK_EXTERNAL_METADATA" + Path.SEPARATOR;
+        externalFunctionDir = systemDbDir + EXTERNAL_FUNCTION_STORE_PATH + 
Path.SEPARATOR;
+        externalTableDir = systemDbDir + EXTERNAL_TABLE_STORE_PATH + 
Path.SEPARATOR;
+        try {
+            fileIO.mkdirs(new Path(externalTableDir));
+        } catch (IOException ignore) {
+
+        }
+        try {
+            fileIO.mkdirs(new Path(externalFunctionDir));
+        } catch (IOException ignore) {
+
+        }
+    }
+
+    public org.apache.paimon.catalog.Catalog catalog() {
+        return paimon.catalog();
+    }
+
+    private String externalTableSchemaDir(ObjectPath table) {
+        return externalTableDir
+                + Path.SEPARATOR
+                + table.getDatabaseName()
+                + Path.SEPARATOR
+                + table.getObjectName()
+                + Path.SEPARATOR;
+    }
+
+    @Override
+    public void open() throws CatalogException {
+        paimon.open();
+    }
+
+    @Override
+    public void close() throws CatalogException {
+        paimon.close();
+    }
+
+    @Override
+    public List<String> listDatabases() throws CatalogException {
+        return paimon.listDatabases();

Review Comment:
   Do we need to list databases for external tables?



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

Reply via email to