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 2020/01/14 10:31:06 UTC

[GitHub] [incubator-shardingsphere] tristaZero edited a comment on issue #3914: Optimization for Sharing Parser with Antlr Visitor

tristaZero edited a comment on issue #3914: Optimization for Sharing Parser with Antlr Visitor
URL: https://github.com/apache/incubator-shardingsphere/issues/3914#issuecomment-574108748
 
 
   ## Here is instruction
   
   ### Tasks
   1. Add rule visitors in `MySQLVisitor.java` based on g4 files[1].
   2. Check whether rule name in g4 files is appropriate or not.
   3. Add parsed integrated test for your **new main rule visitor**.
   
   ### Task details
   1. Add rule visitors
   
   1.1 Since `MySQLVisitor.java` extends `MySQLStatementBaseVisitor<ASTNode>.java`, you should overwrite `visitRuleName(ctx)` from `MySQLStatementBaseVisitor<ASTNode>` referring to rules in g4 files.
   1.2 When adding `visitRuleName(ctx)`, you should put it below the corresponding note generally named `xxx.g4` and keep its order same with where it is in `xxx.g4` file.
   1.3 What we need after parsing is those classes implement `SQLStatemnt` interface, so you should parse all necessary rules (add necessary rule visitors) making up `the main rules` in `MySQLStatement.g4`, and then fill necessary `segments` to `xxxSQLStatemnt`.
   
   
   2.Check rule name
   
   2.1 If we do not care one rule (do not add visitor for it), its name should end up with `_` in g4 file. For instance, we do not add visitor for `IDENTIFIER_` in `baseRule.g4`.
   2.2 Otherwise this rule name should not contain `_` in the end.
   2.3 If existing rule name does not accord with the above rules, please fix it.
   
   
   3. Add parsed integrated test
   
   When you successfully add `one main rule visitor`, adding parsed integrated test for it is necessary.
   
   3.1 Copy sql case you need from `./incubator-shardingsphere/sharding-sql-test/src/main/resources/sql/sharding/` to `./incubator-shardingsphere/sharding-sql-test/src/main/resources/sql/visitor/` (`Please note to keep the same directory`). 
   3.2 Copy the corresponding sql parsed result from `./incubator-shardingsphere/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/test/resources/sharding/` to ` ./incubator-shardingsphere/shardingsphere-sql-parser/shardingsphere-sql-parser-test/src/test/resources/visitor/` (`Please note to keep the same directory`).
   3.3 Run `org.apache.shardingsphere.sql.parser.integrate.engine.visitor.VisitorParameterizedParsingTest`.
   3.4 If there is no sql case you need in `./incubator-shardingsphere/sharding-sql-test/src/main/resources/sql/sharding/`, please record it to this issue[2]. P.S, my suggestion is to easily test its parsed result previously.
   
   
   ### Examples
   1. Current functions in `org.apache.shardingsphere.sql.parser.MySQLVisitor` could provide examples for you.
   2. You could learn more the parsed integrated test from test entrance `org.apache.shardingsphere.sql.parser.integrate.engine.visitor.VisitorParameterizedParsingTest`. 
   
   ### Notice
   1. This guideline applys to `OracleVisitor`, `PostrgreSQLVisitor`, `SQLServerVisitor` and `SQL92Visitor` as well.
   
   [1] DALStatement.g4, DCLStatement.g4, DDLStatement.g4, DMLStatement.g4, TCLStatement.g4 and StoreProcedure.g4
   [2] https://github.com/apache/incubator-shardingsphere/issues/3967

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services