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


##########
catalogs/catalog-hadoop/src/main/java/org/apache/gravitino/catalog/hadoop/fs/FileSystemUtils.java:
##########
@@ -101,4 +102,45 @@ public static FileSystemProvider 
getFileSystemProviderByName(
                         "File system provider with name '%s' not found in the 
file system provider list.",
                         fileSystemProviderName)));
   }
+
+  /**
+   * Convert the Gravitino configuration to Hadoop configuration.
+   *
+   * <p>Predefined keys have the highest priority. If the key does not exist 
in the predefined keys,
+   * it will be set to the configuration. Keys with prefixes 
'gravitino.bypass' has the lowest
+   * priority.
+   *
+   * @param config Gravitino configuration
+   * @return Hadoop configuration Map
+   */
+  public static Map<String, String> toHadoopConfigMap(
+      Map<String, String> config, Map<String, String> predefinedKeys) {
+    Map<String, String> result = Maps.newHashMap();
+    Set<String> highestPriorityKeys = Sets.newHashSet();
+    config.forEach(
+        (k, v) -> {
+          if (predefinedKeys.containsKey(k)) {
+            String key = predefinedKeys.get(k);
+            highestPriorityKeys.add(key);
+            result.put(key, v);
+          }
+
+          if (!k.startsWith(GRAVITINO_BYPASS)) {
+            // If the key does not start with 'gravitino.bypass' and is not in 
the highest priority
+            // keys, set the value to the configuration.
+            if (!highestPriorityKeys.contains(k)) {
+              result.put(k, v);
+            }
+          } else {
+            // If the key starts with 'gravitino.bypass', remove the prefix 
and set the value to the
+            // configuration if the key does not exist in the configuration.
+            String key = k.replace(GRAVITINO_BYPASS, "");
+            if (!result.containsKey(key)) {
+              result.put(key, v);
+            }
+          }
+        });

Review Comment:
   Can we simplify this code? It's a bit hard to understand, I think it is OK 
to iterate for several rounds, just make it easy to read.



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