Repository: apache/shardingsphere (Java)

Issue:
MySQL 8.0 ALTER TABLE RENAME COLUMN is not parsed into AlterTableStatement
## Bug Report

### Which version of ShardingSphere did you use?

master - d9b4780b4010f1554a1b094972b60181bebf046b

### Expected behavior

```sql
alter table f rename column new_col to renamed_col
```

### Actual behavior

There is nothing about rename column in AlterTableStatement.

![image](https://github.com/apache/shardingsphere/assets/20503072/5190ac1d-e6d6-4c11-85b9-022e889f11c4)




Discussion: @TeslaCN Hi, I would like to try to solve this problem
Welcome @zihaoAK47 



Fix (patch):
diff --git a/parser/sql/dialect/mysql/src/main/antlr4/imports/mysql/BaseRule.g4 b/parser/sql/dialect/mysql/src/main/antlr4/imports/mysql/BaseRule.g4
index ff50f740ab985..f92077d5075e4 100644
--- a/parser/sql/dialect/mysql/src/main/antlr4/imports/mysql/BaseRule.g4
+++ b/parser/sql/dialect/mysql/src/main/antlr4/imports/mysql/BaseRule.g4
@@ -665,6 +665,14 @@ constraintName
     : identifier
     ;
 
+oldColumn
+    : columnName
+    ;
+
+newColumn
+    : columnName
+    ;
+
 delimiterName
     : textOrIdentifier | ('\\'. | ~('\'' | '"' | '`' | '\\'))+
     ; 
diff --git a/parser/sql/dialect/mysql/src/main/antlr4/imports/mysql/DDLStatement.g4 b/parser/sql/dialect/mysql/src/main/antlr4/imports/mysql/DDLStatement.g4
index 77a65e3fef44c..f35513a4326bb 100644
--- a/parser/sql/dialect/mysql/src/main/antlr4/imports/mysql/DDLStatement.g4
+++ b/parser/sql/dialect/mysql/src/main/antlr4/imports/mysql/DDLStatement.g4
@@ -104,7 +104,7 @@ alterListItem
     | ALTER INDEX indexName visibility  # alterIndex
     | ALTER CHECK constraintName constraintEnforcement  # alterCheck
     | ALTER CONSTRAINT constraintName constraintEnforcement # alterConstraint
-    | RENAME COLUMN columnInternalRef=identifier TO identifier  # renameColumn
+    | RENAME COLUMN oldColumn TO newColumn  # renameColumn
     | RENAME (TO | AS)? tableName # alterRenameTable
     | RENAME keyOrIndex indexName TO indexName  # renameIndex
     | CONVERT TO charset charsetName collateClause?  # alterConvert
diff --git a/parser/sql/dialect/mysql/src/main/java/org/apache/shardingsphere/sql/parser/mysql/visitor/statement/type/MySQLDDLStatementVisitor.java b/parser/sql/dialect/mysql/src/main/java/org/apache/shardingsphere/sql/parser/mysql/visitor/statement/type/MySQLDDLStatementVisitor.java
index af0606fb0176b..174a4ea1517eb 100644
--- a/parser/sql/dialect/mysql/src/main/java/org/apache/shardingsphere/sql/parser/mysql/visitor/statement/type/MySQLDDLStatementVisitor.java
+++ b/parser/sql/dialect/mysql/src/main/java/org/apache/shardingsphere/sql/parser/mysql/visitor/statement/type/MySQLDDLStatementVisitor.java
@@ -21,6 +21,7 @@
 import org.apache.shardingsphere.sql.parser.api.ASTNode;
 import org.apache.shardingsphere.sql.parser.api.visitor.statement.type.DDLStatementVisitor;
 import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.AddColumnContext;
+import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.RenameColumnContext;
 import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.AddTableConstraintContext;
 import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.AlterCheckContext;
 import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.AlterConstraintContext;
@@ -104,6 +105,7 @@
 import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.column.alter.ChangeColumnDefinitionSegment;
 import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.column.alter.DropColumnDefinitionSegment;
 import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.column.alter.ModifyColumnDefinitionSegment;
+import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.column.alter.RenameColumnSegment;
 import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.column.position.ColumnAfterPositionSegment;
 import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.column.position.ColumnFirstPositionSegment;
 import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.column.position.ColumnPositionSegment;
@@ -292,6 +294,8 @@ public ASTNode visitAlterTable(final AlterTableContext ctx) {
                     result.getDropIndexDefinitions().add((DropIndexDefinitionSegment) each);
                 } else if (each instanceof RenameIndexDefinitionSegment) {
                     result.getRenameIndexDefinitions().add((RenameIndexDefinitionSegment) each);
+                } else if (each instanceof RenameColumnSegment) {
+                    result.getRenameColumnDefinitions().add((RenameColumnSegment) each);
                 }
             }
         }
@@ -351,6 +355,9 @@ public ASTNode visitAlterList(final AlterListContext ctx) {
             if (each instanceof AlterConvertContext) {
                 result.getValue().add((ConvertTableDefinitionSegment) visit(each));
             }
+            if (each instanceof RenameColumnContext) {
+                result.getValue().add((RenameColumnSegment) visit(each));
+            }
             if (each instanceof RenameIndexContext) {
                 result.getValue().add((RenameIndexDefinitionSegment) visit(each));
             }
@@ -454,6 +461,13 @@ public ASTNode visitAddColumn(final AddColumnContext ctx) {
         return result;
     }
     
+    @Override
+    public ASTNode visitRenameColumn(final RenameColumnContext ctx) {
+        ColumnSegment oldColumnSegment = (ColumnSegment) visit(ctx.oldColumn());
+        ColumnSegment newColumnSegment = (ColumnSegment) visit(ctx.newColumn());
+        return new RenameColumnSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), oldColumnSegment, newColumnSegment);
+    }
+    
     @Override
     public ASTNode visitColumnDefinition(final ColumnDefinitionContext ctx) {
         ColumnSegment column = new ColumnSegment(ctx.column_name.start.getStartIndex(), ctx.column_name.stop.getStopIndex(), (IdentifierValue) visit(ctx.column_name));
diff --git a/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/segment/ddl/column/alter/RenameColumnSegment.java b/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/segment/ddl/column/alter/RenameColumnSegment.java
index d5bbf2b20a845..b0241e5266f5a 100644
--- a/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/segment/ddl/column/alter/RenameColumnSegment.java
+++ b/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/segment/ddl/column/alter/RenameColumnSegment.java
@@ -19,7 +19,7 @@
 
 import lombok.Getter;
 import lombok.RequiredArgsConstructor;
-import org.apache.shardingsphere.sql.parser.sql.common.segment.SQLSegment;
+import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.AlterDefinitionSegment;
 import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.column.ColumnSegment;
 
 /**
@@ -27,7 +27,7 @@
  */
 @RequiredArgsConstructor
 @Getter
-public final class RenameColumnSegment implements SQLSegment {
+public final class RenameColumnSegment implements AlterDefinitionSegment {
     
     private final int startIndex;
     
diff --git a/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/statement/ddl/AlterTableStatement.java b/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/statement/ddl/AlterTableStatement.java
index 7df9a11ea7d9d..7c478c6634626 100644
--- a/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/statement/ddl/AlterTableStatement.java
+++ b/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/statement/ddl/AlterTableStatement.java
@@ -23,6 +23,7 @@
 import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.column.alter.ChangeColumnDefinitionSegment;
 import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.column.alter.DropColumnDefinitionSegment;
 import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.column.alter.ModifyColumnDefinitionSegment;
+import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.column.alter.RenameColumnSegment;
 import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.constraint.alter.AddConstraintDefinitionSegment;
 import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.constraint.alter.DropConstraintDefinitionSegment;
 import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.constraint.alter.ModifyConstraintDefinitionSegment;
@@ -68,6 +69,8 @@ public abstract class AlterTableStatement extends AbstractSQLStatement implement
     
     private final Collection<DropIndexDefinitionSegment> dropIndexDefinitions = new LinkedList<>();
     
+    private final Collection<RenameColumnSegment> renameColumnDefinitions = new LinkedList<>();
+    
     private final Collection<RenameIndexDefinitionSegment> renameIndexDefinitions = new LinkedList<>();
     
     /**