FrankChen021 commented on code in PR #13022:
URL: https://github.com/apache/druid/pull/13022#discussion_r965583376


##########
processing/src/main/java/org/apache/druid/query/Query.java:
##########
@@ -124,22 +124,130 @@ default QueryContext getQueryContext()
     return null;
   }
 
-  <ContextType> ContextType getContextValue(String key);
+  /**
+   * Get context value. It's recommended to use following methods instead
+   * {@link #getContextBoolean(String, boolean)}
+   * {@link #getContextAsString(String)}
+   * {@link #getContextAsInt(String)}
+   * {@link #getContextAsLong(String)}
+   * {@link #getContextAsFloat(String, float)}
+   * {@link #getContextAsEnum(String, Class, Enum)}
+   * {@link #getContextAsHumanReadableBytes(String, HumanReadableBytes)}
+   */
+  @Nullable
+  default Object getContextValue(String key)
+  {
+    if (getQueryContext() != null) {
+      return getQueryContext().get(key);
+    } else {
+      return null;
+    }
+  }
 
-  <ContextType> ContextType getContextValue(String key, ContextType 
defaultValue);
+  @Nullable
+  default String getContextAsString(String key)
+  {
+    if (getQueryContext() != null) {
+      return getQueryContext().getAsString(key);
+    } else {
+      return null;
+    }
+  }
 
-  boolean getContextBoolean(String key, boolean defaultValue);
+  default String getContextAsString(String key, String defaultValue)
+  {
+    if (getQueryContext() != null) {
+      return getQueryContext().getAsString(key, defaultValue);
+    } else {
+      return defaultValue;
+    }
+  }
+
+  @Nullable
+  default Integer getContextAsInt(String key)
+  {
+    if (getQueryContext() != null) {
+      return getQueryContext().getAsInt(key);
+    } else {
+      return null;
+    }
+  }
+
+  default int getContextAsInt(String key, int defaultValue)
+  {
+    if (getQueryContext() != null) {
+      return getQueryContext().getAsInt(key, defaultValue);
+    } else {
+      return defaultValue;
+    }
+  }
+
+  @Nullable
+  default Long getContextAsLong(String key)
+  {
+    if (getQueryContext() != null) {
+      return getQueryContext().getAsLong(key);
+    } else {
+      return null;
+    }
+  }
+
+  default long getContextAsLong(String key, long defaultValue)
+  {
+    if (getQueryContext() != null) {
+      return getQueryContext().getAsLong(key, defaultValue);
+    } else {
+      return defaultValue;
+    }
+  }
+
+  default float getContextAsFloat(String key, float defaultValue)
+  {
+    if (getQueryContext() != null) {
+      return getQueryContext().getAsFloat(key, defaultValue);
+    } else {
+      return defaultValue;
+    }
+  }
+
+  default <E extends Enum<E>> E getContextAsEnum(String key, Class<E> clazz, E 
defaultValue)
+  {
+    if (getQueryContext() != null) {
+      return getQueryContext().getAsEnum(key, clazz, defaultValue);
+    } else {
+      return defaultValue;
+    }
+  }
+
+  @Nullable
+  default Boolean getContextAsBoolean(String key)

Review Comment:
   I think you mean this method `getContextBoolean`? 
   I didn't change this method to use the same name pattern as 
'getContextAs...' because there're lots reference to this method which might 
cause this PR so large. But indeed, it should be the same name pattern.



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