You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by "manxihuanchi (via GitHub)" <gi...@apache.org> on 2023/06/14 11:52:52 UTC

[GitHub] [shardingsphere] manxihuanchi opened a new issue, #26346: Can't get COMMENT

manxihuanchi opened a new issue, #26346:
URL: https://github.com/apache/shardingsphere/issues/26346

   ## Bug Report
   
   
   ### Which version of ShardingSphere did you use?
   shardingsphere-sql-parser-mysql  5.3.2
   shardingsphere-sql-parser-sql92   5.3.2
   
   ### Which project did you use? ShardingSphere-JDBC or ShardingSphere-Proxy?
   shardingsphere-sql-parser-sql92 5.3.2
   ### Expected behavior
   Can get COMMENT
   ### Actual behavior
   Can get COMMENT
   ### Reason analyze (If you can)
   package org.apache.shardingsphere.sql.parser.core;
   /**
    * Parse AST node.
    */
   @RequiredArgsConstructor
   public final class ParseASTNode implements ASTNode {
       
       private final ParseTree parseTree;
       
       private final CommonTokenStream tokenStream;
       
       /**
        * Get root node.
        * 
        * @return root node
        */
       public ParseTree getRootNode() {
           return parseTree.getChild(0);
       }
       
       /**
        * Get hidden tokens.
        * 
        * @return hidden tokens
        */
       public Collection<Token> getHiddenTokens() {
           Collection<Token> result = new LinkedList<>();
           for (Token each : tokenStream.getTokens()) {
               if (Token.HIDDEN_CHANNEL == each.getChannel()) {
   // each.getChannel()    Always 0
                   result.add(each);
               }
           }
           return result;
       }
   }
   
   ### Steps to reproduce the behavior, such as: SQL to execute, sharding rule configuration, when exception occur etc.
   
   ### Example codes for reproduce this issue (such as a github link).
   String oneSql = " CREATE TABLE `t_device`  (
     `device_number` varchar(255)  COMMENT '设备编号',
     `name` varchar(255)  COMMENT '设备名称',
     `specifications_models` varchar(255)  COMMENT '规格型号',
     `manufacturing_date` datetime(0)  COMMENT '制造日期',
     `manufacturers` varchar(255)  COMMENT '制造厂家',
     `start_use_date` varchar(255) COMMENT '启用日期',
     `installation_site` varchar(255)  COMMENT '安装地点',
     `brand` varchar(255)  COMMENT '品牌',
     `device_price` decimal(10, 2)  COMMENT '设备价格',
     `power` varchar(255)  COMMENT '功率'
   );";
   String databaseType = "MYSQL";
                   CacheOption cacheOption = new CacheOption(128, 1024L);
   		SQLParserEngine parserEngine = new SQLParserEngine(databaseType, cacheOption);
   		ParseASTNode parseASTNode = parserEngine.parse(oneSql, false);
   		SQLVisitorEngine visitorEngine = new SQLVisitorEngine(sqlType, "STATEMENT", true, new Properties());
   		SQLStatement sqlStatement = visitorEngine.visit(parseASTNode);
   		TableSchema tableSchema = null;
   		if (sqlStatement instanceof CreateTableStatement) {
   			CreateTableStatement statement = (CreateTableStatement) sqlStatement;
   			Collection<CommentSegment> commentSegments = statement.getCommentSegments();
   			// commentSegments  is null
                }


-- 
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.apache.org

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


[GitHub] [shardingsphere] zihaoAK47 commented on issue #26346: Can't get COMMENT

Posted by "zihaoAK47 (via GitHub)" <gi...@apache.org>.
zihaoAK47 commented on issue #26346:
URL: https://github.com/apache/shardingsphere/issues/26346#issuecomment-1591121730

   @manxihuanchi The Comment attribute currently does not seem to have parsing support.


-- 
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] zihaoAK47 commented on issue #26346: Can't get COMMENT

Posted by "zihaoAK47 (via GitHub)" <gi...@apache.org>.
zihaoAK47 commented on issue #26346:
URL: https://github.com/apache/shardingsphere/issues/26346#issuecomment-1591189364

   @manxihuanchi  Of course :smile: 
   
   1.You can use the Antlr4 plugin to check if the createTable rule correctly parses the above SQL statement rules, as specified in the {HOME}/shardingsphere/parser/sql/dialect/mysql/src/main/antlr4/imports/mysql/DDLStatement.g4
   
   2.If parsing is incorrect, you need to modify the correct parsing rule to enable Antlr4 to parse the SQL statement correctly.
   
   3.The visitCreateTable method of the {HOME}/apache/shardingsphere/parser/sql/dialect/mysql/src/main/java/org/apache/shardingsphere/sql/parser/mysql/visitor/statement/type/MySQLDDLStatementVisitor. java class is used to handle the syntax rules corresponding to the create table
   
   4.You can process and parse the code here to support the COMMENT attribute, which is stored in {HOME}/shardingsphere/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/mysql/ddl/MySQLCreateTableStatement.java
   
   You can refer to the previous pr #25993   


-- 
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] manxihuanchi commented on issue #26346: Can't get COMMENT

Posted by "manxihuanchi (via GitHub)" <gi...@apache.org>.
manxihuanchi commented on issue #26346:
URL: https://github.com/apache/shardingsphere/issues/26346#issuecomment-1591142167

   Can you tell me how to parse it? I want to make changes directly on the source code, which is very important to me


-- 
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] manxihuanchi commented on issue #26346: Can't get COMMENT

Posted by "manxihuanchi (via GitHub)" <gi...@apache.org>.
manxihuanchi commented on issue #26346:
URL: https://github.com/apache/shardingsphere/issues/26346#issuecomment-1591050386

   Actual behavior
   Can't get COMMENT


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