arina-ielchiieva 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_r384392947
 
 

 ##########
 File path: 
exec/java-exec/src/main/java/org/apache/drill/exec/server/rest/QueryWrapper.java
 ##########
 @@ -131,6 +146,52 @@ public QueryResult run(final WorkManager workManager, 
final WebUserConnection we
     return new QueryResult(queryId, webUserConnection, 
webUserConnection.results);
   }
 
+  private void applyOptions(WebUserConnection webUserConnection) throws 
BadRequestException {
+    if (options != null && !options.isEmpty()) {
+      SessionOptionManager sessionOptionManager = 
webUserConnection.getSession().getOptions();
+      for (Map.Entry<String, Object> entry : options.entrySet()) {
+        String name = entry.getKey();
+        OptionDefinition definition = 
sessionOptionManager.getOptionDefinition(name);
+        if (definition == null) {
+          throw UserException.validationError().message("Unsupported option 
'%s'", name).build(logger);
+        }
+        if 
(!(definition.getMetaData().getAccessibleScopes().inScopeOf(OptionValue.OptionScope.SESSION)
 || 
definition.getMetaData().getAccessibleScopes().inScopeOf(OptionValue.OptionScope.QUERY)))
 {
+          throw UserException.validationError().message("Option '%s' is not a 
session / query option", name).build(logger);
+        }
+        if (definition.getMetaData().isInternal()) {
+          throw UserException.validationError().message("Internal option '%s' 
cannot be set with query", name).build(logger);
+        }
+        Object value = entry.getValue();
+        switch (definition.getValidator().getKind()) {
+          case BOOLEAN:
+            if (!(value instanceof Boolean)) {
+              throw UserException.validationError().message("Expected boolean 
value for option '%s'", name).build(logger);
+            }
+            sessionOptionManager.setLocalOption(name, (Boolean) value);
+            break;
+          case DOUBLE:
+            if (!(value instanceof Number)) {
+              throw UserException.validationError().message("Expected number 
value for option '%s'", name).build(logger);
+            }
+            sessionOptionManager.setLocalOption(name, ((Number) 
value).doubleValue());
+            break;
+          case STRING:
+            if (!(value instanceof String)) {
+              throw UserException.validationError().message("Expected string 
value for option '%s'", name).build(logger);
+            }
+            sessionOptionManager.setLocalOption(name, (String) value);
+            break;
+          case LONG:
+            if (!(value instanceof Number)) {
+              throw UserException.validationError().message("Expected number 
value for option '%s'", name).build(logger);
+            }
+            sessionOptionManager.setLocalOption(name, ((Number) 
value).longValue());
+            break;
 
 Review comment:
   Please add behavior in case of we encounter unexpected kind.

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