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 2022/04/12 00:23:19 UTC

[GitHub] [shardingsphere] strongduanmu commented on a diff in pull request #16744: support visit and route logic table in comment statement

strongduanmu commented on code in PR #16744:
URL: https://github.com/apache/shardingsphere/pull/16744#discussion_r847837591


##########
shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-opengauss/src/main/java/org/apache/shardingsphere/sql/parser/opengauss/visitor/statement/impl/OpenGaussDDLStatementSQLVisitor.java:
##########
@@ -747,7 +750,35 @@ public ASTNode visitDeclare(final DeclareContext ctx) {
     }
     
     @Override
+    @SuppressWarnings("unchecked")
     public ASTNode visitComment(final CommentContext ctx) {
-        return new OpenGaussCommentStatement();
+        OpenGaussCommentStatement result = new OpenGaussCommentStatement();
+        if (null != ctx.commentClauses().objectTypeAnyName() && null != ctx.commentClauses().objectTypeAnyName().TABLE()) {
+            LinkedList<NameSegment> nameSegments = (LinkedList<NameSegment>) ((CollectionValue<NameSegment>) visit(ctx.commentClauses().anyName())).getValue();
+            findTableName(nameSegments).ifPresent(result::setTable);
+        } else if (null != ctx.commentClauses().COLUMN()) {
+            LinkedList<NameSegment> nameSegments = (LinkedList<NameSegment>) ((CollectionValue<NameSegment>) visit(ctx.commentClauses().anyName())).getValue();
+            nameSegments.pollLast();
+            findTableName(nameSegments).ifPresent(result::setTable);
+        }
+        return result;
+    }
+    
+    private Optional<SimpleTableSegment> findTableName(final LinkedList<NameSegment> nameSegments) {
+        NameSegment tableName = nameSegments.pollLast();
+        if (tableName == null) {

Review Comment:
   Put null to the left condition.



##########
shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-postgresql/src/main/java/org/apache/shardingsphere/sql/parser/postgresql/visitor/statement/impl/PostgreSQLDDLStatementSQLVisitor.java:
##########
@@ -884,8 +887,36 @@ public ASTNode visitDropType(final DropTypeContext ctx) {
     }
     
     @Override
+    @SuppressWarnings("unchecked")
     public ASTNode visitComment(final CommentContext ctx) {
-        return new PostgreSQLCommentStatement();
+        PostgreSQLCommentStatement result = new PostgreSQLCommentStatement();
+        if (null != ctx.commentClauses().objectTypeAnyName() && null != ctx.commentClauses().objectTypeAnyName().TABLE()) {
+            LinkedList<NameSegment> nameSegments = (LinkedList<NameSegment>) ((CollectionValue<NameSegment>) visit(ctx.commentClauses().anyName())).getValue();

Review Comment:
   Please replace LinkedList with Collection.



##########
shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-opengauss/src/main/java/org/apache/shardingsphere/sql/parser/opengauss/visitor/statement/impl/OpenGaussDDLStatementSQLVisitor.java:
##########
@@ -747,7 +750,35 @@ public ASTNode visitDeclare(final DeclareContext ctx) {
     }
     
     @Override
+    @SuppressWarnings("unchecked")
     public ASTNode visitComment(final CommentContext ctx) {
-        return new OpenGaussCommentStatement();
+        OpenGaussCommentStatement result = new OpenGaussCommentStatement();
+        if (null != ctx.commentClauses().objectTypeAnyName() && null != ctx.commentClauses().objectTypeAnyName().TABLE()) {
+            LinkedList<NameSegment> nameSegments = (LinkedList<NameSegment>) ((CollectionValue<NameSegment>) visit(ctx.commentClauses().anyName())).getValue();

Review Comment:
   Please replace LinkedList with Collection.



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