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 4c6e72f5c429b..a0555365bba05 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 @@ -48,6 +48,7 @@ import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.CaseStatementContext; import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.ChangeColumnContext; import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.CharsetNameContext; +import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.CollationNameContext; import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.ColumnDefinitionContext; import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.CompoundStatementContext; import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.CreateDatabaseContext; @@ -101,6 +102,7 @@ import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.TableConstraintDefContext; import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.TableElementContext; import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.TableNameContext; +import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.TextOrIdentifierContext; import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.TruncateTableContext; import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.ValidStatementContext; import org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.WhileStatementContext; @@ -279,6 +281,12 @@ public ASTNode visitCreateTableOptions(final CreateTableOptionsContext ctx) { result.setEngine((EngineSegment) visit(each.engineRef())); } else if (null != each.COMMENT()) { result.setCommentSegment(new CommentSegment(each.string_().getText(), each.string_().getStart().getStartIndex(), each.string_().getStop().getStopIndex())); + } else if (null != each.defaultCharset()) { + Optional.ofNullable(each.defaultCharset().charsetName()).map(CharsetNameContext::textOrIdentifier).map(TextOrIdentifierContext::identifier) + .ifPresent(optional -> result.setCharsetName(optional.getText())); + } else if (null != each.defaultCollation()) { + Optional.ofNullable(each.defaultCollation().collationName()).map(CollationNameContext::textOrIdentifier).map(TextOrIdentifierContext::identifier) + .ifPresent(optional -> result.setCollateName(optional.getText())); } } return result; @@ -576,6 +584,11 @@ public ASTNode visitColumnDefinition(final ColumnDefinitionContext ctx) { ColumnDefinitionSegment result = new ColumnDefinitionSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), column, dataTypeSegment, isPrimaryKey, false); result.getReferencedTables().addAll(getReferencedTables(ctx)); result.setAutoIncrement(isAutoIncrement); + if (null != ctx.fieldDefinition().dataType().charsetWithOptBinary()) { + result.setCharsetName(ctx.fieldDefinition().dataType().charsetWithOptBinary().charsetName().textOrIdentifier().identifier().IDENTIFIER_().getText()); + } + ctx.fieldDefinition().columnAttribute().stream().filter(each -> each.collateClause() != null).findFirst() + .ifPresent(optional -> result.setCollateName(optional.collateClause().collationName().textOrIdentifier().identifier().IDENTIFIER_().getText())); return result; } diff --git a/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/segment/ddl/column/ColumnDefinitionSegment.java b/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/segment/ddl/column/ColumnDefinitionSegment.java index 60a03f1302648..867ef9c242d03 100644 --- a/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/segment/ddl/column/ColumnDefinitionSegment.java +++ b/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/segment/ddl/column/ColumnDefinitionSegment.java @@ -54,4 +54,10 @@ public final class ColumnDefinitionSegment implements CreateDefinitionSegment { @Setter private boolean isRef; + + @Setter + private String charsetName; + + @Setter + private String collateName; } diff --git a/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/segment/ddl/table/CreateTableOptionSegment.java b/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/segment/ddl/table/CreateTableOptionSegment.java index 62fbf3bb6272b..5dab4fbd20a15 100644 --- a/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/segment/ddl/table/CreateTableOptionSegment.java +++ b/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/segment/ddl/table/CreateTableOptionSegment.java @@ -42,6 +42,10 @@ public final class CreateTableOptionSegment implements CreateDefinitionSegment { private CommentSegment commentSegment; + private String charsetName; + + private String collateName; + /** * Get engine. *