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/07/11 23:24:38 UTC

[GitHub] [pinot] Jackie-Jiang commented on a diff in pull request #9017: Support SET key=value syntax

Jackie-Jiang commented on code in PR #9017:
URL: https://github.com/apache/pinot/pull/9017#discussion_r918420821


##########
pinot-common/src/main/java/org/apache/pinot/sql/parsers/CalciteSqlParser.java:
##########
@@ -105,66 +106,80 @@ private static String removeTerminatingSemicolon(String sql) {
   }
 
   public static SqlNodeAndOptions compileToSqlNodeAndOptions(String sql)
-      throws Exception {
+      throws SqlCompilationException {
     // Remove the comments from the query
     sql = removeComments(sql);
 
     // Remove the terminating semicolon from the query
     sql = removeTerminatingSemicolon(sql);
 
-    // Extract OPTION statements from sql as Calcite Parser doesn't parse it.
+    // extract and remove OPTIONS string
     List<String> options = extractOptionsFromSql(sql);
-    if (!options.isEmpty()) {
-      sql = removeOptionsFromSql(sql);
-    }
+    sql = removeOptionsFromSql(sql);

Review Comment:
   Don't remove the if check to avoid overhead when there is no options



##########
pinot-common/src/main/java/org/apache/pinot/sql/parsers/CalciteSqlParser.java:
##########
@@ -105,66 +106,80 @@ private static String removeTerminatingSemicolon(String sql) {
   }
 
   public static SqlNodeAndOptions compileToSqlNodeAndOptions(String sql)
-      throws Exception {
+      throws SqlCompilationException {
     // Remove the comments from the query
     sql = removeComments(sql);
 
     // Remove the terminating semicolon from the query
     sql = removeTerminatingSemicolon(sql);
 
-    // Extract OPTION statements from sql as Calcite Parser doesn't parse it.
+    // extract and remove OPTIONS string
     List<String> options = extractOptionsFromSql(sql);
-    if (!options.isEmpty()) {
-      sql = removeOptionsFromSql(sql);
-    }
+    sql = removeOptionsFromSql(sql);
 
     try (StringReader inStream = new StringReader(sql)) {
       SqlParserImpl sqlParser = newSqlParser(inStream);
-      return new SqlNodeAndOptions(sqlParser.parseSqlStmtEof(), options);
+      SqlNodeList sqlNodeList = sqlParser.SqlStmtsEof();
+      // Extract OPTION statements from sql.
+      SqlNodeAndOptions sqlNodeAndOptions = extractSqlNodeAndOptions(sqlNodeList);
+      // add legacy OPTIONS keyword-based options
+      if (options.size() > 0) {
+        LOGGER.warn("Usage of 'OPTIONS(key=value)' is deprecated, use `SET key = value` instead!");

Review Comment:
   This will flood the log, especially for high throughput use cases. Let's just set the options quietly



##########
pinot-common/src/main/java/org/apache/pinot/sql/parsers/CalciteSqlParser.java:
##########
@@ -469,11 +464,34 @@ private static List<String> extractOptionsFromSql(String sql) {
     return results;
   }
 
+  @Deprecated
   private static String removeOptionsFromSql(String sql) {
     Matcher matcher = OPTIONS_REGEX_PATTEN.matcher(sql);
     return matcher.replaceAll("");
   }
 
+  @Deprecated
+  private static Map<String, String> extractOptionsMap(List<String> optionsStatements) {
+    Map<String, String> options = new HashMap<>();
+    for (String optionsStatement : optionsStatements) {
+      for (String option : optionsStatement.split(",")) {
+        final String[] splits = option.split("=");
+        if (splits.length != 2) {
+          throw new SqlCompilationException("OPTION statement requires two parts separated by '='");
+        }
+        options.put(splits[0].trim(), splits[1].trim());
+      }
+    }
+    return options;
+  }
+
+  private static void setOptions(PinotQuery pinotQuery, List<String> optionsStatements) {

Review Comment:
   Is this still used?



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