deniskuzZ commented on code in PR #6749:
URL: https://github.com/apache/hive/pull/6749#discussion_r4024742132


##########
standalone-metastore/metastore-rest-catalog/src/main/java/org/apache/iceberg/rest/HMSCatalogAdapter.java:
##########
@@ -189,26 +192,60 @@ enum Route {
       }
 
       this.requestClass = requestClass;
-
       this.requiredLength = parts.size();
       this.requirements = requirementsBuilder.build();
       this.variables = variablesBuilder.build();
     }
 
+    /**
+     * Shift index to skip the prefix.
+     */
+    private int mappedIndex(int baseIndex, int offset) {
+      return (offset > 0 && baseIndex >= 1) ? baseIndex + offset : baseIndex;
+    }
+
     private boolean matches(HTTPMethod requestMethod, List<String> 
requestPath) {
-      return method == requestMethod
-          && requiredLength == requestPath.size()
-          && requirements.entrySet().stream()
-          .allMatch(
-              requirement ->
-                  requirement
-                      .getValue()
-                      
.equalsIgnoreCase(requestPath.get(requirement.getKey())));
+      if (method != requestMethod) {
+        return false;
+      }
+
+      int size = requestPath.size();
+      // Calculate the size of the optional prefix by checking how much the 
path expanded.
+      // For a multi-segment prefix like 'catalogs/my_catalog', offset will be 
2.
+      int offset = size - requiredLength;
+
+      // If the path is too short, or too long but the route doesn't support a 
prefix, reject.
+      if (offset < 0 || (offset > 0 && !withPrefix)) {
+        return false;
+      }
+
+      for (Map.Entry<Integer, String> requirement : requirements.entrySet()) {
+        if 
(!requirement.getValue().equalsIgnoreCase(requestPath.get(mappedIndex(requirement.getKey(),
 offset)))) {
+          return false;
+        }
+      }
+      return true;
     }
 
     private Map<String, String> variables(List<String> requestPath) {
       ImmutableMap.Builder<String, String> vars = ImmutableMap.builder();
-      variables.forEach((key, value) -> vars.put(value, requestPath.get(key)));
+      int offset = requestPath.size() - requiredLength;

Review Comment:
   ````
    int prefixLength = prefixLength(requestPath);
   
     ImmutableMap.Builder<String, String> vars = ImmutableMap.builder();
     for (Map.Entry<Integer, String> var : variables.entrySet()) {
       vars.put(var.getValue(), requestPath.get(mappedIndex(var.getKey(), 
prefixLength)));
     }
   
     if (prefixLength > 0) {
       // Clients insert the configured prefix verbatim, so "catalogs/sales" 
arrives
       // as two segments; rejoin them. An encoded %2F inside a prefix is not 
preserved.
       String prefix = String.join("/",
           requestPath.subList(PREFIX_START, PREFIX_START + prefixLength));
       // The HMS backend serves a single HiveCatalog and does not scope by 
prefix yet.
       LOG.debug("Ignoring request prefix '{}' for route {}", prefix, this);
       vars.put(PREFIX_VAR, prefix);
     }
   ````



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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to