You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pinot.apache.org by GitBox <gi...@apache.org> on 2022/04/16 21:44:58 UTC

[GitHub] [pinot] Jackie-Jiang commented on a diff in pull request #8557: Adding DML definition and parse SQL InsertFile

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-unsubscribe@pinot.apache.org

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


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