siddharthteotia commented on code in PR #9202:
URL: https://github.com/apache/pinot/pull/9202#discussion_r944891272


##########
pinot-broker/src/main/java/org/apache/pinot/broker/requesthandler/BrokerRequestHandlerDelegate.java:
##########
@@ -71,18 +77,43 @@ public void shutDown() {
   }
 
   @Override
-  public BrokerResponse handleRequest(JsonNode request, @Nullable 
RequesterIdentity requesterIdentity,
-      RequestContext requestContext)
+  public BrokerResponseNative handleRequest(JsonNode request, @Nullable 
SqlNodeAndOptions sqlNodeAndOptions,
+      @Nullable RequesterIdentity requesterIdentity, RequestContext 
requestContext)
       throws Exception {
-    if (_isMultiStageQueryEngineEnabled && _multiStageWorkerRequestHandler != 
null) {
-      if (request.has("queryOptions")) {
-        Map<String, String> queryOptionMap = 
BaseBrokerRequestHandler.getOptionsFromJson(request, "queryOptions");
-        if (Boolean.parseBoolean(queryOptionMap.get(
-            
CommonConstants.Broker.Request.QueryOptionKey.USE_MULTISTAGE_ENGINE))) {
-          return _multiStageWorkerRequestHandler.handleRequest(request, 
requesterIdentity, requestContext);
-        }
+    if (sqlNodeAndOptions == null) {
+      JsonNode sql = request.get(Request.SQL);
+      if (sql == null) {
+        throw new BadQueryRequestException("Failed to find 'sql' in the 
request: " + request);
+      }
+      try {
+        sqlNodeAndOptions = 
CalciteSqlParser.compileToSqlNodeAndOptions(sql.asText());
+      } catch (Exception e) {
+        LOGGER.info("Caught exception while compiling SQL: {}, {}", 
sql.asText(), e.getMessage());
+        
_brokerMetrics.addMeteredGlobalValue(BrokerMeter.REQUEST_COMPILATION_EXCEPTIONS,
 1);
+        requestContext.setErrorCode(QueryException.SQL_PARSING_ERROR_CODE);
+        return new 
BrokerResponseNative(QueryException.getException(QueryException.SQL_PARSING_ERROR,
 e));
       }
     }
-    return _singleStageBrokerRequestHandler.handleRequest(request, 
requesterIdentity, requestContext);
+
+    if (_multiStageWorkerRequestHandler != null && 
useMultiStageEngine(request, sqlNodeAndOptions)) {
+      return _multiStageWorkerRequestHandler.handleRequest(request, 
sqlNodeAndOptions, requesterIdentity,
+          requestContext);
+    } else {
+      return _singleStageBrokerRequestHandler.handleRequest(request, 
sqlNodeAndOptions, requesterIdentity,
+          requestContext);
+    }
+  }
+
+  private boolean useMultiStageEngine(JsonNode request, SqlNodeAndOptions 
sqlNodeAndOptions) {

Review Comment:
   +1 - Thanks for this change.
   
   This will allow us to deploy this on perf cluster and for a given prod use 
case run a mixed workload where JOIN / subqueries go through multi-stage engine 
based on the query level options and feature flag turned on and existing prod 
queries  (non join / non subquery) continue to go through existing engine 
because they will not have the query level option.
   
   We wanted to do productionization testing on our use cases this way to keep 
it focused on finding problems with new queries that go down the new engine



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