yashmayya commented on code in PR #16536:
URL: https://github.com/apache/pinot/pull/16536#discussion_r2260444452


##########
pinot-controller/src/main/java/org/apache/pinot/controller/api/resources/PinotQueryResource.java:
##########
@@ -151,6 +151,59 @@ public StreamingOutput 
handleTimeSeriesQueryRange(@QueryParam("language") String
     return executeTimeSeriesQueryCatching(httpHeaders, language, query, start, 
end, step);
   }
 
+  @POST
+  @Path("validateMultiStageQuery")
+  public MultiStageQueryValidationResponse validateMultiStageQuery(String 
requestJsonStr,
+      @Context HttpHeaders httpHeaders) {
+    JsonNode requestJson;
+    try {
+      requestJson = JsonUtils.stringToJsonNode(requestJsonStr);
+    } catch (Exception e) {
+      LOGGER.warn("Caught exception while parsing request {}", e.getMessage());
+      return new MultiStageQueryValidationResponse(false, "Failed to parse 
request JSON: " + e.getMessage(), null);
+    }
+    if (!requestJson.has("sql")) {
+      return new MultiStageQueryValidationResponse(false, "JSON Payload is 
missing the query string field 'sql'", null);
+    }
+    String sqlQuery = requestJson.get("sql").asText();
+    Map<String, String> queryOptionsMap = 
RequestUtils.parseQuery(sqlQuery).getOptions();
+    String database = 
DatabaseUtils.extractDatabaseFromQueryRequest(queryOptionsMap, httpHeaders);
+    try (QueryEnvironment.CompiledQuery compiledQuery = new 
QueryEnvironment(database,
+        _pinotHelixResourceManager.getTableCache(), null).compile(sqlQuery)) {
+      return new MultiStageQueryValidationResponse(true, null, null);
+    } catch (QueryException e) {
+      LOGGER.info("Caught exception while compiling multi-stage query: {}", 
e.getMessage());
+      return new MultiStageQueryValidationResponse(false, e.getMessage(), 
e.getErrorCode());
+    }
+  }
+
+  private static class MultiStageQueryValidationResponse {

Review Comment:
   I'm only using the class for JSON serde, but fair point. 



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