You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by GitBox <gi...@apache.org> on 2021/08/12 10:33:23 UTC

[GitHub] [shardingsphere] RaigorJiang opened a new issue #11784: [DISCUSS] design a grammar for `Preview SQL`

RaigorJiang opened a new issue #11784:
URL: https://github.com/apache/shardingsphere/issues/11784


   Hi community,
   
   I am designing `Preview SQL` syntax for DistSQL, which has the following characteristics:
   1. `Preview` is a keyword, `SQL` can be any statement, such as SELECT, CREATE, DROP, etc.;
   2. There is at least one blank character between the `Preview` keyword and the `SQL` statement;
   3. It is expected that after ANTLR parses the input text, it will recognize `SQL` as a `String object`;
   
   ### Here is an example:
   input text:
   ```sql
   preview select * from t_order;
   ```
   parse result:
   ![image](https://user-images.githubusercontent.com/5668787/129182411-bfa61a79-4c1a-4c3d-95a0-cc16ca299bd8.png)
   
   
   
   ### There are some difficulties:
   1. We need a lexer grammar that can match any input sentence after the keyword, which did not exist before;
   2. In the existing ANTLR grammar file, we define the following lexer grammar to ignore whitespace characters
   ```antlr
   WS
       : [ \t\r\n] + ->skip
       ;
   ```
   But the `Preview` statement needs to recognize blank characters to distinguish between the keyword and the statement after it;
   3. If the lexer grammar not ignoring spaces is declared in the existing grammar, it will cause the original grammar parsing to be abnormal;
   
   ### Current solution:
   Add `xxxKeyword.g4` and `xxxStatement.g4` to match the special syntax of `Preview SQL` without affecting the original syntax;
   
   The content of `xxxKeyword.g4` is : 
   ```g4
   import Alphabet;
   
   WS
       : [ \t\r\n] + -> skip
       ;
   
   PREVIEW
       : P R E V I E W
       ;
   
   SQLString
       : WS.*
       ;
   ```
   
   and the content of `xxxStatement.g4` is : 
   ```g4
   previewSQL
       : PREVIEW sql
       ;
   
   sql
       : SQLString
       ;
   ```
   
   But there are some effects:
   1. `Preview SQL` cannot be included in CommonDistSQLStatement, a separate file is required;
   2. An additional try catch is required in `DistSQLStatementParserEngine` (because the `preview` grammar cannot be combined with other rules), it may be changed from:
   ```java
   public SQLStatement parse(final String sql) {
           try {
               return new CommonDistSQLStatementParserEngine().parse(sql);
           } catch (final ParseCancellationException | SQLParsingException ignored) {
               return new FeaturedDistSQLStatementParserEngine().parse(sql);
           }
       }
   ```
   
   to 
   
   ```java
   public SQLStatement parse(final String sql) {
           try {
               return new CommonDistSQLStatementParserEngine().parse(sql);
           } catch (final ParseCancellationException | SQLParsingException ignored) {
               try {
                   return new FeaturedDistSQLStatementParserEngine().parse(sql);
               } catch (final SQLParsingException ignoredToo) {
                   return new XXXDistSQLStatementParserEngine().parse(sql);
               }
           }
       }
   ```
   
   3. At the same time, `xxx` now only has `preview grammar`, and will include `parse` and `optimize` in the future.
   So we need to think of a good name.  What about `Special` or `CommonDistSQL2`?
   
   The above are the problems encountered in the design of `Preview SQL` grammar and the solution at present. I hope to get good suggestions, thank you!


-- 
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: notifications-unsubscribe@shardingsphere.apache.org

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



[GitHub] [shardingsphere] terrymanu commented on issue #11784: [DISCUSS] design a grammar for `Preview SQL`

Posted by GitBox <gi...@apache.org>.
terrymanu commented on issue #11784:
URL: https://github.com/apache/shardingsphere/issues/11784#issuecomment-897546052


   CommonDistSQL2 is fine, I prefer it.


-- 
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: notifications-unsubscribe@shardingsphere.apache.org

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



[GitHub] [shardingsphere] RaigorJiang commented on issue #11784: [DISCUSS] design a grammar for `Preview SQL`

Posted by GitBox <gi...@apache.org>.
RaigorJiang commented on issue #11784:
URL: https://github.com/apache/shardingsphere/issues/11784#issuecomment-898100565


   Let's call it `AdvancedDistSQL` first, and replace it with a better name in the future.


-- 
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: notifications-unsubscribe@shardingsphere.apache.org

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



[GitHub] [shardingsphere] RaigorJiang commented on issue #11784: [DISCUSS] design a grammar for `Preview SQL`

Posted by GitBox <gi...@apache.org>.
RaigorJiang commented on issue #11784:
URL: https://github.com/apache/shardingsphere/issues/11784#issuecomment-897548326


   > CommonDistSQL2 is fine, I prefer it.
   
   Thanks for your advice.


-- 
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: notifications-unsubscribe@shardingsphere.apache.org

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



[GitHub] [shardingsphere] RaigorJiang commented on issue #11784: [DISCUSS] design a grammar for `Preview SQL`

Posted by GitBox <gi...@apache.org>.
RaigorJiang commented on issue #11784:
URL: https://github.com/apache/shardingsphere/issues/11784#issuecomment-897532727


   Suddenly I have a new idea, wait for me to try again.  😀


-- 
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: notifications-unsubscribe@shardingsphere.apache.org

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



[GitHub] [shardingsphere] RaigorJiang closed issue #11784: [DISCUSS] design a grammar for `Preview SQL`

Posted by GitBox <gi...@apache.org>.
RaigorJiang closed issue #11784:
URL: https://github.com/apache/shardingsphere/issues/11784


   


-- 
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: notifications-unsubscribe@shardingsphere.apache.org

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