deniskuzZ commented on PR #6749:
URL: https://github.com/apache/hive/pull/6749#issuecomment-5772980812

   > **there might be a better way,** how about we pre-sort (descending order) 
the routes based on `requiredLength` at startup. `prefixLength = 
request_path_size - requiredLength` **_The greater the requiredLength the lower 
the prefixLenght_**. So the first one will be best match. WDYT?
   
   I would keep the explicit best-match loop with the early exit on 
prefixLength == 0, and skip the pre-sorting
   
   ````
   /**
    * Resolves the route for a request. When several routes match (e.g. a table 
named
    * "namespaces" can make a commit look like CREATE_NAMESPACE with a long 
prefix), the
    * route with the shortest implied prefix wins. This is a heuristic: without 
knowing
    * the server's expected prefix, such paths are inherently ambiguous.
    * Ties keep the first-declared route; no current templates can tie.
    */
   public static Pair<Route, Map<String, String>> from(HTTPMethod method, 
String path) {
     List<String> parts = SLASH.splitToList(path);
     Route best = null;
     int bestPrefix = Integer.MAX_VALUE;
     for (Route candidate : Route.values()) {
       if (!candidate.matches(method, parts)) {
         continue;
       }
       int prefix = candidate.prefixLength(parts);
       if (prefix < bestPrefix) {
         best = candidate;
         bestPrefix = prefix;
         if (prefix == 0) {
           break; // exact match, can't do better
         }
       }
     }
     return best == null ? null : Pair.of(best, best.variables(parts));
   }
   ````


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