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


##########
paimon-common/src/main/java/org/apache/paimon/fs/HybridFileIO.java:
##########
@@ -0,0 +1,135 @@
+/*
+ * 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.Options;
+
+import java.io.IOException;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * A hybrid 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 HybridFileIO implements FileIO {
+    private static final long serialVersionUID = 1L;
+
+    protected Options options;
+
+    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() {
+        return false;
+    }
+
+    @Override
+    public void configure(CatalogContext context) {
+        this.options = context.options();
+        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();
+        if (scheme == null) {
+            if (fallbackFileIO == null) {

Review Comment:
   Why to create fallbackFileIO lazily?



-- 
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: issues-unsubscr...@paimon.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to