jerryshao commented on code in PR #5020:
URL: https://github.com/apache/gravitino/pull/5020#discussion_r1800399496


##########
catalogs/catalog-hadoop/src/main/java/org/apache/gravitino/catalog/hadoop/HadoopCatalogOperations.java:
##########
@@ -742,4 +742,44 @@ private boolean checkSingleFile(Fileset fileset) {
           fileset.name());
     }
   }
+
+  FileSystem getFileSystem(Path path, Map<String, String> config) throws 
IOException {
+    String defaultFilesystemProvider =
+        (String)
+            propertiesMetadata
+                .catalogPropertiesMetadata()
+                .getOrDefault(config, 
HadoopCatalogPropertiesMetadata.DEFAULT_FS);
+
+    Map<String, String> newConfig = Maps.newHashMap(config);
+    if (path == null) {
+      if (defaultFilesystemProvider != null) {
+        return getFileSystemByScheme(defaultFilesystemProvider, newConfig);
+      } else {
+        LOG.warn("The path and default filesystem provider are both null, 
using local file system");
+        return getFileSystemByScheme(LOCAL_FILE_SCHEMA, newConfig);
+      }
+    }
+
+    // Path is not null;
+    if (path.toUri().getScheme() == null) {
+      LOG.warn(
+          "Can't get schema from path: {} and default filesystem provider are 
both null, using"
+              + " local file system",
+          path);
+      return getFileSystemByScheme(LOCAL_FILE_SCHEMA, newConfig);
+    } else {
+      newConfig.put(DEFAULT_FS, path.toUri().toString());
+      return getFileSystemByScheme(path.toUri().getScheme(), newConfig);
+    }
+  }

Review Comment:
   I believe all these logic can be simplified by:
   
   ```java
   scheme = path == null || path.uri.getScheme == null ? 
defaultProvider.scheme(): path.scheme.
   getFileSystemByScheme(scheme, newConfig)
   ```
   



-- 
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: commits-unsubscr...@gravitino.apache.org

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

Reply via email to