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 b9cc46d59e343..1934827c85b83 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 | PRECISION | VIEWS + | MEMBER | SEARCH | TEXT | SECOND | PRECISION | VIEWS | PROVIDER ; 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 1f9fa961ff7af..aee7775a9c5ae 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 | insertExecClause) ; insertDefaultValue @@ -35,6 +35,14 @@ insertSelectClause : columnNames? outputClause? select ; +insertExecClause + : columnNames? exec + ; + +exec + : (EXEC | EXECUTE) procedureName (expr (COMMA_ expr)*)? + ; + update : withClause? UPDATE top? tableReferences setAssignmentsClause whereClause? (OPTION queryHint)? ; 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..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 @@ -692,3 +692,6 @@ WITHOUT : W I T H O U T ; +APPLY + : A P P L Y + ; 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 1d4579d08ef4f..a4b06d510f338 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 @@ -107,6 +107,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; @@ -115,6 +118,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; @@ -181,6 +185,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; @@ -914,6 +919,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()); } @@ -935,6 +942,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/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/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..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 @@ -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,29 @@ 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..ba65da6abdc91 --- /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 final class ExecSegment implements SQLSegment { + + private final int startIndex; + + private final int stopIndex; + + @Setter + private FunctionNameSegment procedureName; + + private final 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..670188826648d --- /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; + +/** + * SQLServer 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..940bacbe85fb2 --- /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..656103482ef50 --- /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 execute clause. + */ +@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 cf0a00f588b99..14ce407ad7c49 100644 --- a/test/it/parser/src/main/resources/case/dml/insert.xml +++ b/test/it/parser/src/main/resources/case/dml/insert.xml @@ -3026,4 +3026,39 @@ + + + + + + + + + + + + + + + + + = + + + + + + + + + + + = + + + + + + + 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..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 @@ -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/case/dml/select.xml b/test/it/parser/src/main/resources/case/dml/select.xml index f133b8efec01e..25a46d41758b9 100644 --- a/test/it/parser/src/main/resources/case/dml/select.xml +++ b/test/it/parser/src/main/resources/case/dml/select.xml @@ -7682,6 +7682,19 @@ + +