imply-cheddar commented on code in PR #13564:
URL: https://github.com/apache/druid/pull/13564#discussion_r1051913011


##########
sql/src/main/java/org/apache/druid/sql/http/SqlResource.java:
##########
@@ -320,4 +181,187 @@ public Response cancelQuery(
       return Response.status(Status.FORBIDDEN).build();
     }
   }
+
+  /**
+   * The SqlResource only generates metrics and doesn't keep track of 
aggregate counts of successful/failed/interrupted
+   * queries, so this implementation is effectively just a noop.
+   */
+  private static class SqlResourceQueryMetricCounter implements 
QueryResource.QueryMetricCounter
+  {
+    @Override
+    public void incrementSuccess()
+    {
+
+    }
+
+    @Override
+    public void incrementFailed()
+    {
+
+    }
+
+    @Override
+    public void incrementInterrupted()
+    {
+
+    }
+
+    @Override
+    public void incrementTimedOut()
+    {
+
+    }
+  }
+
+  private class SqlResourceQueryResultPusher extends QueryResultPusher
+  {
+    private final String sqlQueryId;
+    private final HttpStatement stmt;
+    private final SqlQuery sqlQuery;
+
+    public SqlResourceQueryResultPusher(
+        AsyncContext asyncContext,
+        String sqlQueryId,
+        HttpStatement stmt,
+        SqlQuery sqlQuery
+    )
+    {
+      super(
+          (HttpServletResponse) asyncContext.getResponse(),
+          SqlResource.this.jsonMapper,
+          SqlResource.this.responseContextConfig,
+          SqlResource.this.selfNode,
+          SqlResource.QUERY_METRIC_COUNTER,
+          sqlQueryId,
+          MediaType.APPLICATION_JSON_TYPE
+      );
+      this.sqlQueryId = sqlQueryId;
+      this.stmt = stmt;
+      this.sqlQuery = sqlQuery;
+    }
+
+    @Override
+    public ResultsWriter start()
+    {
+      return new ResultsWriter()
+      {
+        private ResultSet thePlan;
+
+        @Override
+        @Nullable
+        @SuppressWarnings({"unchecked", "rawtypes"})
+        public QueryResponse<Object> start(HttpServletResponse response)
+        {
+          response.setHeader(SQL_QUERY_ID_RESPONSE_HEADER, sqlQueryId);
+
+          final QueryResponse<Object[]> retVal;
+          try {
+            thePlan = stmt.plan();
+            retVal = thePlan.run();

Review Comment:
   Fwiw, this refactor doesn't actually change any thread ownership at all.  
All of the work that was previously being done by the request thread is still 
doing that.  The RequestResultsPusher could theoretically be used across thread 
boundaries and the API now might make it look a bit more tempting to do that, 
but we should be careful if/when we actually do that.



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