dobesv commented on a change in pull request #1997: DRILL-7604: Allow session 
options to be set in HTTP queries
URL: https://github.com/apache/drill/pull/1997#discussion_r384919237
 
 

 ##########
 File path: 
exec/java-exec/src/main/java/org/apache/drill/exec/server/rest/QueryResources.java
 ##########
 @@ -110,6 +117,47 @@ public Viewable submitQuery(@FormParam("query") String 
query,
     }
   }
 
+  private Map<String, Object> readOptionsFromForm(Form form) {
+    Map<String, Object> options = new HashMap<>();
+    SessionOptionManager sessionOptionManager = 
webUserConnection.getSession().getOptions();
+    for (Map.Entry<String, List<String>> pair : form.asMap().entrySet()) {
+      String name = pair.getKey();
+      OptionDefinition definition = 
sessionOptionManager.getOptionDefinition(name);
+      if (definition != null) {
+        String valueStr = pair.getValue().get(0);
+        if (!valueStr.isEmpty()) {
+          try {
+            Object value = null;
+            switch (definition.getValidator().getKind()) {
+              case BOOLEAN:
+                if ("true".equals(valueStr)) {
+                  value = true;
+                } else if ("false".equals(valueStr)) {
+                  value = false;
+                } else {
+                  throw new BadRequestException(String.format("Invalid boolean 
option value for %s: %s", name, valueStr));
+                }
+                break;
+              case DOUBLE:
+                value = Double.valueOf(valueStr);
+                break;
+              case STRING:
+                value = valueStr;
+                break;
+              case LONG:
+                value = Long.valueOf(valueStr);
+                break;
+            }
+            options.put(name, value);
 
 Review comment:
   I'm not exactly sure what an unknown type is - the switch/case is exhaustive 
for that enum currently:
   
   ```
   public enum Kind {
       BOOLEAN, LONG, STRING, DOUBLE
     }
   ```
   
   I have added a default clause anyway.

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to