Jackie-Jiang commented on code in PR #8557: URL: https://github.com/apache/pinot/pull/8557#discussion_r851673992
########## pinot-controller/src/main/java/org/apache/pinot/controller/api/resources/PinotQueryResource.java: ########## @@ -135,20 +142,39 @@ public String handlePostSql(String requestJsonStr, @Context HttpHeaders httpHead queryOptions = requestJson.get("queryOptions").asText(); } LOGGER.debug("Trace: {}, Running query: {}", traceEnabled, sqlQuery); - return getQueryResponse(sqlQuery, traceEnabled, queryOptions, httpHeaders, CommonConstants.Broker.Request.SQL); + return executeSqlQuery(httpHeaders, sqlQuery, traceEnabled, queryOptions); } catch (Exception e) { LOGGER.error("Caught exception while processing post request", e); return QueryException.getException(QueryException.INTERNAL_ERROR, e).toString(); } } + private String executeSqlQuery(@Context HttpHeaders httpHeaders, String sqlQuery, + String traceEnabled, String queryOptions) + throws Exception { + SqlNodeAndOptions sqlNodeAndOptions = CalciteSqlParser.compileToSqlNodeAndOptions(sqlQuery); + PinotSqlType sqlType = CalciteSqlParser.extractSqlType(sqlNodeAndOptions.getSqlNode()); + switch (sqlType) { + case DQL: + return getQueryResponse(sqlQuery, traceEnabled, queryOptions, httpHeaders, CommonConstants.Broker.Request.SQL); + case DML: + Map<String, String> headers = + httpHeaders.getRequestHeaders().entrySet().stream().filter(entry -> !entry.getValue().isEmpty()) + .map(entry -> Pair.of(entry.getKey(), entry.getValue().get(0))) + .collect(Collectors.toMap(Pair::getKey, Pair::getValue)); + return _sqlQueryExecutor.executeDMLStatement(sqlNodeAndOptions, headers).toJsonString(); Review Comment: Since this is executed on controller, we can skip sending the request again ########## pinot-controller/src/main/java/org/apache/pinot/controller/api/resources/PinotQueryResource.java: ########## @@ -135,20 +142,39 @@ public String handlePostSql(String requestJsonStr, @Context HttpHeaders httpHead queryOptions = requestJson.get("queryOptions").asText(); } LOGGER.debug("Trace: {}, Running query: {}", traceEnabled, sqlQuery); - return getQueryResponse(sqlQuery, traceEnabled, queryOptions, httpHeaders, CommonConstants.Broker.Request.SQL); + return executeSqlQuery(httpHeaders, sqlQuery, traceEnabled, queryOptions); } catch (Exception e) { LOGGER.error("Caught exception while processing post request", e); return QueryException.getException(QueryException.INTERNAL_ERROR, e).toString(); } } + private String executeSqlQuery(@Context HttpHeaders httpHeaders, String sqlQuery, + String traceEnabled, String queryOptions) + throws Exception { + SqlNodeAndOptions sqlNodeAndOptions = CalciteSqlParser.compileToSqlNodeAndOptions(sqlQuery); + PinotSqlType sqlType = CalciteSqlParser.extractSqlType(sqlNodeAndOptions.getSqlNode()); + switch (sqlType) { + case DQL: + return getQueryResponse(sqlQuery, traceEnabled, queryOptions, httpHeaders, CommonConstants.Broker.Request.SQL); Review Comment: Since we already compiled the query, no need to compile again in `getQueryResponse()` -- 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