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/02/01 04:45:15 UTC

[GitHub] [incubator-shardingsphere] tristaZero commented on a change in pull request #4123: Add MySQL DDLStatement antlr visitor

tristaZero commented on a change in pull request #4123: Add MySQL DDLStatement antlr visitor
URL: https://github.com/apache/incubator-shardingsphere/pull/4123#discussion_r373757785
 
 

 ##########
 File path: shardingsphere-sql-parser/shardingsphere-sql-parser-mysql/src/main/java/org/apache/shardingsphere/sql/parser/MySQLVisitor.java
 ##########
 @@ -190,6 +227,135 @@ public ASTNode visitCreateUser(final CreateUserContext ctx) {
     }
 
     // DDLStatement.g4
+    @Override
+    public ASTNode visitCreateTable(final CreateTableContext ctx) {
+        CreateTableStatement result = new CreateTableStatement();
+        TableSegment table = (TableSegment) visit(ctx.tableName());
+        result.setTable(table);
+        result.getAllSQLSegments().add(table);
+        CreateDefinitionClause_Context createDefinitionClause = ctx.createDefinitionClause_();
+        if (null != createDefinitionClause) {
+            for (CreateDefinition_Context createDefinition : createDefinitionClause.createDefinitions_().createDefinition_()) {
+                ColumnDefinitionContext columnDefinition = createDefinition.columnDefinition();
+                if (null != columnDefinition) {
+                    ColumnDefinitionSegment columnDefinitionSegment = createColumnDefinitionSegment(columnDefinition, result);
+                    result.getColumnDefinitions().add(columnDefinitionSegment);
+                    result.getAllSQLSegments().add(columnDefinitionSegment);
+                }
+                ConstraintDefinition_Context constraintDefinition = createDefinition.constraintDefinition_();
+                ForeignKeyOption_Context foreignKeyOption = null == constraintDefinition ? null : constraintDefinition.foreignKeyOption_();
+                if (null != foreignKeyOption) {
+                    result.getAllSQLSegments().add((TableSegment) visit(foreignKeyOption.referenceDefinition_().tableName()));
+                }
+            }
+        }
+        CreateLikeClause_Context createLikeClause = ctx.createLikeClause_();
+        if (null != createLikeClause) {
+            result.getAllSQLSegments().add((TableSegment) visit(createLikeClause));
+        }
+        return result;
+    }
+
+    @Override
+    public ASTNode visitAlterTable(final AlterTableContext ctx) {
+        AlterTableStatement result = new AlterTableStatement();
+        TableSegment table = (TableSegment) visit(ctx.tableName());
+        result.setTable(table);
+        result.getAllSQLSegments().add(table);
+        if (null != ctx.alterDefinitionClause_()) {
 
 Review comment:
   The above suggestion applied to the following visitors. Could you review those rather long visitors for optimizing?

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