gortiz commented on code in PR #14951:
URL: https://github.com/apache/pinot/pull/14951#discussion_r1942636179


##########
pinot-controller/src/main/java/org/apache/pinot/controller/api/resources/PinotQueryResource.java:
##########
@@ -104,59 +104,61 @@ public class PinotQueryResource {
   @POST
   @Path("sql")
   @ManualAuthorization // performed by broker
-  public String handlePostSql(String requestJsonStr, @Context HttpHeaders 
httpHeaders) {
+  public StreamingOutput handlePostSql(String requestJsonStr, @Context 
HttpHeaders httpHeaders) {
+    JsonNode requestJson;
     try {
-      JsonNode requestJson = JsonUtils.stringToJsonNode(requestJsonStr);
-      if (!requestJson.has("sql")) {
-        return 
constructQueryExceptionResponse(QueryException.getException(QueryException.JSON_PARSING_ERROR,
-            "JSON Payload is missing the query string field 'sql'"));
-      }
-      String sqlQuery = requestJson.get("sql").asText();
-      String traceEnabled = "false";
-      if (requestJson.has("trace")) {
-        traceEnabled = requestJson.get("trace").toString();
-      }
-      String queryOptions = null;
-      if (requestJson.has("queryOptions")) {
-        queryOptions = requestJson.get("queryOptions").asText();
-      }
-      LOGGER.debug("Trace: {}, Running query: {}", traceEnabled, sqlQuery);
-      return executeSqlQuery(httpHeaders, sqlQuery, traceEnabled, 
queryOptions, "/sql");
-    } catch (ProcessingException pe) {
-      LOGGER.error("Caught exception while processing post request {}", 
pe.getMessage());
-      return constructQueryExceptionResponse(pe);
-    } catch (WebApplicationException wae) {
-      LOGGER.error("Caught exception while processing post request", wae);
-      throw wae;
+      requestJson = JsonUtils.stringToJsonNode(requestJsonStr);
     } catch (Exception e) {
-      LOGGER.error("Caught exception while processing post request", e);
-      return 
constructQueryExceptionResponse(QueryException.getException(QueryException.INTERNAL_ERROR,
 e));
+      return 
constructQueryExceptionResponse(QueryException.JSON_PARSING_ERROR_CODE, 
e.getMessage());
+    }
+    if (!requestJson.has("sql")) {
+      return 
constructQueryExceptionResponse(QueryException.getException(QueryException.JSON_PARSING_ERROR,
+          "JSON Payload is missing the query string field 'sql'"));
+    }
+    String sqlQuery = requestJson.get("sql").asText();
+    String traceEnabled = "false";
+    if (requestJson.has("trace")) {
+      traceEnabled = requestJson.get("trace").toString();
+    }
+    String queryOptions = null;
+    if (requestJson.has("queryOptions")) {
+      queryOptions = requestJson.get("queryOptions").asText();
     }
+
+    return executeSqlQueryCatching(httpHeaders, sqlQuery, traceEnabled, 
queryOptions);
   }
 
   @GET
   @Path("sql")
   @ManualAuthorization
-  public String handleGetSql(@QueryParam("sql") String sqlQuery, 
@QueryParam("trace") String traceEnabled,
+  public StreamingOutput handleGetSql(@QueryParam("sql") String sqlQuery, 
@QueryParam("trace") String traceEnabled,
       @QueryParam("queryOptions") String queryOptions, @Context HttpHeaders 
httpHeaders) {
+    return executeSqlQueryCatching(httpHeaders, sqlQuery, traceEnabled, 
queryOptions);
+  }
+
+  private StreamingOutput executeSqlQueryCatching(HttpHeaders httpHeaders, 
String sqlQuery, String traceEnabled,
+      String queryOptions) {
     try {
-      LOGGER.debug("Trace: {}, Running query: {}", traceEnabled, sqlQuery);
-      return executeSqlQuery(httpHeaders, sqlQuery, traceEnabled, 
queryOptions, "/sql");
+      return executeSqlQuery(httpHeaders, sqlQuery, traceEnabled, 
queryOptions);
+    } catch (QException e) {
+      LOGGER.error("Caught query exception while processing post request", e);

Review Comment:
   Good catch. Same in the others.



-- 
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: commits-unsubscr...@pinot.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org
For additional commands, e-mail: commits-h...@pinot.apache.org

Reply via email to