richardstartin commented on a change in pull request #7861:
URL: https://github.com/apache/pinot/pull/7861#discussion_r761955557



##########
File path: 
pinot-common/src/main/java/org/apache/pinot/sql/parsers/CalciteSqlParser.java
##########
@@ -96,8 +96,36 @@ private CalciteSqlParser() {
   private static final Pattern OPTIONS_REGEX_PATTEN =
       Pattern.compile("option\\s*\\(([^\\)]+)\\)", Pattern.CASE_INSENSITIVE);
 
+  /**
+   * Checks for the presence of semicolon in the sql query and modifies the 
query accordingly
+   *
+   * @param sql sql query
+   * @return sql query without semicolons
+   *
+   */
+  private static String checkForSemicolonInTheQuery(String sql) {
+    // Check if the query has semicolon
+    int semiColonIndex = sql.indexOf(';');
+    if (semiColonIndex > -1) {
+      // Split the input query based on semicolon
+      String[] sqlSplit = sql.split(";");
+
+      // If only semicolons are present in the input query
+      if (sqlSplit.length == 0) {
+        new SqlCompilationException("Caught exception while parsing query: " + 
sql);
+      } else {
+        // After spliting take the string present at 0th index and then parse 
the SQL
+        sql = sqlSplit[0];
+      }

Review comment:
       My suggestion is to change the logic to allow only _terminating_ 
semicolons (like 
[beam](https://beam.apache.org/documentation/dsls/sql/calcite/lexical-structure/#terminating-semicolons))
 - so only modify the query if there is only whitespace after the semicolon or 
it is the last character:
   
   ```java
   int semiColonIndex = sql.indexOf(';');
   boolean stripSemiColon = semiColonIndex >= 0;
   for (int i = semiColonIndex + 1; i < sql.length() && stripSemiColon; i++) {
     stripSemiColon = Character.isWhitespace(sql.charAt(i));
   }
   return stripSemiColon ? sql.substring(0, semiColonIndex) : sql;
   ```
   
   This way terminating semicolons can be stripped, but rejecting semicolons 
which can be ambiguous is left to the parser which has the intelligence to 
discern properly.




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