Aggarwal-Raghav commented on PR #6749:
URL: https://github.com/apache/hive/pull/6749#issuecomment-5704342870
> please check
>
> ```
> @Test
> public void testResourceNamedNamespacesIsNotTreatedAsPrefix() {
> assertEquals(Route.LOAD_NAMESPACE,
route("v1/namespaces/namespaces").first());
> assertEquals(Route.LOAD_TABLE,
route("v1/namespaces/db/tables/namespaces").first());
> assertEquals(Route.UPDATE_TABLE,
> Route.from(HTTPMethod.POST,
"v1/namespaces/db/tables/namespaces").first());
> assertEquals(Route.LOAD_TABLE,
> route("v1/catalogs/sales/namespaces/db/tables/namespaces").first());
> }
> ```
>
> I think an exact-length match (no prefix) should always win, and among
prefixed matches, the fewest prefix segments should win:
>
> ```
> public static Pair<Route, Map<String, String>> from(HTTPMethod method,
String path) {
> List<String> parts = SLASH.splitToList(path);
> Route best = null;
> for (Route candidate : Route.values()) {
> if (candidate.matches(method, parts)
> && (best == null || candidate.prefixLength(parts) <
best.prefixLength(parts))) {
> best = candidate;
> }
> }
> return best == null ? null : Pair.of(best, best.variables(parts));
> }
> ```
**Yes, this edge case was a miss from me** but 1 question in this approach,
if I do `/v1/config` then it will search for all the Route enum values i.e. all
25 routes LIST_NAMESPACES, CREATE_NAMESPACE etc. but as the number of routes is
just 25 so there shouldn't be any performance concern but this cost will be for
all REST HTTP calls.
**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?
--
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]