siddharthteotia commented on code in PR #9912:
URL: https://github.com/apache/pinot/pull/9912#discussion_r1049979311
##########
pinot-spi/src/main/java/org/apache/pinot/spi/utils/QueryOptionsUtils.java:
##########
@@ -32,6 +36,59 @@ public class QueryOptionsUtils {
private QueryOptionsUtils() {
}
+
+ private static final Map<String, String> CONFIG_RESOLVER;
+ private static final RuntimeException CLASS_LOAD_ERROR;
+
+ static {
+ // this is a bit hacky, but lots of the code depends directly on usage of
+ // Map<String, String> (JSON serialization/GRPC code) so we cannot just
+ // refactor all code to use a case-insensitive abstraction like
PinotConfiguration
+ // without a lot of work - additionally, the config constants are string
constants
+ // instead of enums so there's no good way to iterate over them, but they
are
+ // public API so we cannot just change them to be an enum
+ Map<String, String> configResolver = new HashMap<>();
+ Throwable classLoadError = null;
+
+ try {
+ for (Field declaredField : QueryOptionKey.class.getDeclaredFields()) {
+ if (declaredField.getType().equals(String.class)) {
+ int mods = declaredField.getModifiers();
+ if (Modifier.isStatic(mods) && Modifier.isFinal(mods)) {
+ String config = (String) declaredField.get(null);
+ configResolver.put(config.toLowerCase(), config);
+ }
+ }
+ }
+ } catch (IllegalAccessException e) {
+ // prefer rethrowing this during runtime instead of a
ClassNotFoundException
+ configResolver = null;
+ classLoadError = e;
+ }
+
+ CONFIG_RESOLVER = configResolver == null ? null :
ImmutableMap.copyOf(configResolver);
+ CLASS_LOAD_ERROR = classLoadError == null ? null
+ : new RuntimeException("Failure to build case insensitive mapping.",
classLoadError);
+ }
+
+ public static Map<String, String> resolveCaseInsensitiveOptions(Map<String,
String> queryOptions) {
+ if (CLASS_LOAD_ERROR != null) {
+ throw CLASS_LOAD_ERROR;
+ }
+
+ Map<String, String> resolved = new HashMap<>();
+ for (Map.Entry<String, String> configEntry : queryOptions.entrySet()) {
+ String config = CONFIG_RESOLVER.get(configEntry.getKey().toLowerCase());
+ if (config != null) {
+ resolved.put(config, configEntry.getValue());
+ } else {
+ resolved.put(configEntry.getKey(), configEntry.getValue());
+ }
+ }
Review Comment:
Looks good to me.
--
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]