Akshat-Jain commented on code in PR #17212:
URL: https://github.com/apache/druid/pull/17212#discussion_r1792910300


##########
extensions-core/lookups-cached-single/src/main/java/org/apache/druid/server/lookup/LoadingLookup.java:
##########
@@ -74,14 +75,22 @@ public String apply(@Nullable final String key)
     }
 
     final String presentVal;
-    try {
-      presentVal = loadingCache.get(keyEquivalent, new 
ApplyCallable(keyEquivalent));
+    presentVal = this.loadingCache.getIfPresent(keyEquivalent);
+    if (presentVal != null) {
       return NullHandling.emptyToNullIfNeeded(presentVal);
     }
-    catch (ExecutionException e) {
-      LOGGER.debug("value not found for key [%s]", key);
+
+    String val = this.dataFetcher.fetch(keyEquivalent);
+    if (val == null) {
       return null;
     }
+
+    Map<String, String> map = new HashMap<>();
+    map.put(keyEquivalent, val);
+
+    this.loadingCache.putAll(map);
+
+    return NullHandling.emptyToNullIfNeeded(val);

Review Comment:
   This seems functionally equivalent to the existing code. Can you please 
elaborate on why this change is needed? Thanks!



##########
extensions-core/lookups-cached-single/src/main/java/org/apache/druid/server/lookup/LoadingLookup.java:
##########
@@ -108,13 +117,18 @@ public List<String> unapply(@Nullable final String value)
   @Override
   public boolean supportsAsMap()
   {
-    return false;
+    return true;
   }
 
   @Override
   public Map<String, String> asMap()
   {
-    throw new UnsupportedOperationException("Cannot get map view");
+    Iterable<Map.Entry<String, String>> data = this.dataFetcher.fetchAll();
+    Map<String, String> map = new HashMap<>();
+    if (data != null) {
+      data.forEach(each -> map.put(each.getKey(), each.getValue()));
+    }
+    return map;

Review Comment:
   A couple of small nits: 
   
   1. Can make the map final
   2. Can remove the explicit null check in favor of 
Optional.ofNullable().ifPresent() format
   
   ```suggestion
       final Map<String, String> map = new HashMap<>();
   
       Optional.ofNullable(this.dataFetcher.fetchAll())
               .ifPresent(data -> data.forEach(entry -> map.put(entry.getKey(), 
entry.getValue())));
       return map;
   ```



##########
extensions-core/lookups-cached-single/src/main/java/org/apache/druid/server/lookup/LoadingLookup.java:
##########


Review Comment:
   I had a couple of questions regarding this overall change:
   1. The PR description suggests that it fixes #15936 - but that doesn't seem 
right. Can you confirm this, and update the PR description if needed?
   2. Can you give an example use-case for iterating over all the data? Is this 
for queries like `select * from "lookup"."lookupName"`?
   
   Appreciate your clarification on these. Thank you!



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