neuyilan commented on code in PR #4891:
URL: https://github.com/apache/paimon/pull/4891#discussion_r1919868498


##########
paimon-common/src/main/java/org/apache/paimon/fs/ResolvingFileIO.java:
##########
@@ -0,0 +1,141 @@
+/*
+ * 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.fs;
+
+import org.apache.paimon.annotation.VisibleForTesting;
+import org.apache.paimon.catalog.CatalogContext;
+import org.apache.paimon.options.CatalogOptions;
+
+import java.io.IOException;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * An implementation of {@link FileIO} that supports multiple file system 
schemas. It dynamically
+ * selects the appropriate {@link FileIO} based on the URI scheme of the given 
path.
+ */
+public class ResolvingFileIO implements FileIO {
+    private static final long serialVersionUID = 1L;
+
+    private CatalogContext context;
+
+    private Map<String, FileIO> fileIOMap;
+    private volatile FileIO fallbackFileIO;
+
+    // TODO, how to decide the real fileio is object store or not?
+    @Override
+    public boolean isObjectStore() {
+        String warehouse = context.options().get(CatalogOptions.WAREHOUSE);
+        if (warehouse == null) {
+            return false;
+        }
+        Path path = new Path(warehouse);
+        String scheme = path.toUri().getScheme();
+        return scheme != null
+                && !scheme.equalsIgnoreCase("file")
+                && !scheme.equalsIgnoreCase("hdfs");
+    }
+
+    @Override
+    public void configure(CatalogContext context) {
+        this.context = context;
+        this.fileIOMap = new ConcurrentHashMap<>();
+    }
+
+    @Override
+    public SeekableInputStream newInputStream(Path path) throws IOException {
+        return wrap(() -> fileIO(path).newInputStream(path));
+    }
+
+    @Override
+    public PositionOutputStream newOutputStream(Path path, boolean overwrite) 
throws IOException {
+        return wrap(() -> fileIO(path).newOutputStream(path, overwrite));
+    }
+
+    @Override
+    public FileStatus getFileStatus(Path path) throws IOException {
+        return wrap(() -> fileIO(path).getFileStatus(path));
+    }
+
+    @Override
+    public FileStatus[] listStatus(Path path) throws IOException {
+        return wrap(() -> fileIO(path).listStatus(path));
+    }
+
+    @Override
+    public boolean exists(Path path) throws IOException {
+        return wrap(() -> fileIO(path).exists(path));
+    }
+
+    @Override
+    public boolean delete(Path path, boolean recursive) throws IOException {
+        return wrap(() -> fileIO(path).delete(path, recursive));
+    }
+
+    @Override
+    public boolean mkdirs(Path path) throws IOException {
+        return wrap(() -> fileIO(path).mkdirs(path));
+    }
+
+    @Override
+    public boolean rename(Path src, Path dst) throws IOException {
+        return wrap(() -> fileIO(src).rename(src, dst));
+    }
+
+    @VisibleForTesting
+    public FileIO fileIO(Path path) throws IOException {
+        String scheme = path.toUri().getScheme();

Review Comment:
   Yes,we can implement it as OSSFileIO.Cachekey class



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