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 607a2812bc777..b9cc46d59e343 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 @@ -120,7 +120,7 @@ unreservedWord | DATA_RETENTION | TEMPORAL_HISTORY_RETENTION | EDITION | MIXED_PAGE_ALLOCATION | DISABLED | ALLOWED | HADR | MULTI_USER | RESTRICTED_USER | SINGLE_USER | OFFLINE | EMERGENCY | SUSPEND | DATE_CORRELATION_OPTIMIZATION | ELASTIC_POOL | SERVICE_OBJECTIVE | DATABASE_NAME | ALLOW_CONNECTIONS | GEO | NAMED | DATEFIRST | BACKUP_STORAGE_REDUNDANCY | FORCE_FAILOVER_ALLOW_DATA_LOSS | SECONDARY | FAILOVER | DEFAULT_FULLTEXT_LANGUAGE | DEFAULT_LANGUAGE | INLINE | NESTED_TRIGGERS | TRANSFORM_NOISE_WORDS | TWO_DIGIT_YEAR_CUTOFF | PERSISTENT_LOG_BUFFER | DIRECTORY_NAME | DATEFORMAT | DELAYED_DURABILITY | TRANSFER | SCHEMA | PASSWORD | AUTHORIZATION - | MEMBER | SEARCH | TEXT | SECOND + | MEMBER | SEARCH | TEXT | SECOND | PRECISION | VIEWS ; databaseName diff --git a/parser/sql/dialect/sqlserver/src/main/antlr4/imports/sqlserver/DMLStatement.g4 b/parser/sql/dialect/sqlserver/src/main/antlr4/imports/sqlserver/DMLStatement.g4 index 8c56339adfa66..1f9fa961ff7af 100644 --- a/parser/sql/dialect/sqlserver/src/main/antlr4/imports/sqlserver/DMLStatement.g4 +++ b/parser/sql/dialect/sqlserver/src/main/antlr4/imports/sqlserver/DMLStatement.g4 @@ -89,12 +89,14 @@ duplicateSpecification ; projections - : (unqualifiedShorthand | projection | top (unqualifiedShorthand | projection)?) (COMMA_ (unqualifiedShorthand | projection))* + : (projection | top projection?) (COMMA_ projection)* ; projection - : (alias EQ_)? (columnName | expr) | qualifiedShorthand - | (columnName | expr) (AS? alias)? | qualifiedShorthand + : qualifiedShorthand + | unqualifiedShorthand + | (alias EQ_)? (columnName | expr) + | (columnName | expr) (AS? alias)? ; top 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 112ec390d6ff5..1d4579d08ef4f 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 @@ -102,7 +102,6 @@ import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.TableReferenceContext; import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.TableReferencesContext; import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.TopContext; -import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.UnqualifiedShorthandContext; import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.UnreservedWordContext; import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.UpdateContext; import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.ViewNameContext; @@ -851,13 +850,10 @@ private boolean isDistinct(final SelectClauseContext ctx) { @Override public ASTNode visitProjections(final ProjectionsContext ctx) { - Collection projections = new LinkedList<>(); + List projections = new LinkedList<>(); if (null != ctx.top()) { projections.add((ProjectionSegment) visit(ctx.top())); } - for (UnqualifiedShorthandContext each : ctx.unqualifiedShorthand()) { - projections.add(new ShorthandProjectionSegment(each.getStart().getStartIndex(), each.getStop().getStopIndex())); - } for (ProjectionContext each : ctx.projection()) { projections.add((ProjectionSegment) visit(each)); } @@ -1128,7 +1124,6 @@ public ASTNode visitDuplicateSpecification(final DuplicateSpecificationContext c @Override public ASTNode visitProjection(final ProjectionContext ctx) { - // FIXME :The stop index of project is the stop index of projection, instead of alias. if (null != ctx.qualifiedShorthand()) { QualifiedShorthandContext shorthand = ctx.qualifiedShorthand(); ShorthandProjectionSegment result = new ShorthandProjectionSegment(shorthand.getStart().getStartIndex(), shorthand.getStop().getStopIndex()); @@ -1136,6 +1131,9 @@ public ASTNode visitProjection(final ProjectionContext ctx) { result.setOwner(new OwnerSegment(shorthand.identifier().getStart().getStartIndex(), shorthand.identifier().getStop().getStopIndex(), identifier)); return result; } + if (null != ctx.unqualifiedShorthand()) { + return new ShorthandProjectionSegment(ctx.unqualifiedShorthand().getStart().getStartIndex(), ctx.unqualifiedShorthand().getStop().getStopIndex()); + } AliasSegment alias = null == ctx.alias() ? null : (AliasSegment) visit(ctx.alias()); if (null != ctx.columnName()) { ColumnSegment column = (ColumnSegment) visit(ctx.columnName()); diff --git a/test/it/parser/src/main/resources/case/dml/insert.xml b/test/it/parser/src/main/resources/case/dml/insert.xml index 0baf66a99b8ec..cf0a00f588b99 100644 --- a/test/it/parser/src/main/resources/case/dml/insert.xml +++ b/test/it/parser/src/main/resources/case/dml/insert.xml @@ -3005,4 +3005,25 @@ + + + + + + +
+ + +
diff --git a/test/it/parser/src/main/resources/case/dml/select-join.xml b/test/it/parser/src/main/resources/case/dml/select-join.xml index 1947515a46915..5c3bf47e084b2 100644 --- a/test/it/parser/src/main/resources/case/dml/select-join.xml +++ b/test/it/parser/src/main/resources/case/dml/select-join.xml @@ -705,4 +705,201 @@ + + + + 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 7b7c20ee552c8..f133b8efec01e 100644 --- a/test/it/parser/src/main/resources/case/dml/select.xml +++ b/test/it/parser/src/main/resources/case/dml/select.xml @@ -7858,4 +7858,123 @@ + + + + diff --git a/test/it/parser/src/main/resources/sql/supported/dml/insert.xml b/test/it/parser/src/main/resources/sql/supported/dml/insert.xml index 7bca7b5876634..3e01695c742d0 100644 --- a/test/it/parser/src/main/resources/sql/supported/dml/insert.xml +++ b/test/it/parser/src/main/resources/sql/supported/dml/insert.xml @@ -108,4 +108,5 @@ + diff --git a/test/it/parser/src/main/resources/sql/supported/dml/select-join.xml b/test/it/parser/src/main/resources/sql/supported/dml/select-join.xml index f29cb6b6cb099..a5b9ce05371eb 100644 --- a/test/it/parser/src/main/resources/sql/supported/dml/select-join.xml +++ b/test/it/parser/src/main/resources/sql/supported/dml/select-join.xml @@ -34,4 +34,6 @@ + + diff --git a/test/it/parser/src/main/resources/sql/supported/dml/select.xml b/test/it/parser/src/main/resources/sql/supported/dml/select.xml index ea53597659d1a..50185cd9fc30c 100644 --- a/test/it/parser/src/main/resources/sql/supported/dml/select.xml +++ b/test/it/parser/src/main/resources/sql/supported/dml/select.xml @@ -239,4 +239,6 @@ + +