From dbf6a86750d44d9f6e8691bdd1ffdd11151112db Mon Sep 17 00:00:00 2001 From: yydeng626 Date: Tue, 19 Dec 2023 18:20:25 +0800 Subject: [PATCH 1/7] draft --- .../main/antlr4/imports/sqlserver/BaseRule.g4 | 6 +- .../antlr4/imports/sqlserver/DMLStatement.g4 | 17 ++- .../main/antlr4/imports/sqlserver/Keyword.g4 | 7 + .../statement/SQLServerStatementVisitor.java | 137 +++--------------- .../internal/SQLServerParserTest.java | 36 +++++ .../sql/parser/sql/common/enums/JoinType.java | 2 +- .../src/main/resources/case/dml/select.xml | 13 ++ .../resources/sql/supported/dml/select.xml | 1 + 8 files changed, 98 insertions(+), 121 deletions(-) create mode 100644 parser/sql/dialect/sqlserver/src/test/java/org/apache/shardingsphere/test/it/sql/parser/it/sqlserver/internal/SQLServerParserTest.java 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 27e745e4eeca8..c315a9e6ee09c 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 + | MEMBER | SEARCH | PROVIDER ; databaseName @@ -524,3 +524,7 @@ entityType ifExists : IF EXISTS ; + +tableValuedFunction + : STRING_SPLIT LP_ columnName COMMA_ stringLiterals (COMMA_ (bitValueLiterals|numberLiterals|nullValueLiterals))? RP_ + ; 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 e868949cba966..b0ac3edb19800 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 @@ -20,7 +20,7 @@ grammar DMLStatement; import BaseRule; insert - : withClause? INSERT top? INTO? tableName (AS? alias)? (insertDefaultValue | insertValuesClause | insertSelectClause) + : withClause? INSERT top? INTO? tableName (AS? alias)? (insertDefaultValue | insertValuesClause | insertSelectClause | insertExecuteClause) ; insertDefaultValue @@ -35,6 +35,18 @@ insertSelectClause : columnNames? outputClause? select ; +insertExecuteClause + : columnNames? outputClause? (EXEC | EXECUTE) procedureName procedureParameters + ; + +procedureParameters + : ( procedureParameter (COMMA_ procedureParameter)* )? + ; + +procedureParameter + : identifier EQ_ literals + ; + update : withClause? UPDATE top? tableReferences setAssignmentsClause whereClause? (OPTION queryHint)? ; @@ -125,12 +137,13 @@ tableReference ; tableFactor - : tableName (AS? alias)? | subquery AS? alias columnNames? | LP_ tableReferences RP_ + : tableName (AS? alias)? | tableValuedFunction (AS? alias)? | subquery AS? alias columnNames? | LP_ tableReferences RP_ ; joinedTable : NATURAL? ((INNER | CROSS)? JOIN) tableFactor joinSpecification? | NATURAL? (LEFT | RIGHT | FULL) OUTER? JOIN tableFactor joinSpecification? + | (CROSS | OUTER) APPLY tableFactor? ; joinSpecification diff --git a/parser/sql/dialect/sqlserver/src/main/antlr4/imports/sqlserver/Keyword.g4 b/parser/sql/dialect/sqlserver/src/main/antlr4/imports/sqlserver/Keyword.g4 index 66c214d290cea..e448a839f977e 100644 --- a/parser/sql/dialect/sqlserver/src/main/antlr4/imports/sqlserver/Keyword.g4 +++ b/parser/sql/dialect/sqlserver/src/main/antlr4/imports/sqlserver/Keyword.g4 @@ -692,3 +692,10 @@ WITHOUT : W I T H O U T ; +APPLY + : A P P L Y + ; + +STRING_SPLIT + : S T R I N G UL_ S P L I T + ; \ No newline at end of file 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 af86cd13b07b6..69de174ed30c3 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 @@ -25,88 +25,7 @@ import org.antlr.v4.runtime.tree.TerminalNode; import org.apache.shardingsphere.sql.parser.api.ASTNode; import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementBaseVisitor; -import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.AggregationClauseContext; -import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.AggregationFunctionContext; -import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.AliasContext; -import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.AssignmentContext; -import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.AssignmentValueContext; -import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.AssignmentValuesContext; -import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.BitExprContext; -import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.BitValueLiteralsContext; -import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.BooleanLiteralsContext; -import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.BooleanPrimaryContext; -import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.CastFunctionContext; -import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.CharFunctionContext; -import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.ColumnNameContext; -import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.ColumnNameWithSortContext; -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; -import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.DatabaseNameContext; -import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.DataTypeContext; -import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.DataTypeLengthContext; -import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.DataTypeNameContext; -import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.DeleteContext; -import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.DelimitedIdentifierContext; -import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.DuplicateSpecificationContext; -import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.ExprContext; -import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.FromClauseContext; -import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.FunctionCallContext; -import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.GroupByClauseContext; -import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.HavingClauseContext; -import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.HexadecimalLiteralsContext; -import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.IdentifierContext; -import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.IndexNameContext; -import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.InsertContext; -import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.InsertDefaultValueContext; -import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.InsertSelectClauseContext; -import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.InsertValuesClauseContext; -import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.JoinSpecificationContext; -import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.JoinedTableContext; -import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.LiteralsContext; -import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.MultipleTableNamesContext; -import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.MultipleTablesClauseContext; -import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.NullValueLiteralsContext; -import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.NumberLiteralsContext; -import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.OrderByClauseContext; -import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.OrderByItemContext; -import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.OutputClauseContext; -import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.OutputTableNameContext; -import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.OutputWithColumnContext; -import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.OutputWithColumnsContext; -import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.OwnerContext; -import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.ParameterMarkerContext; -import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.PredicateContext; -import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.ProjectionContext; -import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.ProjectionsContext; -import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.QualifiedShorthandContext; -import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.RegularFunctionContext; -import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.RegularIdentifierContext; -import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.SchemaNameContext; -import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.ScriptVariableNameContext; -import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.SelectClauseContext; -import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.SelectContext; -import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.SetAssignmentsClauseContext; -import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.SimpleExprContext; -import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.SingleTableClauseContext; -import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.SpecialFunctionContext; -import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.StringLiteralsContext; -import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.SubqueryContext; -import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.TableFactorContext; -import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.TableNameContext; -import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.TableNamesContext; -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.UnreservedWordContext; -import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.UpdateContext; -import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.ViewNameContext; -import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.WhereClauseContext; -import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.WithClauseContext; +import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.*; import org.apache.shardingsphere.sql.parser.sql.common.enums.AggregationType; import org.apache.shardingsphere.sql.parser.sql.common.enums.JoinType; import org.apache.shardingsphere.sql.parser.sql.common.enums.OrderDirection; @@ -120,27 +39,14 @@ import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.assignment.SetAssignmentSegment; import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.column.ColumnSegment; import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.column.InsertColumnsSegment; -import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.BetweenExpression; -import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.BinaryOperationExpression; -import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.ExpressionSegment; -import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.FunctionSegment; -import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.InExpression; -import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.ListExpression; -import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.NotExpression; +import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.*; import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.complex.CommonExpressionSegment; import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.complex.CommonTableExpressionSegment; import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.simple.LiteralExpressionSegment; import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.simple.ParameterMarkerExpressionSegment; import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.subquery.SubqueryExpressionSegment; import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.subquery.SubquerySegment; -import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.item.AggregationDistinctProjectionSegment; -import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.item.AggregationProjectionSegment; -import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.item.ColumnProjectionSegment; -import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.item.ExpressionProjectionSegment; -import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.item.ProjectionSegment; -import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.item.ProjectionsSegment; -import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.item.ShorthandProjectionSegment; -import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.item.SubqueryProjectionSegment; +import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.item.*; import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.order.GroupBySegment; import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.order.OrderBySegment; import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.order.item.ColumnOrderByItemSegment; @@ -157,28 +63,13 @@ import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.pagination.top.TopProjectionSegment; import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.predicate.HavingSegment; import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.predicate.WhereSegment; -import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.AliasSegment; -import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.DataTypeLengthSegment; -import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.DataTypeSegment; -import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.OutputSegment; -import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.OwnerSegment; -import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.ParameterMarkerSegment; -import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.WithSegment; -import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.DeleteMultiTableSegment; -import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.JoinTableSegment; -import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.SimpleTableSegment; -import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.SubqueryTableSegment; -import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.TableNameSegment; -import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.TableSegment; +import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.*; +import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.*; import org.apache.shardingsphere.sql.parser.sql.common.util.SQLUtils; import org.apache.shardingsphere.sql.parser.sql.common.value.collection.CollectionValue; import org.apache.shardingsphere.sql.parser.sql.common.value.identifier.IdentifierValue; import org.apache.shardingsphere.sql.parser.sql.common.value.keyword.KeywordValue; -import org.apache.shardingsphere.sql.parser.sql.common.value.literal.impl.BooleanLiteralValue; -import org.apache.shardingsphere.sql.parser.sql.common.value.literal.impl.NullLiteralValue; -import org.apache.shardingsphere.sql.parser.sql.common.value.literal.impl.NumberLiteralValue; -import org.apache.shardingsphere.sql.parser.sql.common.value.literal.impl.OtherLiteralValue; -import org.apache.shardingsphere.sql.parser.sql.common.value.literal.impl.StringLiteralValue; +import org.apache.shardingsphere.sql.parser.sql.common.value.literal.impl.*; import org.apache.shardingsphere.sql.parser.sql.common.value.parametermarker.ParameterMarkerValue; import org.apache.shardingsphere.sql.parser.sql.dialect.statement.sqlserver.ddl.SQLServerCreateTableStatement; import org.apache.shardingsphere.sql.parser.sql.dialect.statement.sqlserver.dml.SQLServerDeleteStatement; @@ -913,7 +804,8 @@ public ASTNode visitInsert(final InsertContext ctx) { result = (SQLServerInsertStatement) visit(ctx.insertDefaultValue()); } else if (null != ctx.insertValuesClause()) { result = (SQLServerInsertStatement) visit(ctx.insertValuesClause()); - } else { + } + else { result = (SQLServerInsertStatement) visit(ctx.insertSelectClause()); } if (null != ctx.withClause()) { @@ -1258,6 +1150,15 @@ public ASTNode visitTableFactor(final TableFactorContext ctx) { } return result; } + if(null != ctx.tableValuedFunction()) { + FunctionSegment functionSegment = (FunctionSegment) visit(ctx.tableValuedFunction()); + FunctionTableSegment result = new FunctionTableSegment(ctx.start.getStartIndex(),ctx.stop.getStopIndex(),functionSegment); + if (null != ctx.alias()) { + result.setAlias((AliasSegment) visit(ctx.alias())); + } + return result; + } + return visit(ctx.tableReferences()); } @@ -1274,7 +1175,7 @@ private JoinTableSegment visitJoinedTable(final JoinedTableContext ctx, final Ta } return result; } - + private String getJoinType(final JoinedTableContext ctx) { if (null != ctx.LEFT()) { return JoinType.LEFT.name(); @@ -1286,6 +1187,8 @@ private String getJoinType(final JoinedTableContext ctx) { return JoinType.INNER.name(); } else if (null != ctx.CROSS()) { return JoinType.CROSS.name(); + }else if(null != ctx.APPLY()) { + return JoinType.APPLY.name(); } return JoinType.INNER.name(); } diff --git a/parser/sql/dialect/sqlserver/src/test/java/org/apache/shardingsphere/test/it/sql/parser/it/sqlserver/internal/SQLServerParserTest.java b/parser/sql/dialect/sqlserver/src/test/java/org/apache/shardingsphere/test/it/sql/parser/it/sqlserver/internal/SQLServerParserTest.java new file mode 100644 index 0000000000000..b49b27128c3c4 --- /dev/null +++ b/parser/sql/dialect/sqlserver/src/test/java/org/apache/shardingsphere/test/it/sql/parser/it/sqlserver/internal/SQLServerParserTest.java @@ -0,0 +1,36 @@ +package org.apache.shardingsphere.test.it.sql.parser.it.sqlserver.internal; + +import org.apache.shardingsphere.infra.database.core.type.DatabaseType; +import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader; +import org.apache.shardingsphere.infra.util.json.JsonUtils; +import org.apache.shardingsphere.sql.parser.api.SQLStatementVisitorEngine; +import org.apache.shardingsphere.sql.parser.core.ParseASTNode; +import org.apache.shardingsphere.sql.parser.core.database.parser.SQLParserExecutor; +import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement; +import org.junit.jupiter.api.Test; + +/** + * Example generator entrance. + */ +public class SQLServerParserTest { + + + /** + * Main entrance. + * + */ + @Test + public void testExecuteSQL() { + String sql = "INSERT INTO iris_rx_data (\"Sepal.Length\", \"Sepal.Width\", \"Petal.Length\", \"Petal.Width\" , \"Species\")\n" + + "EXECUTE sp_execute_external_script\n" + + " @language = N'R'\n" + + " , @script = N'iris_data <- iris'"; + DatabaseType databaseType = TypedSPILoader.getService(DatabaseType.class, "SQLServer"); + SQLParserExecutor sqlParserExecutor = new SQLParserExecutor(databaseType); + ParseASTNode parse = sqlParserExecutor.parse(sql); + + SQLStatement visit = new SQLStatementVisitorEngine(databaseType, true).visit(parse); + + System.out.println(JsonUtils.toJsonString(visit)); + } +} diff --git a/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/enums/JoinType.java b/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/enums/JoinType.java index b714ce63a29fe..15adb192ac0d9 100644 --- a/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/enums/JoinType.java +++ b/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/enums/JoinType.java @@ -22,5 +22,5 @@ */ public enum JoinType { - INNER, FULL, CROSS, LEFT, RIGHT, COMMA + INNER, FULL, CROSS, LEFT, RIGHT, COMMA, APPLY } 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 859271a97e124..ed8cf48b22840 100644 --- a/test/it/parser/src/main/resources/case/dml/select.xml +++ b/test/it/parser/src/main/resources/case/dml/select.xml @@ -7681,4 +7681,17 @@ + + 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 885b7d41f48a2..9485c164b8065 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 @@ -232,4 +232,5 @@ + From 56d9c7246d74c8bced57425f6715a6f6fc4bee9f Mon Sep 17 00:00:00 2001 From: yydeng626 Date: Tue, 2 Jan 2024 14:10:58 +0800 Subject: [PATCH 2/7] Support parsing SQL Server SELECT name, sql --- .../main/antlr4/imports/sqlserver/BaseRule.g4 | 4 -- .../main/antlr4/imports/sqlserver/Keyword.g4 | 4 -- .../statement/SQLServerStatementVisitor.java | 4 +- .../handler/dml/InsertStatementHandler.java | 24 +++++++ .../segment/sqlserver/exec/ExecSegment.java | 45 +++++++++++++ .../sqlserver/dml/SQLServerCallStatement.java | 40 +++++++++++ .../dml/SQLServerInsertStatement.java | 12 ++++ .../insert/InsertExecClauseAssert.java | 67 +++++++++++++++++++ .../dml/impl/InsertStatementAssert.java | 13 ++++ .../segment/impl/exec/ExpectedExecClause.java | 46 +++++++++++++ .../dml/InsertStatementTestCase.java | 8 ++- .../src/main/resources/case/dml/insert.xml | 37 ++++++++++ .../case/dml/select-special-function.xml | 44 +++++++++++- .../resources/case/dml/select-sub-query.xml | 46 +++++++++++++ .../resources/sql/supported/dml/insert.xml | 1 + .../supported/dml/select-special-function.xml | 1 + .../sql/supported/dml/select-sub-query.xml | 1 + 17 files changed, 383 insertions(+), 14 deletions(-) create mode 100644 parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/segment/sqlserver/exec/ExecSegment.java create mode 100644 parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/sqlserver/dml/SQLServerCallStatement.java create mode 100644 test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/segment/insert/InsertExecClauseAssert.java create mode 100644 test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/segment/impl/exec/ExpectedExecClause.java 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 77f6d6ae45a21..26db46ca71954 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 @@ -524,7 +524,3 @@ entityType ifExists : IF EXISTS ; - -tableValuedFunction - : STRING_SPLIT LP_ columnName COMMA_ stringLiterals (COMMA_ (bitValueLiterals|numberLiterals|nullValueLiterals))? RP_ - ; diff --git a/parser/sql/dialect/sqlserver/src/main/antlr4/imports/sqlserver/Keyword.g4 b/parser/sql/dialect/sqlserver/src/main/antlr4/imports/sqlserver/Keyword.g4 index e448a839f977e..e319733baf0b2 100644 --- a/parser/sql/dialect/sqlserver/src/main/antlr4/imports/sqlserver/Keyword.g4 +++ b/parser/sql/dialect/sqlserver/src/main/antlr4/imports/sqlserver/Keyword.g4 @@ -694,8 +694,4 @@ WITHOUT APPLY : A P P L Y - ; - -STRING_SPLIT - : S T R I N G UL_ S P L I T ; \ No newline at end of file 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 6418edc943447..112ec390d6ff5 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 @@ -1225,11 +1225,11 @@ private ASTNode createProjection(final ProjectionContext ctx, final AliasSegment private int getStartIndexWithAlias(final SQLSegment sqlSegment, final AliasSegment alias) { return null != alias && alias.getStartIndex() < sqlSegment.getStartIndex() ? alias.getStartIndex() : sqlSegment.getStartIndex(); } - + private int getStopIndexWithAlias(final SQLSegment sqlSegment, final AliasSegment alias) { return null != alias && alias.getStopIndex() > sqlSegment.getStopIndex() ? alias.getStopIndex() : sqlSegment.getStopIndex(); } - + @Override public ASTNode visitFromClause(final FromClauseContext ctx) { return visit(ctx.tableReferences()); diff --git a/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/handler/dml/InsertStatementHandler.java b/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/handler/dml/InsertStatementHandler.java index 65bcfbe39bf46..1c74f68182ce4 100644 --- a/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/handler/dml/InsertStatementHandler.java +++ b/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/handler/dml/InsertStatementHandler.java @@ -30,6 +30,7 @@ import org.apache.shardingsphere.sql.parser.sql.dialect.segment.oracle.table.MultiTableConditionalIntoSegment; import org.apache.shardingsphere.sql.parser.sql.dialect.segment.oracle.table.MultiTableInsertIntoSegment; import org.apache.shardingsphere.sql.parser.sql.dialect.segment.oracle.table.MultiTableInsertType; +import org.apache.shardingsphere.sql.parser.sql.dialect.segment.sqlserver.exec.ExecSegment; import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dml.MySQLInsertStatement; import org.apache.shardingsphere.sql.parser.sql.dialect.statement.opengauss.dml.OpenGaussInsertStatement; import org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.dml.OracleInsertStatement; @@ -295,4 +296,27 @@ public static void setWhereSegment(final InsertStatement insertStatement, final ((OracleInsertStatement) insertStatement).setWhere(whereSegment); } } + + /** + * get execute segment. + * @param insertStatement insert statement + * @return execute segment + */ + public static Optional getExecSegment(final InsertStatement insertStatement) { + if (insertStatement instanceof SQLServerInsertStatement) { + return ((SQLServerInsertStatement) insertStatement).getExecSegment(); + } + return Optional.empty(); + } + + /** + * set execute segment. + * @param insertStatement insert statement + * @param execSegment execute segment + */ + public static void setExecSegment(final InsertStatement insertStatement, final ExecSegment execSegment) { + if (insertStatement instanceof SQLServerInsertStatement) { + ((SQLServerInsertStatement) insertStatement).setExecSegment(execSegment); + } + } } diff --git a/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/segment/sqlserver/exec/ExecSegment.java b/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/segment/sqlserver/exec/ExecSegment.java new file mode 100644 index 0000000000000..7fabad9cf0461 --- /dev/null +++ b/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/segment/sqlserver/exec/ExecSegment.java @@ -0,0 +1,45 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.shardingsphere.sql.parser.sql.dialect.segment.sqlserver.exec; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import lombok.Setter; +import org.apache.shardingsphere.sql.parser.sql.common.segment.SQLSegment; +import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.routine.FunctionNameSegment; +import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.ExpressionSegment; + +import java.util.Collection; +import java.util.LinkedList; + +/** + * execute segment. + */ +@RequiredArgsConstructor +@Getter +public class ExecSegment implements SQLSegment { + + private final int startIndex; + + private final int stopIndex; + + @Setter + private FunctionNameSegment procedureName; + + private Collection expressionSegments = new LinkedList<>(); +} diff --git a/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/sqlserver/dml/SQLServerCallStatement.java b/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/sqlserver/dml/SQLServerCallStatement.java new file mode 100644 index 0000000000000..1550d51dbc182 --- /dev/null +++ b/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/sqlserver/dml/SQLServerCallStatement.java @@ -0,0 +1,40 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.shardingsphere.sql.parser.sql.dialect.statement.sqlserver.dml; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.ExpressionSegment; +import org.apache.shardingsphere.sql.parser.sql.common.statement.dml.CallStatement; +import org.apache.shardingsphere.sql.parser.sql.dialect.statement.sqlserver.SQLServerStatement; + +import java.util.List; + +/** + * MySQL call statement. + */ +@AllArgsConstructor +@NoArgsConstructor +@Getter +public final class SQLServerCallStatement extends CallStatement implements SQLServerStatement { + + private String procedureName; + + private List parameters; +} diff --git a/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/sqlserver/dml/SQLServerInsertStatement.java b/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/sqlserver/dml/SQLServerInsertStatement.java index 501188f02428a..aa4e9cbe5a06b 100644 --- a/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/sqlserver/dml/SQLServerInsertStatement.java +++ b/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/sqlserver/dml/SQLServerInsertStatement.java @@ -21,6 +21,7 @@ import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.OutputSegment; import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.WithSegment; import org.apache.shardingsphere.sql.parser.sql.common.statement.dml.InsertStatement; +import org.apache.shardingsphere.sql.parser.sql.dialect.segment.sqlserver.exec.ExecSegment; import org.apache.shardingsphere.sql.parser.sql.dialect.statement.sqlserver.SQLServerStatement; import java.util.Optional; @@ -35,6 +36,8 @@ public final class SQLServerInsertStatement extends InsertStatement implements S private OutputSegment outputSegment; + private ExecSegment execSegment; + /** * Get with segment. * @@ -52,4 +55,13 @@ public Optional getWithSegment() { public Optional getOutputSegment() { return Optional.ofNullable(outputSegment); } + + /** + * Get execute segment. + * + * @return execute segment. + */ + public Optional getExecSegment() { + return Optional.ofNullable(execSegment); + } } diff --git a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/segment/insert/InsertExecClauseAssert.java b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/segment/insert/InsertExecClauseAssert.java new file mode 100644 index 0000000000000..8a335daa24b3b --- /dev/null +++ b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/segment/insert/InsertExecClauseAssert.java @@ -0,0 +1,67 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.shardingsphere.test.it.sql.parser.internal.asserts.segment.insert; + +import lombok.AccessLevel; +import lombok.NoArgsConstructor; +import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.ExpressionSegment; +import org.apache.shardingsphere.sql.parser.sql.dialect.segment.sqlserver.exec.ExecSegment; +import org.apache.shardingsphere.test.it.sql.parser.internal.asserts.SQLCaseAssertContext; +import org.apache.shardingsphere.test.it.sql.parser.internal.asserts.segment.SQLSegmentAssert; +import org.apache.shardingsphere.test.it.sql.parser.internal.asserts.segment.expression.ExpressionAssert; +import org.apache.shardingsphere.test.it.sql.parser.internal.asserts.segment.owner.OwnerAssert; +import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.segment.impl.exec.ExpectedExecClause; +import org.hamcrest.CoreMatchers; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +/** + * insert execute clause assert. + **/ +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class InsertExecClauseAssert { + + /** + * Assert actual execute segment is correct with expected execute clause. + * @param assertContext assert context + * @param actual actual execute segment + * @param expected expected execute clause + */ + public static void assertIs(final SQLCaseAssertContext assertContext, final ExecSegment actual, final ExpectedExecClause expected) { + assertThat(assertContext.getText("exec procedure name assertion error: "), actual.getProcedureName().getIdentifier().getValue(), CoreMatchers.is(expected.getName())); + if (null == expected.getOwner()) { + assertFalse(actual.getProcedureName().getOwner().isPresent(), assertContext.getText("Actual owner should not exist.")); + } else { + assertTrue(actual.getProcedureName().getOwner().isPresent(), assertContext.getText("Actual owner should exist.")); + OwnerAssert.assertIs(assertContext, actual.getProcedureName().getOwner().get(), expected.getOwner()); + } + + if (null == expected.getParameters()) { + assertThat(assertContext.getText("exec procedure parameters assertion error: "), actual.getExpressionSegments().size(), CoreMatchers.is(expected.getParameters().size())); + } else { + int count = 0; + for (ExpressionSegment expressionSegment : actual.getExpressionSegments()) { + ExpressionAssert.assertExpression(assertContext, expressionSegment, expected.getParameters().get(count)); + count++; + } + } + SQLSegmentAssert.assertIs(assertContext, actual, expected); + } +} diff --git a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/statement/dml/impl/InsertStatementAssert.java b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/statement/dml/impl/InsertStatementAssert.java index 6e8895ccbfdd2..6ec82b77b700e 100644 --- a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/statement/dml/impl/InsertStatementAssert.java +++ b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/statement/dml/impl/InsertStatementAssert.java @@ -29,7 +29,9 @@ import org.apache.shardingsphere.sql.parser.sql.dialect.segment.oracle.table.MultiTableConditionalIntoSegment; import org.apache.shardingsphere.sql.parser.sql.dialect.segment.oracle.table.MultiTableInsertIntoSegment; import org.apache.shardingsphere.sql.parser.sql.dialect.segment.oracle.table.MultiTableInsertType; +import org.apache.shardingsphere.sql.parser.sql.dialect.segment.sqlserver.exec.ExecSegment; import org.apache.shardingsphere.test.it.sql.parser.internal.asserts.SQLCaseAssertContext; +import org.apache.shardingsphere.test.it.sql.parser.internal.asserts.segment.insert.InsertExecClauseAssert; import org.apache.shardingsphere.test.it.sql.parser.internal.asserts.segment.insert.InsertColumnsClauseAssert; import org.apache.shardingsphere.test.it.sql.parser.internal.asserts.segment.insert.InsertValuesClauseAssert; import org.apache.shardingsphere.test.it.sql.parser.internal.asserts.segment.insert.MultiTableConditionalIntoClauseAssert; @@ -77,6 +79,7 @@ public static void assertIs(final SQLCaseAssertContext assertContext, final Inse assertMultiTableInsertIntoClause(assertContext, actual, expected); assertMultiTableConditionalIntoClause(assertContext, actual, expected); assertReturningClause(assertContext, actual, expected); + assertInsertExecClause(assertContext, actual, expected); } private static void assertTable(final SQLCaseAssertContext assertContext, final InsertStatement actual, final InsertStatementTestCase expected) { @@ -195,4 +198,14 @@ private static void assertReturningClause(final SQLCaseAssertContext assertConte ReturningClauseAssert.assertIs(assertContext, returningSegment.get(), expected.getReturningClause()); } } + + private static void assertInsertExecClause(final SQLCaseAssertContext assertContext, final InsertStatement actual, final InsertStatementTestCase expected) { + Optional execSegment = InsertStatementHandler.getExecSegment(actual); + if (null == expected.getExecClause()) { + assertFalse(execSegment.isPresent(), assertContext.getText("Actual exec segment should not exist.")); + } else { + assertTrue(execSegment.isPresent(), assertContext.getText("Actual exec segment should exist.")); + InsertExecClauseAssert.assertIs(assertContext, execSegment.get(), expected.getExecClause()); + } + } } diff --git a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/segment/impl/exec/ExpectedExecClause.java b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/segment/impl/exec/ExpectedExecClause.java new file mode 100644 index 0000000000000..edbd3abb358f1 --- /dev/null +++ b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/segment/impl/exec/ExpectedExecClause.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.segment.impl.exec; + +import lombok.Getter; +import lombok.Setter; +import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.segment.AbstractExpectedSQLSegment; +import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.segment.impl.expr.ExpectedExpression; +import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.segment.impl.table.ExpectedOwner; + +import javax.xml.bind.annotation.XmlAttribute; +import javax.xml.bind.annotation.XmlElement; +import java.util.LinkedList; +import java.util.List; + +/** + * Expected procedure name. + */ +@Getter +@Setter +public final class ExpectedExecClause extends AbstractExpectedSQLSegment { + + @XmlAttribute + private String name; + + @XmlElement + private ExpectedOwner owner; + + @XmlElement(name = "parameter") + private final List parameters = new LinkedList<>(); +} diff --git a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/statement/dml/InsertStatementTestCase.java b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/statement/dml/InsertStatementTestCase.java index 404e58ad87f66..f2796de3263ae 100644 --- a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/statement/dml/InsertStatementTestCase.java +++ b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/statement/dml/InsertStatementTestCase.java @@ -20,12 +20,13 @@ import lombok.Getter; import lombok.Setter; import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.SQLParserTestCase; +import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.segment.impl.exec.ExpectedExecClause; import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.segment.impl.insert.ExpectedInsertColumnsClause; import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.segment.impl.insert.ExpectedInsertValuesClause; -import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.segment.impl.insert.ExpectedMultiTableConditionalIntoClause; -import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.segment.impl.insert.ExpectedMultiTableInsertIntoClause; import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.segment.impl.insert.ExpectedMultiTableInsertType; import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.segment.impl.insert.ExpectedOnDuplicateKeyColumns; +import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.segment.impl.insert.ExpectedMultiTableInsertIntoClause; +import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.segment.impl.insert.ExpectedMultiTableConditionalIntoClause; import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.segment.impl.insert.ExpectedReturningClause; import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.segment.impl.output.ExpectedOutputClause; import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.segment.impl.set.ExpectedSetClause; @@ -83,4 +84,7 @@ public final class InsertStatementTestCase extends SQLParserTestCase { @XmlElement(name = "where") private ExpectedWhereClause whereClause; + + @XmlElement(name = "exec") + private ExpectedExecClause execClause; } 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..0129cfc0173be 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,41 @@ + + + + + + + + + + + + + + + + + = + + + + + + + + + + + = + + + + + + + + + diff --git a/test/it/parser/src/main/resources/case/dml/select-special-function.xml b/test/it/parser/src/main/resources/case/dml/select-special-function.xml index 44ef9346357b7..dab47570d3d26 100644 --- a/test/it/parser/src/main/resources/case/dml/select-special-function.xml +++ b/test/it/parser/src/main/resources/case/dml/select-special-function.xml @@ -462,7 +462,7 @@ - + - + + + + + diff --git a/test/it/parser/src/main/resources/case/dml/select-sub-query.xml b/test/it/parser/src/main/resources/case/dml/select-sub-query.xml index f07dc55427765..43631b45468ec 100644 --- a/test/it/parser/src/main/resources/case/dml/select-sub-query.xml +++ b/test/it/parser/src/main/resources/case/dml/select-sub-query.xml @@ -656,4 +656,50 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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..fb07ca6d0995d 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-special-function.xml b/test/it/parser/src/main/resources/sql/supported/dml/select-special-function.xml index 33706e16d67fa..382afdca0594a 100644 --- a/test/it/parser/src/main/resources/sql/supported/dml/select-special-function.xml +++ b/test/it/parser/src/main/resources/sql/supported/dml/select-special-function.xml @@ -44,4 +44,5 @@ + diff --git a/test/it/parser/src/main/resources/sql/supported/dml/select-sub-query.xml b/test/it/parser/src/main/resources/sql/supported/dml/select-sub-query.xml index 0bc79bdd0b3a3..20c797a6d87df 100644 --- a/test/it/parser/src/main/resources/sql/supported/dml/select-sub-query.xml +++ b/test/it/parser/src/main/resources/sql/supported/dml/select-sub-query.xml @@ -32,4 +32,5 @@ + From 1d511da995d1dbee521d72e9796f0332c32cc52b Mon Sep 17 00:00:00 2001 From: yydeng626 Date: Tue, 2 Jan 2024 15:01:13 +0800 Subject: [PATCH 3/7] remove test parser --- .../internal/SQLServerParserTest.java | 36 ------------------- 1 file changed, 36 deletions(-) delete mode 100644 parser/sql/dialect/sqlserver/src/test/java/org/apache/shardingsphere/test/it/sql/parser/it/sqlserver/internal/SQLServerParserTest.java diff --git a/parser/sql/dialect/sqlserver/src/test/java/org/apache/shardingsphere/test/it/sql/parser/it/sqlserver/internal/SQLServerParserTest.java b/parser/sql/dialect/sqlserver/src/test/java/org/apache/shardingsphere/test/it/sql/parser/it/sqlserver/internal/SQLServerParserTest.java deleted file mode 100644 index b49b27128c3c4..0000000000000 --- a/parser/sql/dialect/sqlserver/src/test/java/org/apache/shardingsphere/test/it/sql/parser/it/sqlserver/internal/SQLServerParserTest.java +++ /dev/null @@ -1,36 +0,0 @@ -package org.apache.shardingsphere.test.it.sql.parser.it.sqlserver.internal; - -import org.apache.shardingsphere.infra.database.core.type.DatabaseType; -import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader; -import org.apache.shardingsphere.infra.util.json.JsonUtils; -import org.apache.shardingsphere.sql.parser.api.SQLStatementVisitorEngine; -import org.apache.shardingsphere.sql.parser.core.ParseASTNode; -import org.apache.shardingsphere.sql.parser.core.database.parser.SQLParserExecutor; -import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement; -import org.junit.jupiter.api.Test; - -/** - * Example generator entrance. - */ -public class SQLServerParserTest { - - - /** - * Main entrance. - * - */ - @Test - public void testExecuteSQL() { - String sql = "INSERT INTO iris_rx_data (\"Sepal.Length\", \"Sepal.Width\", \"Petal.Length\", \"Petal.Width\" , \"Species\")\n" + - "EXECUTE sp_execute_external_script\n" + - " @language = N'R'\n" + - " , @script = N'iris_data <- iris'"; - DatabaseType databaseType = TypedSPILoader.getService(DatabaseType.class, "SQLServer"); - SQLParserExecutor sqlParserExecutor = new SQLParserExecutor(databaseType); - ParseASTNode parse = sqlParserExecutor.parse(sql); - - SQLStatement visit = new SQLStatementVisitorEngine(databaseType, true).visit(parse); - - System.out.println(JsonUtils.toJsonString(visit)); - } -} From bb1c172fe29f31a0b47b049f9bbae4dc2345ce50 Mon Sep 17 00:00:00 2001 From: yydeng626 Date: Tue, 2 Jan 2024 17:52:09 +0800 Subject: [PATCH 4/7] fix test error --- .../antlr4/imports/sqlserver/DMLStatement.g4 | 14 +++---- .../statement/SQLServerStatementVisitor.java | 40 +++++++++++++++++++ .../src/main/resources/case/dml/insert.xml | 1 - 3 files changed, 45 insertions(+), 10 deletions(-) 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 3718bb460aaee..21d5637f544d5 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 @@ -20,7 +20,7 @@ grammar DMLStatement; import BaseRule; insert - : withClause? INSERT top? INTO? tableName (AS? alias)? (insertDefaultValue | insertValuesClause | insertSelectClause | insertExecuteClause) + : withClause? INSERT top? INTO? tableName (AS? alias)? (insertDefaultValue | insertValuesClause | insertSelectClause | insertExecClause) ; insertDefaultValue @@ -35,16 +35,12 @@ insertSelectClause : columnNames? outputClause? select ; -insertExecuteClause - : columnNames? outputClause? (EXEC | EXECUTE) procedureName procedureParameters +insertExecClause + : columnNames? exec ; -procedureParameters - : ( procedureParameter (COMMA_ procedureParameter)* )? - ; - -procedureParameter - : identifier EQ_ literals +exec + : (EXEC | EXECUTE) procedureName (expr (COMMA_ expr)*)? ; update 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..cc53861a31b00 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 @@ -108,6 +108,9 @@ import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.ViewNameContext; import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.WhereClauseContext; import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.WithClauseContext; +import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.InsertExecClauseContext; +import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.ExecContext; +import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.ProcedureNameContext; import org.apache.shardingsphere.sql.parser.sql.common.enums.AggregationType; import org.apache.shardingsphere.sql.parser.sql.common.enums.JoinType; import org.apache.shardingsphere.sql.parser.sql.common.enums.OrderDirection; @@ -116,6 +119,7 @@ import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.constraint.ConstraintSegment; import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.index.IndexNameSegment; import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.index.IndexSegment; +import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.routine.FunctionNameSegment; import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.assignment.ColumnAssignmentSegment; import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.assignment.InsertValuesSegment; import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.assignment.SetAssignmentSegment; @@ -182,6 +186,7 @@ import org.apache.shardingsphere.sql.parser.sql.common.value.literal.impl.OtherLiteralValue; import org.apache.shardingsphere.sql.parser.sql.common.value.literal.impl.StringLiteralValue; import org.apache.shardingsphere.sql.parser.sql.common.value.parametermarker.ParameterMarkerValue; +import org.apache.shardingsphere.sql.parser.sql.dialect.segment.sqlserver.exec.ExecSegment; import org.apache.shardingsphere.sql.parser.sql.dialect.statement.sqlserver.ddl.SQLServerCreateTableStatement; import org.apache.shardingsphere.sql.parser.sql.dialect.statement.sqlserver.dml.SQLServerDeleteStatement; import org.apache.shardingsphere.sql.parser.sql.dialect.statement.sqlserver.dml.SQLServerInsertStatement; @@ -918,6 +923,8 @@ public ASTNode visitInsert(final InsertContext ctx) { result = (SQLServerInsertStatement) visit(ctx.insertDefaultValue()); } else if (null != ctx.insertValuesClause()) { result = (SQLServerInsertStatement) visit(ctx.insertValuesClause()); + } else if (null != ctx.insertExecClause()) { + result = (SQLServerInsertStatement) visit(ctx.insertExecClause()); } else { result = (SQLServerInsertStatement) visit(ctx.insertSelectClause()); } @@ -939,6 +946,39 @@ public ASTNode visitInsertDefaultValue(final InsertDefaultValueContext ctx) { return result; } + @Override + public ASTNode visitInsertExecClause(final InsertExecClauseContext ctx) { + SQLServerInsertStatement result = new SQLServerInsertStatement(); + result.setInsertColumns(createInsertColumns(ctx.columnNames(), ctx.start.getStartIndex())); + result.setExecSegment((ExecSegment) visit(ctx.exec())); + return result; + } + + @Override + public ASTNode visitExec(final ExecContext ctx) { + ExecSegment result = new ExecSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex()); + if (null != ctx.procedureName()) { + result.setProcedureName((FunctionNameSegment) visitProcedureName(ctx.procedureName())); + } + if (null != ctx.expr()) { + Collection items = new LinkedList<>(); + for (ExprContext each : ctx.expr()) { + items.add((ExpressionSegment) visit(each)); + } + result.getExpressionSegments().addAll(items); + } + return result; + } + + @Override + public ASTNode visitProcedureName(final ProcedureNameContext ctx) { + FunctionNameSegment result = new FunctionNameSegment(ctx.name().start.getStartIndex(), ctx.name().stop.getStopIndex(), (IdentifierValue) visit(ctx.name())); + if (null != ctx.owner()) { + result.setOwner(new OwnerSegment(ctx.owner().start.getStartIndex(), ctx.owner().stop.getStopIndex(), (IdentifierValue) visit(ctx.owner()))); + } + return result; + } + @Override public ASTNode visitOutputClause(final OutputClauseContext ctx) { OutputSegment result = new OutputSegment(ctx.start.getStartIndex(), ctx.stop.getStopIndex()); 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 0129cfc0173be..65f1d681db9ac 100644 --- a/test/it/parser/src/main/resources/case/dml/insert.xml +++ b/test/it/parser/src/main/resources/case/dml/insert.xml @@ -3039,7 +3039,6 @@ - From 5ad1e5696e1ac0e3aae7bfed25ce2ab0e6a661c9 Mon Sep 17 00:00:00 2001 From: yydeng626 Date: Wed, 3 Jan 2024 09:28:44 +0800 Subject: [PATCH 5/7] fix code style check --- .../sql/dialect/handler/dml/InsertStatementHandler.java | 4 ++-- .../asserts/segment/insert/InsertExecClauseAssert.java | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/handler/dml/InsertStatementHandler.java b/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/handler/dml/InsertStatementHandler.java index 1c74f68182ce4..5bd2bb60db0fb 100644 --- a/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/handler/dml/InsertStatementHandler.java +++ b/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/handler/dml/InsertStatementHandler.java @@ -296,7 +296,7 @@ public static void setWhereSegment(final InsertStatement insertStatement, final ((OracleInsertStatement) insertStatement).setWhere(whereSegment); } } - + /** * get execute segment. * @param insertStatement insert statement @@ -308,7 +308,7 @@ public static Optional getExecSegment(final InsertStatement insertS } return Optional.empty(); } - + /** * set execute segment. * @param insertStatement insert statement diff --git a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/segment/insert/InsertExecClauseAssert.java b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/segment/insert/InsertExecClauseAssert.java index 8a335daa24b3b..56b855a6649e9 100644 --- a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/segment/insert/InsertExecClauseAssert.java +++ b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/segment/insert/InsertExecClauseAssert.java @@ -37,7 +37,7 @@ **/ @NoArgsConstructor(access = AccessLevel.PRIVATE) public class InsertExecClauseAssert { - + /** * Assert actual execute segment is correct with expected execute clause. * @param assertContext assert context From 76a01d6d8911eb05592f3510df40cdb74c29206b Mon Sep 17 00:00:00 2001 From: yydeng626 Date: Thu, 4 Jan 2024 16:37:15 +0800 Subject: [PATCH 6/7] fix code style --- .../sqlserver/src/main/antlr4/imports/sqlserver/Keyword.g4 | 2 +- .../sql/dialect/handler/dml/InsertStatementHandler.java | 4 ++-- .../sql/dialect/segment/sqlserver/exec/ExecSegment.java | 4 ++-- .../statement/sqlserver/dml/SQLServerCallStatement.java | 2 +- .../asserts/segment/insert/InsertExecClauseAssert.java | 4 ++-- .../src/main/resources/case/dml/select-special-function.xml | 2 -- 6 files changed, 8 insertions(+), 10 deletions(-) diff --git a/parser/sql/dialect/sqlserver/src/main/antlr4/imports/sqlserver/Keyword.g4 b/parser/sql/dialect/sqlserver/src/main/antlr4/imports/sqlserver/Keyword.g4 index e319733baf0b2..1eb79442040ba 100644 --- a/parser/sql/dialect/sqlserver/src/main/antlr4/imports/sqlserver/Keyword.g4 +++ b/parser/sql/dialect/sqlserver/src/main/antlr4/imports/sqlserver/Keyword.g4 @@ -694,4 +694,4 @@ WITHOUT APPLY : A P P L Y - ; \ No newline at end of file + ; diff --git a/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/handler/dml/InsertStatementHandler.java b/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/handler/dml/InsertStatementHandler.java index 5bd2bb60db0fb..74e42876c5164 100644 --- a/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/handler/dml/InsertStatementHandler.java +++ b/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/handler/dml/InsertStatementHandler.java @@ -298,7 +298,7 @@ public static void setWhereSegment(final InsertStatement insertStatement, final } /** - * get execute segment. + * Get execute segment. * @param insertStatement insert statement * @return execute segment */ @@ -310,7 +310,7 @@ public static Optional getExecSegment(final InsertStatement insertS } /** - * set execute segment. + * Set execute segment. * @param insertStatement insert statement * @param execSegment execute segment */ diff --git a/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/segment/sqlserver/exec/ExecSegment.java b/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/segment/sqlserver/exec/ExecSegment.java index 7fabad9cf0461..4c9a1cbcf967f 100644 --- a/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/segment/sqlserver/exec/ExecSegment.java +++ b/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/segment/sqlserver/exec/ExecSegment.java @@ -28,11 +28,11 @@ import java.util.LinkedList; /** - * execute segment. + * Execute segment. */ @RequiredArgsConstructor @Getter -public class ExecSegment implements SQLSegment { +public final class ExecSegment implements SQLSegment { private final int startIndex; diff --git a/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/sqlserver/dml/SQLServerCallStatement.java b/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/sqlserver/dml/SQLServerCallStatement.java index 1550d51dbc182..670188826648d 100644 --- a/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/sqlserver/dml/SQLServerCallStatement.java +++ b/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/sqlserver/dml/SQLServerCallStatement.java @@ -27,7 +27,7 @@ import java.util.List; /** - * MySQL call statement. + * SQLServer call statement. */ @AllArgsConstructor @NoArgsConstructor diff --git a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/segment/insert/InsertExecClauseAssert.java b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/segment/insert/InsertExecClauseAssert.java index 56b855a6649e9..940bacbe85fb2 100644 --- a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/segment/insert/InsertExecClauseAssert.java +++ b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/segment/insert/InsertExecClauseAssert.java @@ -33,13 +33,14 @@ import static org.junit.jupiter.api.Assertions.assertTrue; /** - * insert execute clause assert. + * Insert execute clause assert. **/ @NoArgsConstructor(access = AccessLevel.PRIVATE) public class InsertExecClauseAssert { /** * Assert actual execute segment is correct with expected execute clause. + * * @param assertContext assert context * @param actual actual execute segment * @param expected expected execute clause @@ -52,7 +53,6 @@ public static void assertIs(final SQLCaseAssertContext assertContext, final Exec assertTrue(actual.getProcedureName().getOwner().isPresent(), assertContext.getText("Actual owner should exist.")); OwnerAssert.assertIs(assertContext, actual.getProcedureName().getOwner().get(), expected.getOwner()); } - if (null == expected.getParameters()) { assertThat(assertContext.getText("exec procedure parameters assertion error: "), actual.getExpressionSegments().size(), CoreMatchers.is(expected.getParameters().size())); } else { diff --git a/test/it/parser/src/main/resources/case/dml/select-special-function.xml b/test/it/parser/src/main/resources/case/dml/select-special-function.xml index dab47570d3d26..9704599ec4bfb 100644 --- a/test/it/parser/src/main/resources/case/dml/select-special-function.xml +++ b/test/it/parser/src/main/resources/case/dml/select-special-function.xml @@ -592,7 +592,6 @@ - - From f87c60a589345af823009ee214102b1e66b85a5a Mon Sep 17 00:00:00 2001 From: yydeng626 Date: Fri, 5 Jan 2024 09:15:24 +0800 Subject: [PATCH 7/7] fix code style --- .../parser/sql/dialect/handler/dml/InsertStatementHandler.java | 2 ++ .../parser/sql/dialect/segment/sqlserver/exec/ExecSegment.java | 2 +- .../cases/parser/jaxb/segment/impl/exec/ExpectedExecClause.java | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/handler/dml/InsertStatementHandler.java b/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/handler/dml/InsertStatementHandler.java index 74e42876c5164..2a63293f29cdc 100644 --- a/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/handler/dml/InsertStatementHandler.java +++ b/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/handler/dml/InsertStatementHandler.java @@ -299,6 +299,7 @@ public static void setWhereSegment(final InsertStatement insertStatement, final /** * Get execute segment. + * * @param insertStatement insert statement * @return execute segment */ @@ -311,6 +312,7 @@ public static Optional getExecSegment(final InsertStatement insertS /** * Set execute segment. + * * @param insertStatement insert statement * @param execSegment execute segment */ diff --git a/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/segment/sqlserver/exec/ExecSegment.java b/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/segment/sqlserver/exec/ExecSegment.java index 4c9a1cbcf967f..ba65da6abdc91 100644 --- a/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/segment/sqlserver/exec/ExecSegment.java +++ b/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/segment/sqlserver/exec/ExecSegment.java @@ -41,5 +41,5 @@ public final class ExecSegment implements SQLSegment { @Setter private FunctionNameSegment procedureName; - private Collection expressionSegments = new LinkedList<>(); + private final Collection expressionSegments = new LinkedList<>(); } diff --git a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/segment/impl/exec/ExpectedExecClause.java b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/segment/impl/exec/ExpectedExecClause.java index edbd3abb358f1..656103482ef50 100644 --- a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/segment/impl/exec/ExpectedExecClause.java +++ b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/segment/impl/exec/ExpectedExecClause.java @@ -29,7 +29,7 @@ import java.util.List; /** - * Expected procedure name. + * Expected execute clause. */ @Getter @Setter