diff --git a/parser/sql/dialect/sqlserver/src/main/antlr4/imports/sqlserver/BaseRule.g4 b/parser/sql/dialect/sqlserver/src/main/antlr4/imports/sqlserver/BaseRule.g4 index 487acd22e1979..c6837bc787418 100644 --- a/parser/sql/dialect/sqlserver/src/main/antlr4/imports/sqlserver/BaseRule.g4 +++ b/parser/sql/dialect/sqlserver/src/main/antlr4/imports/sqlserver/BaseRule.g4 @@ -300,13 +300,17 @@ distinct ; specialFunction - : castFunction | charFunction + : castFunction | charFunction | convertFunction ; castFunction : CAST LP_ expr AS dataType RP_ ; +convertFunction + : CONVERT LP_ dataType COMMA_ expr (COMMA_ NUMBER_)? RP_ + ; + charFunction : CHAR LP_ expr (COMMA_ expr)* (USING ignoredIdentifier)? RP_ ; diff --git a/parser/sql/dialect/sqlserver/src/main/antlr4/imports/sqlserver/Literals.g4 b/parser/sql/dialect/sqlserver/src/main/antlr4/imports/sqlserver/Literals.g4 index 099b735c8af0c..3f259ff749171 100644 --- a/parser/sql/dialect/sqlserver/src/main/antlr4/imports/sqlserver/Literals.g4 +++ b/parser/sql/dialect/sqlserver/src/main/antlr4/imports/sqlserver/Literals.g4 @@ -24,7 +24,7 @@ IDENTIFIER_ ; DELIMITED_IDENTIFIER_ - : (LBT_ | DQ_) [a-zA-Z0-9@$#_.\\/\u0080-\uFFFF ]+ (DQ_ | RBT_) + : (LBT_ | DQ_) [a-zA-Z0-9@$#_,.\\/\u0080-\uFFFF ]+ (DQ_ | RBT_) ; STRING_ diff --git a/parser/sql/dialect/sqlserver/src/main/java/org/apache/shardingsphere/sql/parser/sqlserver/visitor/statement/SQLServerStatementVisitor.java b/parser/sql/dialect/sqlserver/src/main/java/org/apache/shardingsphere/sql/parser/sqlserver/visitor/statement/SQLServerStatementVisitor.java index 4147471516b77..fed3241059e66 100644 --- a/parser/sql/dialect/sqlserver/src/main/java/org/apache/shardingsphere/sql/parser/sqlserver/visitor/statement/SQLServerStatementVisitor.java +++ b/parser/sql/dialect/sqlserver/src/main/java/org/apache/shardingsphere/sql/parser/sqlserver/visitor/statement/SQLServerStatementVisitor.java @@ -42,6 +42,7 @@ import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.ColumnNamesContext; import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.ColumnNamesWithSortContext; import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.ConstraintNameContext; +import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.ConvertFunctionContext; import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.CreateTableAsSelectClauseContext; import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.CteClauseContext; import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.CteClauseSetContext; @@ -598,6 +599,9 @@ public final ASTNode visitSpecialFunction(final SpecialFunctionContext ctx) { if (null != ctx.castFunction()) { return visit(ctx.castFunction()); } + if (null != ctx.convertFunction()) { + return visit(ctx.convertFunction()); + } if (null != ctx.charFunction()) { return visit(ctx.charFunction()); } @@ -618,6 +622,17 @@ public final ASTNode visitCastFunction(final CastFunctionContext ctx) { return result; } + @Override + public ASTNode visitConvertFunction(final ConvertFunctionContext ctx) { + FunctionSegment result = new FunctionSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), ctx.CONVERT().getText(), getOriginalText(ctx)); + result.getParameters().add((DataTypeSegment) visit(ctx.dataType())); + result.getParameters().add((ExpressionSegment) visit(ctx.expr())); + if (null != ctx.NUMBER_()) { + result.getParameters().add(new LiteralExpressionSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), ctx.NUMBER_().getText())); + } + return result; + } + @Override public final ASTNode visitCharFunction(final CharFunctionContext ctx) { calculateParameterCount(ctx.expr()); diff --git a/test/it/parser/src/main/resources/case/dml/select.xml b/test/it/parser/src/main/resources/case/dml/select.xml index fa588d4f47a62..2e4c1d956f77f 100644 --- a/test/it/parser/src/main/resources/case/dml/select.xml +++ b/test/it/parser/src/main/resources/case/dml/select.xml @@ -3771,7 +3771,7 @@ - @@ -3797,6 +3797,299 @@ + + + + + + + + + + + + + + + + + + + + + +