From d5bb7de5cf4836b18a322498d2895f68d8d63a49 Mon Sep 17 00:00:00 2001 From: Ashwin Tumma Date: Wed, 30 Oct 2024 08:23:22 -0700 Subject: [PATCH] Fix Map Lookup Introspection Endpoints and update doc for Globally Cached Lookups (#17436) Map Lookup Introspection API endpoints /keys and /values no longer return an invalid JSON object. Also, update documentation to clarify the version returned by the /version introspection endpoint. --------- Co-authored-by: Ashwin Tumma --- docs/querying/lookups-cached-global.md | 2 +- .../apache/druid/query/lookup/MapLookupExtractorFactory.java | 4 ++-- .../druid/query/lookup/LookupIntrospectionResourceTest.java | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/querying/lookups-cached-global.md b/docs/querying/lookups-cached-global.md index a0208b17bc3..68a7b642130 100644 --- a/docs/querying/lookups-cached-global.md +++ b/docs/querying/lookups-cached-global.md @@ -384,4 +384,4 @@ The JDBC lookups will poll a database to populate its local cache. If the `tsCol ## Introspection -Globally cached lookups have introspection points at `/keys` and `/values` which return a complete set of the keys and values (respectively) in the lookup. Introspection to `/` returns the entire map. Introspection to `/version` returns the version indicator for the lookup. +Globally cached lookups have introspection points at `/keys` and `/values`, which return the complete set of keys and values respectively in the lookup as a JSON object. Introspection to `/` returns the entire map as a JSON object. Introspection to `/version` provides the internal version indicating when the lookup cache was last updated. See [Introspect A Lookup](./lookups.md#Introspect a Lookup) for examples. \ No newline at end of file diff --git a/server/src/main/java/org/apache/druid/query/lookup/MapLookupExtractorFactory.java b/server/src/main/java/org/apache/druid/query/lookup/MapLookupExtractorFactory.java index 74f68b20a5d..c0981d10ce3 100644 --- a/server/src/main/java/org/apache/druid/query/lookup/MapLookupExtractorFactory.java +++ b/server/src/main/java/org/apache/druid/query/lookup/MapLookupExtractorFactory.java @@ -145,7 +145,7 @@ public class MapLookupExtractorFactory implements LookupExtractorFactory @Produces(MediaType.APPLICATION_JSON) public Response getKeys() { - return Response.ok(map.keySet().toString()).build(); + return Response.ok(map.keySet()).build(); } @GET @@ -153,7 +153,7 @@ public class MapLookupExtractorFactory implements LookupExtractorFactory @Produces(MediaType.APPLICATION_JSON) public Response getValues() { - return Response.ok(map.values().toString()).build(); + return Response.ok(map.values()).build(); } @GET diff --git a/server/src/test/java/org/apache/druid/query/lookup/LookupIntrospectionResourceTest.java b/server/src/test/java/org/apache/druid/query/lookup/LookupIntrospectionResourceTest.java index dd8c84a96dc..1c0bc4d12e9 100644 --- a/server/src/test/java/org/apache/druid/query/lookup/LookupIntrospectionResourceTest.java +++ b/server/src/test/java/org/apache/druid/query/lookup/LookupIntrospectionResourceTest.java @@ -152,7 +152,7 @@ public class LookupIntrospectionResourceTest .accept(MediaType.APPLICATION_JSON) .get(ClientResponse.class); String s = resp.getEntity(String.class); - Assert.assertEquals("[key, key2]", s); + Assert.assertEquals("[\"key\",\"key2\"]", s); Assert.assertEquals(200, resp.getStatus()); } @@ -166,7 +166,7 @@ public class LookupIntrospectionResourceTest .accept(MediaType.APPLICATION_JSON) .get(ClientResponse.class); String s = resp.getEntity(String.class); - Assert.assertEquals("[value, value2]", s); + Assert.assertEquals("[\"value\",\"value2\"]", s); Assert.assertEquals(200, resp.getStatus()); }