tristaZero commented on a change in pull request #4123: Add MySQL DDLStatement
antlr visitor
URL:
https://github.com/apache/incubator-shardingsphere/pull/4123#discussion_r373778942
##########
File path:
shardingsphere-sql-parser/shardingsphere-sql-parser-mysql/src/main/java/org/apache/shardingsphere/sql/parser/MySQLVisitor.java
##########
@@ -871,6 +1051,53 @@ private ASTNode createExpressionSegment(final ASTNode
astNode, final ParserRuleC
return astNode;
}
+ private ColumnDefinitionSegment createColumnDefinitionSegment(final
ColumnDefinitionContext columnDefinition, final DDLStatement statement) {
+ ColumnSegment column = (ColumnSegment)
visit(columnDefinition.columnName());
+ LiteralValue dataType = (LiteralValue)
visit(columnDefinition.dataType().dataTypeName_());
+ boolean isPrimaryKey = false;
+ for (InlineDataType_Context inlineDataType :
columnDefinition.inlineDataType_()) {
+ CommonDataTypeOption_Context commonDataTypeOption =
inlineDataType.commonDataTypeOption_();
+ if (null != commonDataTypeOption) {
+ if (null != commonDataTypeOption.primaryKey()) {
+ isPrimaryKey = true;
+ }
+ if (null != commonDataTypeOption.referenceDefinition_()) {
+ statement.getAllSQLSegments().add((TableSegment)
visit(commonDataTypeOption.referenceDefinition_().tableName()));
+ }
+ }
+ }
+ for (GeneratedDataType_Context generatedDataType:
columnDefinition.generatedDataType_()) {
+ CommonDataTypeOption_Context commonDataTypeOption =
generatedDataType.commonDataTypeOption_();
+ if (null != commonDataTypeOption) {
+ if (null != commonDataTypeOption.primaryKey()) {
+ isPrimaryKey = true;
+ }
+ if (null != commonDataTypeOption.referenceDefinition_()) {
+ statement.getAllSQLSegments().add((TableSegment)
visit(commonDataTypeOption.referenceDefinition_().tableName()));
Review comment:
To create `visitReferenceDefinition_()` is better. Short and simple function
always make peple easy to read. Other than, one function is supposed to focus
on itself, not include its child.
----------------------------------------------------------------
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:
[email protected]
With regards,
Apache Git Services