From f1312bf6a464c5380e3c65cfb44866cecd990d97 Mon Sep 17 00:00:00 2001 From: tmyVvit Date: Sun, 27 Aug 2023 21:22:46 +0800 Subject: [PATCH 01/11] opengauss add create_index with global partition --- .../src/main/antlr4/imports/opengauss/BaseRule.g4 | 4 ++++ .../main/antlr4/imports/opengauss/DDLStatement.g4 | 15 ++++++++++++++- .../src/main/resources/case/ddl/create-index.xml | 10 ++++++++++ .../resources/sql/supported/ddl/create-index.xml | 7 +++++++ 4 files changed, 35 insertions(+), 1 deletion(-) diff --git a/parser/sql/dialect/opengauss/src/main/antlr4/imports/opengauss/BaseRule.g4 b/parser/sql/dialect/opengauss/src/main/antlr4/imports/opengauss/BaseRule.g4 index 603b694b7b0c0..c9650a3c752a2 100644 --- a/parser/sql/dialect/opengauss/src/main/antlr4/imports/opengauss/BaseRule.g4 +++ b/parser/sql/dialect/opengauss/src/main/antlr4/imports/opengauss/BaseRule.g4 @@ -513,6 +513,10 @@ collationName ; indexName + : (schemaName DOT_)? identifier + ; + +indexPartitionName : identifier ; diff --git a/parser/sql/dialect/opengauss/src/main/antlr4/imports/opengauss/DDLStatement.g4 b/parser/sql/dialect/opengauss/src/main/antlr4/imports/opengauss/DDLStatement.g4 index 8aef4046a7061..770d7f87b8b84 100644 --- a/parser/sql/dialect/opengauss/src/main/antlr4/imports/opengauss/DDLStatement.g4 +++ b/parser/sql/dialect/opengauss/src/main/antlr4/imports/opengauss/DDLStatement.g4 @@ -89,7 +89,7 @@ accessMethod createIndex : CREATE createIndexSpecification INDEX concurrentlyClause (ifNotExists? indexName)? ON onlyClause tableName - accessMethodClause? LP_ indexParams RP_ include? (WITH reloptions)? tableSpace? whereClause? + accessMethodClause? LP_ indexParams RP_ include? createIndexPartitionClause? (WITH reloptions)? tableSpace? whereClause? ; include @@ -316,6 +316,19 @@ createIndexSpecification : UNIQUE? ; +createIndexPartitionClause + : LOCAL (LP_ indexPartitionElemList RP_)? + | GLOBAL + ; + +indexPartitionElemList + : indexPartitionElem (COMMA_ indexPartitionElem)* + ; + +indexPartitionElem + : PARTITION indexPartitionName tableSpace? + ; + concurrentlyClause : CONCURRENTLY? ; diff --git a/test/it/parser/src/main/resources/case/ddl/create-index.xml b/test/it/parser/src/main/resources/case/ddl/create-index.xml index 76622e923cd06..6673cf6594c5e 100644 --- a/test/it/parser/src/main/resources/case/ddl/create-index.xml +++ b/test/it/parser/src/main/resources/case/ddl/create-index.xml @@ -253,4 +253,14 @@ + + + + + + +
+ + +
diff --git a/test/it/parser/src/main/resources/sql/supported/ddl/create-index.xml b/test/it/parser/src/main/resources/sql/supported/ddl/create-index.xml index 15790c5da1360..6a91811e79f5e 100644 --- a/test/it/parser/src/main/resources/sql/supported/ddl/create-index.xml +++ b/test/it/parser/src/main/resources/sql/supported/ddl/create-index.xml @@ -52,4 +52,11 @@ + + + + + + + From 7ebfb6fb725131d93d764b014168923ff7114533 Mon Sep 17 00:00:00 2001 From: tmyVvit Date: Sun, 27 Aug 2023 22:34:42 +0800 Subject: [PATCH 02/11] opengauss add create_index add owner for index name --- .../src/main/antlr4/imports/opengauss/BaseRule.g4 | 2 +- .../visitor/statement/OpenGaussStatementVisitor.java | 9 +++++++-- .../it/sql/parser/internal/InternalSQLParserIT.java | 2 +- .../statement/ddl/impl/CreateIndexStatementAssert.java | 3 +++ .../src/main/resources/case/ddl/create-index.xml | 10 ++++++++++ .../main/resources/sql/supported/ddl/create-index.xml | 1 + 6 files changed, 23 insertions(+), 4 deletions(-) diff --git a/parser/sql/dialect/opengauss/src/main/antlr4/imports/opengauss/BaseRule.g4 b/parser/sql/dialect/opengauss/src/main/antlr4/imports/opengauss/BaseRule.g4 index c9650a3c752a2..44ca6b4050ff4 100644 --- a/parser/sql/dialect/opengauss/src/main/antlr4/imports/opengauss/BaseRule.g4 +++ b/parser/sql/dialect/opengauss/src/main/antlr4/imports/opengauss/BaseRule.g4 @@ -513,7 +513,7 @@ collationName ; indexName - : (schemaName DOT_)? identifier + : (owner DOT_)? name ; indexPartitionName diff --git a/parser/sql/dialect/opengauss/src/main/java/org/apache/shardingsphere/sql/parser/opengauss/visitor/statement/OpenGaussStatementVisitor.java b/parser/sql/dialect/opengauss/src/main/java/org/apache/shardingsphere/sql/parser/opengauss/visitor/statement/OpenGaussStatementVisitor.java index f997564004f31..3e2fe15ee6b1e 100644 --- a/parser/sql/dialect/opengauss/src/main/java/org/apache/shardingsphere/sql/parser/opengauss/visitor/statement/OpenGaussStatementVisitor.java +++ b/parser/sql/dialect/opengauss/src/main/java/org/apache/shardingsphere/sql/parser/opengauss/visitor/statement/OpenGaussStatementVisitor.java @@ -260,8 +260,13 @@ public final ASTNode visitColumnName(final ColumnNameContext ctx) { @Override public final ASTNode visitIndexName(final IndexNameContext ctx) { - IndexNameSegment indexName = new IndexNameSegment(ctx.start.getStartIndex(), ctx.stop.getStopIndex(), (IdentifierValue) visit(ctx.identifier())); - return new IndexSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), indexName); + IndexNameSegment indexName = new IndexNameSegment(ctx.name().getStart().getStartIndex(), ctx.name().getStop().getStopIndex(), (IdentifierValue) visit(ctx.name())); + IndexSegment result = new IndexSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), indexName); + OwnerContext owner = ctx.owner(); + if (null != owner) { + result.setOwner(new OwnerSegment(owner.getStart().getStartIndex(), owner.getStop().getStopIndex(), (IdentifierValue) visit(owner.identifier()))); + } + return result; } @Override diff --git a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/InternalSQLParserIT.java b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/InternalSQLParserIT.java index 57d90ee3672a2..c8c95d9274877 100644 --- a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/InternalSQLParserIT.java +++ b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/InternalSQLParserIT.java @@ -80,7 +80,7 @@ private Collection getTestParameters(final String... databaseTypes) { result.add(Arguments.arguments(each.getSqlCaseId(), each.getSqlCaseType(), each.getDatabaseType())); } } - return result; + return result.stream().filter(r -> "create_index_with_owner01".equals(r.get()[0])).collect(Collectors.toList()); } private boolean isPlaceholderWithoutParameter(final InternalSQLParserTestParameter testParam) { diff --git a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/statement/ddl/impl/CreateIndexStatementAssert.java b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/statement/ddl/impl/CreateIndexStatementAssert.java index 3134aff4137dc..1b1c4ca885b18 100644 --- a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/statement/ddl/impl/CreateIndexStatementAssert.java +++ b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/statement/ddl/impl/CreateIndexStatementAssert.java @@ -21,6 +21,7 @@ import lombok.NoArgsConstructor; import org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.CreateIndexStatement; import org.apache.shardingsphere.sql.parser.sql.dialect.handler.ddl.CreateIndexStatementHandler; +import org.apache.shardingsphere.sql.parser.sql.dialect.statement.opengauss.ddl.OpenGaussCreateIndexStatement; import org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.ddl.OracleCreateIndexStatement; import org.apache.shardingsphere.test.it.sql.parser.internal.asserts.SQLCaseAssertContext; import org.apache.shardingsphere.test.it.sql.parser.internal.asserts.segment.column.ColumnAssert; @@ -69,6 +70,8 @@ private static void assertIndex(final SQLCaseAssertContext assertContext, final // TODO should assert index for all databases(mysql and sqlserver do not parse index right now) if (actual instanceof OracleCreateIndexStatement) { IndexAssert.assertIs(assertContext, actual.getIndex(), expected.getIndex()); + } else if (actual instanceof OpenGaussCreateIndexStatement) { + IndexAssert.assertIs(assertContext, actual.getIndex(), expected.getIndex()); } } diff --git a/test/it/parser/src/main/resources/case/ddl/create-index.xml b/test/it/parser/src/main/resources/case/ddl/create-index.xml index 6673cf6594c5e..09ce3d3accdf2 100644 --- a/test/it/parser/src/main/resources/case/ddl/create-index.xml +++ b/test/it/parser/src/main/resources/case/ddl/create-index.xml @@ -263,4 +263,14 @@ + + + + +
+ + + + +
diff --git a/test/it/parser/src/main/resources/sql/supported/ddl/create-index.xml b/test/it/parser/src/main/resources/sql/supported/ddl/create-index.xml index 6a91811e79f5e..ee95fc832b53e 100644 --- a/test/it/parser/src/main/resources/sql/supported/ddl/create-index.xml +++ b/test/it/parser/src/main/resources/sql/supported/ddl/create-index.xml @@ -53,6 +53,7 @@ + From 22f64f8a765110f8b8002aac525dccac32cf3a5e Mon Sep 17 00:00:00 2001 From: tmyVvit Date: Mon, 28 Aug 2023 01:26:58 +0800 Subject: [PATCH 03/11] opengauss add create_index with index partitions and tablespace --- .../statement/OpenGaussStatementVisitor.java | 42 +++++++++++ .../type/OpenGaussDDLStatementVisitor.java | 8 +++ .../ddl/CreateIndexStatementHandler.java | 29 ++++++++ .../ddl/OpenGaussCreateIndexStatement.java | 23 ++++++ .../segment/IndexPartitionSegment.java | 44 ++++++++++++ .../segment/IndexPartitionTypeEnum.java | 22 ++++++ .../segment/IndexPartitionsSegment.java | 37 ++++++++++ .../parser/internal/InternalSQLParserIT.java | 2 +- .../segment/index/IndexPartitionsAssert.java | 70 +++++++++++++++++++ .../segment/tablespace/TablespaceAssert.java | 45 ++++++++++++ .../ddl/impl/CreateIndexStatementAssert.java | 33 ++++++++- .../impl/index/ExpectedIndexPartition.java | 32 +++++++++ .../impl/index/ExpectedIndexPartitions.java | 38 ++++++++++ .../ddl/CreateIndexStatementTestCase.java | 8 +++ .../main/resources/case/ddl/create-index.xml | 19 +++++ .../sql/supported/ddl/create-index.xml | 13 ++-- 16 files changed, 457 insertions(+), 8 deletions(-) create mode 100644 parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/opengauss/segment/IndexPartitionSegment.java create mode 100644 parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/opengauss/segment/IndexPartitionTypeEnum.java create mode 100644 parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/opengauss/segment/IndexPartitionsSegment.java create mode 100644 test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/segment/index/IndexPartitionsAssert.java create mode 100644 test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/segment/tablespace/TablespaceAssert.java create mode 100644 test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/segment/impl/index/ExpectedIndexPartition.java create mode 100644 test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/segment/impl/index/ExpectedIndexPartitions.java diff --git a/parser/sql/dialect/opengauss/src/main/java/org/apache/shardingsphere/sql/parser/opengauss/visitor/statement/OpenGaussStatementVisitor.java b/parser/sql/dialect/opengauss/src/main/java/org/apache/shardingsphere/sql/parser/opengauss/visitor/statement/OpenGaussStatementVisitor.java index 3e2fe15ee6b1e..7ffe20a705f25 100644 --- a/parser/sql/dialect/opengauss/src/main/java/org/apache/shardingsphere/sql/parser/opengauss/visitor/statement/OpenGaussStatementVisitor.java +++ b/parser/sql/dialect/opengauss/src/main/java/org/apache/shardingsphere/sql/parser/opengauss/visitor/statement/OpenGaussStatementVisitor.java @@ -26,6 +26,7 @@ import org.apache.shardingsphere.infra.database.core.metadata.database.enums.NullsOrderType; import org.apache.shardingsphere.sql.parser.api.ASTNode; import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementBaseVisitor; +import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser; import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.AExprContext; import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.AexprConstContext; import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.AliasClauseContext; @@ -119,6 +120,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.tablespace.TablespaceSegment; import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.ReturningSegment; import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.assignment.AssignmentSegment; import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.assignment.ColumnAssignmentSegment; @@ -200,6 +202,9 @@ import java.util.LinkedList; import java.util.List; import java.util.Optional; +import org.apache.shardingsphere.sql.parser.sql.dialect.statement.opengauss.segment.IndexPartitionSegment; +import org.apache.shardingsphere.sql.parser.sql.dialect.statement.opengauss.segment.IndexPartitionTypeEnum; +import org.apache.shardingsphere.sql.parser.sql.dialect.statement.opengauss.segment.IndexPartitionsSegment; /** * Statement visitor for openGauss. @@ -1410,4 +1415,41 @@ public ASTNode visitAttrs(final AttrsContext ctx) { public ASTNode visitSignedIconst(final SignedIconstContext ctx) { return new NumberLiteralValue(ctx.getText()); } + + @SuppressWarnings("unchecked") + @Override + public ASTNode visitCreateIndexPartitionClause(final OpenGaussStatementParser.CreateIndexPartitionClauseContext ctx) { + IndexPartitionTypeEnum indexPartitionType = null; + if (ctx.LOCAL() != null || ctx.GLOBAL() != null) { + indexPartitionType = ctx.LOCAL() != null ? IndexPartitionTypeEnum.LOCAL : IndexPartitionTypeEnum.GLOBAL; + } + IndexPartitionsSegment result = new IndexPartitionsSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), indexPartitionType); + if (null != ctx.indexPartitionElemList()) { + result.getIndexPartitionSegment().addAll(((CollectionValue) visit(ctx.indexPartitionElemList())).getValue()); + } + return result; + } + + @Override + public ASTNode visitIndexPartitionElemList(final OpenGaussStatementParser.IndexPartitionElemListContext ctx) { + CollectionValue result = new CollectionValue<>(); + for (OpenGaussStatementParser.IndexPartitionElemContext each : ctx.indexPartitionElem()) { + result.getValue().add((IndexPartitionSegment) visit(each)); + } + return result; + } + + @Override + public ASTNode visitIndexPartitionElem(final OpenGaussStatementParser.IndexPartitionElemContext ctx) { + IndexPartitionSegment result = new IndexPartitionSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), (IdentifierValue) visit(ctx.indexPartitionName())); + if (null != ctx.tableSpace()) { + result.setTablespace((TablespaceSegment) visit(ctx.tableSpace())); + } + return result; + } + + @Override + public ASTNode visitTableSpace(final OpenGaussStatementParser.TableSpaceContext ctx) { + return new TablespaceSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), (IdentifierValue) visit(ctx.name())); + } } diff --git a/parser/sql/dialect/opengauss/src/main/java/org/apache/shardingsphere/sql/parser/opengauss/visitor/statement/type/OpenGaussDDLStatementVisitor.java b/parser/sql/dialect/opengauss/src/main/java/org/apache/shardingsphere/sql/parser/opengauss/visitor/statement/type/OpenGaussDDLStatementVisitor.java index ff57857de21c0..7baf6a38f20bc 100644 --- a/parser/sql/dialect/opengauss/src/main/java/org/apache/shardingsphere/sql/parser/opengauss/visitor/statement/type/OpenGaussDDLStatementVisitor.java +++ b/parser/sql/dialect/opengauss/src/main/java/org/apache/shardingsphere/sql/parser/opengauss/visitor/statement/type/OpenGaussDDLStatementVisitor.java @@ -157,6 +157,7 @@ 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.table.RenameTableDefinitionSegment; +import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.tablespace.TablespaceSegment; import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.column.ColumnSegment; import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.ExpressionSegment; import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.FunctionSegment; @@ -253,6 +254,7 @@ import java.util.LinkedList; import java.util.Optional; import java.util.stream.Collectors; +import org.apache.shardingsphere.sql.parser.sql.dialect.statement.opengauss.segment.IndexPartitionsSegment; /** * DDL statement visitor for openGauss. @@ -524,6 +526,12 @@ public ASTNode visitCreateIndex(final CreateIndexContext ctx) { } else { result.setIndex((IndexSegment) visit(ctx.indexName())); } + if (null != ctx.createIndexPartitionClause()) { + result.setIndexPartitionsSegment((IndexPartitionsSegment) visit(ctx.createIndexPartitionClause())); + } + if (null != ctx.tableSpace()) { + result.setTablespace((TablespaceSegment) visit(ctx.tableSpace())); + } return result; } diff --git a/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/handler/ddl/CreateIndexStatementHandler.java b/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/handler/ddl/CreateIndexStatementHandler.java index 16c302be49bdd..6217e29141e2d 100644 --- a/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/handler/ddl/CreateIndexStatementHandler.java +++ b/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/handler/ddl/CreateIndexStatementHandler.java @@ -21,11 +21,13 @@ import lombok.NoArgsConstructor; import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.table.AlgorithmTypeSegment; import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.table.LockTableSegment; +import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.tablespace.TablespaceSegment; import org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.CreateIndexStatement; import org.apache.shardingsphere.sql.parser.sql.dialect.handler.SQLStatementHandler; import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.ddl.MySQLCreateIndexStatement; import org.apache.shardingsphere.sql.parser.sql.dialect.statement.opengauss.OpenGaussStatement; import org.apache.shardingsphere.sql.parser.sql.dialect.statement.opengauss.ddl.OpenGaussCreateIndexStatement; +import org.apache.shardingsphere.sql.parser.sql.dialect.statement.opengauss.segment.IndexPartitionsSegment; import org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.PostgreSQLStatement; import org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl.PostgreSQLCreateIndexStatement; @@ -94,4 +96,31 @@ public static Optional getLockTableSegment(final CreateIndexSt } return Optional.empty(); } + + /** + * Get index partitions segment. + * + * @param createIndexStatement create index statement + * @return index partitions segment + */ + public static Optional getIndexPartitionsSegment(final CreateIndexStatement createIndexStatement) { + if (createIndexStatement instanceof OpenGaussCreateIndexStatement) { + return ((OpenGaussCreateIndexStatement) createIndexStatement).getIndexPartitionsSegment(); + } + return Optional.empty(); + } + + /** + * Get tablespace segment. + * + * @param createIndexStatement create index statement + * @return tablespace segment + */ + public static Optional getTablespaceSegment(final CreateIndexStatement createIndexStatement) { + if (createIndexStatement instanceof OpenGaussCreateIndexStatement) { + return ((OpenGaussCreateIndexStatement) createIndexStatement).getTablespace(); + } + return Optional.empty(); + } + } diff --git a/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/opengauss/ddl/OpenGaussCreateIndexStatement.java b/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/opengauss/ddl/OpenGaussCreateIndexStatement.java index 5b6c526145c73..06b87f793cb6c 100644 --- a/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/opengauss/ddl/OpenGaussCreateIndexStatement.java +++ b/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/opengauss/ddl/OpenGaussCreateIndexStatement.java @@ -20,10 +20,12 @@ import lombok.Getter; import lombok.RequiredArgsConstructor; import lombok.Setter; +import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.tablespace.TablespaceSegment; import org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.CreateIndexStatement; import org.apache.shardingsphere.sql.parser.sql.dialect.statement.opengauss.OpenGaussStatement; import java.util.Optional; +import org.apache.shardingsphere.sql.parser.sql.dialect.statement.opengauss.segment.IndexPartitionsSegment; /** * OpenGauss create index statement. @@ -37,6 +39,10 @@ public final class OpenGaussCreateIndexStatement extends CreateIndexStatement im private Integer generatedIndexStartIndex; + private IndexPartitionsSegment indexPartitionsSegment; + + private TablespaceSegment tablespace; + /** * Get generated index start index. * @@ -45,4 +51,21 @@ public final class OpenGaussCreateIndexStatement extends CreateIndexStatement im public Optional getGeneratedIndexStartIndex() { return Optional.ofNullable(generatedIndexStartIndex); } + + /** + * Get index partitions segment. + * + * @return index partitions segment + */ + public Optional getIndexPartitionsSegment() { + return Optional.ofNullable(indexPartitionsSegment); + } + + /** + * Get tablespace. + * @return tablespace + */ + public Optional getTablespace() { + return Optional.ofNullable(tablespace); + } } diff --git a/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/opengauss/segment/IndexPartitionSegment.java b/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/opengauss/segment/IndexPartitionSegment.java new file mode 100644 index 0000000000000..d6430532a69af --- /dev/null +++ b/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/opengauss/segment/IndexPartitionSegment.java @@ -0,0 +1,44 @@ +/* + * 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.opengauss.segment; + +import java.util.Optional; +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.tablespace.TablespaceSegment; +import org.apache.shardingsphere.sql.parser.sql.common.value.identifier.IdentifierValue; + +@RequiredArgsConstructor +@Getter +@Setter +public class IndexPartitionSegment implements SQLSegment { + + private final int startIndex; + + private final int stopIndex; + + private final IdentifierValue indexPartitionName; + + private TablespaceSegment tablespace; + + public Optional getTablespace() { + return Optional.ofNullable(tablespace); + } +} diff --git a/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/opengauss/segment/IndexPartitionTypeEnum.java b/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/opengauss/segment/IndexPartitionTypeEnum.java new file mode 100644 index 0000000000000..ba145887394d3 --- /dev/null +++ b/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/opengauss/segment/IndexPartitionTypeEnum.java @@ -0,0 +1,22 @@ +/* + * 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.opengauss.segment; + +public enum IndexPartitionTypeEnum { + GLOBAL, LOCAL +} diff --git a/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/opengauss/segment/IndexPartitionsSegment.java b/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/opengauss/segment/IndexPartitionsSegment.java new file mode 100644 index 0000000000000..7c7d019d749f7 --- /dev/null +++ b/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/opengauss/segment/IndexPartitionsSegment.java @@ -0,0 +1,37 @@ +/* + * 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.opengauss.segment; + +import java.util.Collection; +import java.util.LinkedList; +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.AlterDefinitionSegment; + +@RequiredArgsConstructor +@Getter +public class IndexPartitionsSegment implements AlterDefinitionSegment { + + private final int startIndex; + + private final int stopIndex; + + private final IndexPartitionTypeEnum partitionType; + + private final Collection indexPartitionSegment = new LinkedList<>(); +} diff --git a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/InternalSQLParserIT.java b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/InternalSQLParserIT.java index c8c95d9274877..57d90ee3672a2 100644 --- a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/InternalSQLParserIT.java +++ b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/InternalSQLParserIT.java @@ -80,7 +80,7 @@ private Collection getTestParameters(final String... databaseTypes) { result.add(Arguments.arguments(each.getSqlCaseId(), each.getSqlCaseType(), each.getDatabaseType())); } } - return result.stream().filter(r -> "create_index_with_owner01".equals(r.get()[0])).collect(Collectors.toList()); + return result; } private boolean isPlaceholderWithoutParameter(final InternalSQLParserTestParameter testParam) { diff --git a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/segment/index/IndexPartitionsAssert.java b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/segment/index/IndexPartitionsAssert.java new file mode 100644 index 0000000000000..3ed8eb773ace7 --- /dev/null +++ b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/segment/index/IndexPartitionsAssert.java @@ -0,0 +1,70 @@ +/* + * 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.index; + +import lombok.AccessLevel; +import lombok.NoArgsConstructor; +import org.apache.shardingsphere.sql.parser.sql.dialect.statement.opengauss.segment.IndexPartitionSegment; +import org.apache.shardingsphere.sql.parser.sql.dialect.statement.opengauss.segment.IndexPartitionsSegment; +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.identifier.IdentifierValueAssert; +import org.apache.shardingsphere.test.it.sql.parser.internal.asserts.segment.tablespace.TablespaceAssert; +import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.segment.impl.index.ExpectedIndexPartition; +import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.segment.impl.index.ExpectedIndexPartitions; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class IndexPartitionsAssert { + + /** + * Assert actual index partitions segment is correct with expected index. + * + * @param assertContext assert context + * @param actual actual index segment + * @param expected expected index + */ + public static void assertIs(final SQLCaseAssertContext assertContext, final IndexPartitionsSegment actual, final ExpectedIndexPartitions expected) { + assertNotNull(expected, assertContext.getText("Index partitions should exist.")); + assertThat(assertContext.getText("Index partitions type assertion error: "), actual.getPartitionType().name(), is(expected.getType())); + assertThat(assertContext.getText("Index partitions size assertion error: "), actual.getIndexPartitionSegment().size(), is(expected.getPartitions().size())); + int i = 0; + for (IndexPartitionSegment actualIndexPartitionSegment : actual.getIndexPartitionSegment()) { + assertIs(assertContext, actualIndexPartitionSegment, expected.getPartitions().get(i++)); + } + SQLSegmentAssert.assertIs(assertContext, actual, expected); + } + + private static void assertIs(final SQLCaseAssertContext assertContext, final IndexPartitionSegment actual, final ExpectedIndexPartition expected) { + assertNotNull(expected, assertContext.getText("Index partition should exist.")); + assertNotNull(actual, assertContext.getText("Index partition should exist.")); + IdentifierValueAssert.assertIs(assertContext, actual.getIndexPartitionName(), expected, "Index Partition"); + if (null == expected.getTablespace()) { + assertFalse(actual.getTablespace().isPresent(), assertContext.getText("Actual tablespace should not exist.")); + } else { + assertTrue(actual.getTablespace().isPresent(), assertContext.getText("Actual tablespace should exist.")); + TablespaceAssert.assertIs(assertContext, actual.getTablespace().get(), expected.getTablespace()); + } + SQLSegmentAssert.assertIs(assertContext, actual, expected); + } +} diff --git a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/segment/tablespace/TablespaceAssert.java b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/segment/tablespace/TablespaceAssert.java new file mode 100644 index 0000000000000..1ec98eb7dfc15 --- /dev/null +++ b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/segment/tablespace/TablespaceAssert.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.test.it.sql.parser.internal.asserts.segment.tablespace; + +import lombok.AccessLevel; +import lombok.NoArgsConstructor; +import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.tablespace.TablespaceSegment; +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.identifier.IdentifierValueAssert; +import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.segment.impl.tablespace.ExpectedTablespace; + +import static org.junit.jupiter.api.Assertions.assertNotNull; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class TablespaceAssert { + + /** + * Assert actual tablespace segment is correct with expected tablespace. + * + * @param assertContext assert context + * @param actual actual tablespace segment + * @param expected expected tablespace + */ + public static void assertIs(final SQLCaseAssertContext assertContext, final TablespaceSegment actual, final ExpectedTablespace expected) { + assertNotNull(expected, assertContext.getText("Tablespace should exist.")); + IdentifierValueAssert.assertIs(assertContext, actual.getIdentifier(), expected, "Tablespace"); + SQLSegmentAssert.assertIs(assertContext, actual, expected); + } +} diff --git a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/statement/ddl/impl/CreateIndexStatementAssert.java b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/statement/ddl/impl/CreateIndexStatementAssert.java index 1b1c4ca885b18..568e31cc34ab1 100644 --- a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/statement/ddl/impl/CreateIndexStatementAssert.java +++ b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/statement/ddl/impl/CreateIndexStatementAssert.java @@ -17,15 +17,18 @@ package org.apache.shardingsphere.test.it.sql.parser.internal.asserts.statement.ddl.impl; +import java.util.Optional; import lombok.AccessLevel; import lombok.NoArgsConstructor; import org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.CreateIndexStatement; import org.apache.shardingsphere.sql.parser.sql.dialect.handler.ddl.CreateIndexStatementHandler; import org.apache.shardingsphere.sql.parser.sql.dialect.statement.opengauss.ddl.OpenGaussCreateIndexStatement; +import org.apache.shardingsphere.sql.parser.sql.dialect.statement.opengauss.segment.IndexPartitionsSegment; import org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.ddl.OracleCreateIndexStatement; import org.apache.shardingsphere.test.it.sql.parser.internal.asserts.SQLCaseAssertContext; import org.apache.shardingsphere.test.it.sql.parser.internal.asserts.segment.column.ColumnAssert; import org.apache.shardingsphere.test.it.sql.parser.internal.asserts.segment.index.IndexAssert; +import org.apache.shardingsphere.test.it.sql.parser.internal.asserts.segment.index.IndexPartitionsAssert; import org.apache.shardingsphere.test.it.sql.parser.internal.asserts.segment.table.TableAssert; import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.ddl.CreateIndexStatementTestCase; @@ -55,6 +58,8 @@ public static void assertIs(final SQLCaseAssertContext assertContext, final Crea assertColumns(assertContext, actual, expected); assertLockTable(assertContext, actual, expected); assertAlgorithm(assertContext, actual, expected); + assertTablespace(assertContext, actual, expected); + assertIndexPartitions(assertContext, actual, expected); } private static void assertTable(final SQLCaseAssertContext assertContext, final CreateIndexStatement actual, final CreateIndexStatementTestCase expected) { @@ -71,7 +76,9 @@ private static void assertIndex(final SQLCaseAssertContext assertContext, final if (actual instanceof OracleCreateIndexStatement) { IndexAssert.assertIs(assertContext, actual.getIndex(), expected.getIndex()); } else if (actual instanceof OpenGaussCreateIndexStatement) { - IndexAssert.assertIs(assertContext, actual.getIndex(), expected.getIndex()); + if (null != expected.getIndex()) { + IndexAssert.assertIs(assertContext, actual.getIndex(), expected.getIndex()); + } } } @@ -102,4 +109,28 @@ private static void assertAlgorithm(final SQLCaseAssertContext assertContext, fi CreateIndexStatementHandler.getAlgorithmTypeSegment(actual).get().getAlgorithmOption().name(), is(expected.getAlgorithmOption().getType())); } } + + private static void assertTablespace(final SQLCaseAssertContext assertContext, final CreateIndexStatement actual, final CreateIndexStatementTestCase expected) { + if (null == expected.getTablespace()) { + assertFalse(CreateIndexStatementHandler.getTablespaceSegment(actual).isPresent(), assertContext.getText("Actual tablespace segments should not exist.")); + } else { + assertTrue(CreateIndexStatementHandler.getTablespaceSegment(actual).isPresent(), assertContext.getText("Actual tablespace segments should exist.")); + assertThat(assertContext.getText(String.format("`%s`'s tablespace assertion error: ", actual.getClass().getSimpleName())), + CreateIndexStatementHandler.getTablespaceSegment(actual).get().getIdentifier().getValue(), is(expected.getTablespace().getName())); + } + } + + private static void assertIndexPartitions(final SQLCaseAssertContext assertContext, final CreateIndexStatement actual, final CreateIndexStatementTestCase expected) { + if (actual instanceof OpenGaussCreateIndexStatement) { + OpenGaussCreateIndexStatement actualOpenGauss = (OpenGaussCreateIndexStatement) actual; + if (null == expected.getIndexPartitions()) { + assertFalse(CreateIndexStatementHandler.getIndexPartitionsSegment(actualOpenGauss).isPresent(), assertContext.getText("Actual index partitions segments should not exist.")); + } else { + Optional optional = CreateIndexStatementHandler.getIndexPartitionsSegment(actualOpenGauss); + assertTrue(optional.isPresent(), assertContext.getText("Actual index partitions segments should exist.")); + IndexPartitionsAssert.assertIs(assertContext, optional.get(), expected.getIndexPartitions()); + } + } + } + } diff --git a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/segment/impl/index/ExpectedIndexPartition.java b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/segment/impl/index/ExpectedIndexPartition.java new file mode 100644 index 0000000000000..bdc82cc11bc54 --- /dev/null +++ b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/segment/impl/index/ExpectedIndexPartition.java @@ -0,0 +1,32 @@ +/* + * 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.index; + +import javax.xml.bind.annotation.XmlElement; +import lombok.Getter; +import lombok.Setter; +import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.segment.AbstractExpectedIdentifierSQLSegment; +import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.segment.impl.tablespace.ExpectedTablespace; + +@Getter +@Setter +public class ExpectedIndexPartition extends AbstractExpectedIdentifierSQLSegment { + + @XmlElement + private ExpectedTablespace tablespace; +} diff --git a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/segment/impl/index/ExpectedIndexPartitions.java b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/segment/impl/index/ExpectedIndexPartitions.java new file mode 100644 index 0000000000000..23badbf7da958 --- /dev/null +++ b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/segment/impl/index/ExpectedIndexPartitions.java @@ -0,0 +1,38 @@ +/* + * 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.index; + +import java.util.LinkedList; +import java.util.List; +import javax.xml.bind.annotation.XmlAttribute; +import javax.xml.bind.annotation.XmlElement; +import lombok.Getter; +import lombok.Setter; +import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.segment.AbstractExpectedSQLSegment; + +@Getter +@Setter +public class ExpectedIndexPartitions extends AbstractExpectedSQLSegment { + + @XmlAttribute + private String type; + + @XmlElement(name = "index-partition") + private final List partitions = new LinkedList<>(); + +} diff --git a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/statement/ddl/CreateIndexStatementTestCase.java b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/statement/ddl/CreateIndexStatementTestCase.java index ad8986407eb3d..28d68ecd2754e 100644 --- a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/statement/ddl/CreateIndexStatementTestCase.java +++ b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/statement/ddl/CreateIndexStatementTestCase.java @@ -22,6 +22,7 @@ import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.segment.impl.algorithm.ExpectedAlgorithmClause; import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.segment.impl.column.ExpectedColumn; import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.segment.impl.index.ExpectedIndex; +import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.segment.impl.index.ExpectedIndexPartitions; import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.segment.impl.lock.ExpectedLockTypeClause; import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.segment.impl.table.ExpectedTable; import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.SQLParserTestCase; @@ -29,6 +30,7 @@ import javax.xml.bind.annotation.XmlElement; import java.util.LinkedList; import java.util.List; +import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.segment.impl.tablespace.ExpectedTablespace; /** * Create index statement test case. @@ -49,6 +51,12 @@ public final class CreateIndexStatementTestCase extends SQLParserTestCase { @XmlElement(name = "lock-option") private ExpectedLockTypeClause lockOption; + @XmlElement(name = "index-partitions") + private ExpectedIndexPartitions indexPartitions; + + @XmlElement(name = "tablespace") + private ExpectedTablespace tablespace; + @XmlElement(name = "column") private final List columns = new LinkedList<>(); } diff --git a/test/it/parser/src/main/resources/case/ddl/create-index.xml b/test/it/parser/src/main/resources/case/ddl/create-index.xml index 09ce3d3accdf2..8b35b60f46f78 100644 --- a/test/it/parser/src/main/resources/case/ddl/create-index.xml +++ b/test/it/parser/src/main/resources/case/ddl/create-index.xml @@ -216,6 +216,7 @@ + @@ -262,6 +263,7 @@ + @@ -273,4 +275,21 @@
+ + + +
+ + + + + + + + + + + + +
diff --git a/test/it/parser/src/main/resources/sql/supported/ddl/create-index.xml b/test/it/parser/src/main/resources/sql/supported/ddl/create-index.xml index ee95fc832b53e..497c8a97b0209 100644 --- a/test/it/parser/src/main/resources/sql/supported/ddl/create-index.xml +++ b/test/it/parser/src/main/resources/sql/supported/ddl/create-index.xml @@ -54,10 +54,11 @@ WITH (FILLFACTOR = 80, PAD_INDEX = ON, DROP_EXISTING = ON);" db-types="SQLServer" /> - - - - - - + From 463f2176b630997a68f898ca7d298c7384edb5a3 Mon Sep 17 00:00:00 2001 From: tmyVvit Date: Mon, 28 Aug 2023 01:57:35 +0800 Subject: [PATCH 04/11] disable index assert in create index statement assert --- .../statement/ddl/impl/CreateIndexStatementAssert.java | 4 ---- test/it/parser/src/main/resources/case/ddl/create-index.xml | 1 - 2 files changed, 5 deletions(-) diff --git a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/statement/ddl/impl/CreateIndexStatementAssert.java b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/statement/ddl/impl/CreateIndexStatementAssert.java index 568e31cc34ab1..63b8dcbca1fe2 100644 --- a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/statement/ddl/impl/CreateIndexStatementAssert.java +++ b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/statement/ddl/impl/CreateIndexStatementAssert.java @@ -75,10 +75,6 @@ private static void assertIndex(final SQLCaseAssertContext assertContext, final // TODO should assert index for all databases(mysql and sqlserver do not parse index right now) if (actual instanceof OracleCreateIndexStatement) { IndexAssert.assertIs(assertContext, actual.getIndex(), expected.getIndex()); - } else if (actual instanceof OpenGaussCreateIndexStatement) { - if (null != expected.getIndex()) { - IndexAssert.assertIs(assertContext, actual.getIndex(), expected.getIndex()); - } } } diff --git a/test/it/parser/src/main/resources/case/ddl/create-index.xml b/test/it/parser/src/main/resources/case/ddl/create-index.xml index 8b35b60f46f78..7bbd8ac193762 100644 --- a/test/it/parser/src/main/resources/case/ddl/create-index.xml +++ b/test/it/parser/src/main/resources/case/ddl/create-index.xml @@ -216,7 +216,6 @@ - From 156a41c44f992aeae61816e31eb7cdfedba16406 Mon Sep 17 00:00:00 2001 From: tmyVvit Date: Mon, 28 Aug 2023 02:18:07 +0800 Subject: [PATCH 05/11] only enable tablespace assert for opengauss when create index --- .../ddl/impl/CreateIndexStatementAssert.java | 18 ++++++++++++------ .../main/resources/case/ddl/create-index.xml | 1 + 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/statement/ddl/impl/CreateIndexStatementAssert.java b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/statement/ddl/impl/CreateIndexStatementAssert.java index 63b8dcbca1fe2..2ffc3af895045 100644 --- a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/statement/ddl/impl/CreateIndexStatementAssert.java +++ b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/statement/ddl/impl/CreateIndexStatementAssert.java @@ -20,6 +20,7 @@ import java.util.Optional; import lombok.AccessLevel; import lombok.NoArgsConstructor; +import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.tablespace.TablespaceSegment; import org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.CreateIndexStatement; import org.apache.shardingsphere.sql.parser.sql.dialect.handler.ddl.CreateIndexStatementHandler; import org.apache.shardingsphere.sql.parser.sql.dialect.statement.opengauss.ddl.OpenGaussCreateIndexStatement; @@ -30,6 +31,7 @@ import org.apache.shardingsphere.test.it.sql.parser.internal.asserts.segment.index.IndexAssert; import org.apache.shardingsphere.test.it.sql.parser.internal.asserts.segment.index.IndexPartitionsAssert; import org.apache.shardingsphere.test.it.sql.parser.internal.asserts.segment.table.TableAssert; +import org.apache.shardingsphere.test.it.sql.parser.internal.asserts.segment.tablespace.TablespaceAssert; import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.ddl.CreateIndexStatementTestCase; import static org.hamcrest.CoreMatchers.is; @@ -107,13 +109,17 @@ private static void assertAlgorithm(final SQLCaseAssertContext assertContext, fi } private static void assertTablespace(final SQLCaseAssertContext assertContext, final CreateIndexStatement actual, final CreateIndexStatementTestCase expected) { - if (null == expected.getTablespace()) { - assertFalse(CreateIndexStatementHandler.getTablespaceSegment(actual).isPresent(), assertContext.getText("Actual tablespace segments should not exist.")); - } else { - assertTrue(CreateIndexStatementHandler.getTablespaceSegment(actual).isPresent(), assertContext.getText("Actual tablespace segments should exist.")); - assertThat(assertContext.getText(String.format("`%s`'s tablespace assertion error: ", actual.getClass().getSimpleName())), - CreateIndexStatementHandler.getTablespaceSegment(actual).get().getIdentifier().getValue(), is(expected.getTablespace().getName())); + // TODO should assert tablespace for all databases(postgreSQL do not support tablespace right now) + if (actual instanceof OpenGaussCreateIndexStatement) { + if (null == expected.getTablespace()) { + assertFalse(CreateIndexStatementHandler.getTablespaceSegment(actual).isPresent(), assertContext.getText("Actual tablespace segments should not exist.")); + } else { + assertTrue(CreateIndexStatementHandler.getTablespaceSegment(actual).isPresent(), assertContext.getText("Actual tablespace segments should exist.")); + TablespaceSegment tablespaceSegment = CreateIndexStatementHandler.getTablespaceSegment(actual).get(); + TablespaceAssert.assertIs(assertContext, tablespaceSegment, expected.getTablespace()); + } } + } private static void assertIndexPartitions(final SQLCaseAssertContext assertContext, final CreateIndexStatement actual, final CreateIndexStatementTestCase expected) { diff --git a/test/it/parser/src/main/resources/case/ddl/create-index.xml b/test/it/parser/src/main/resources/case/ddl/create-index.xml index 7bbd8ac193762..8b35b60f46f78 100644 --- a/test/it/parser/src/main/resources/case/ddl/create-index.xml +++ b/test/it/parser/src/main/resources/case/ddl/create-index.xml @@ -216,6 +216,7 @@ + From 00fe19e2a2e99922337e6c4ff7a55793495a5bda Mon Sep 17 00:00:00 2001 From: tmyVvit Date: Mon, 28 Aug 2023 21:12:44 +0800 Subject: [PATCH 06/11] opengauss add alter index move partition syntax parse --- .../antlr4/imports/opengauss/DDLStatement.g4 | 5 ++ .../statement/OpenGaussStatementVisitor.java | 14 ++++- .../type/OpenGaussDDLStatementVisitor.java | 4 ++ .../ddl/partition/PartitionNameSegment.java | 38 ++++++++++++++ .../ddl/OpenGaussAlterIndexStatement.java | 11 ++++ .../segment/IndexPartitionSegment.java | 4 +- .../segment/MovePartitionSegment.java | 39 ++++++++++++++ .../segment/index/IndexPartitionsAssert.java | 2 +- .../ddl/impl/AlterIndexStatementAssert.java | 51 +++++++++++++++++++ .../ddl/impl/CreateIndexStatementAssert.java | 2 +- .../impl/index/ExpectedMovePartition.java | 35 +++++++++++++ .../ddl/AlterIndexStatementTestCase.java | 4 ++ .../main/resources/case/ddl/alter-index.xml | 9 ++++ .../sql/supported/ddl/alter-index.xml | 1 + 14 files changed, 214 insertions(+), 5 deletions(-) create mode 100644 parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/segment/ddl/partition/PartitionNameSegment.java create mode 100644 parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/opengauss/segment/MovePartitionSegment.java create mode 100644 test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/segment/impl/index/ExpectedMovePartition.java diff --git a/parser/sql/dialect/opengauss/src/main/antlr4/imports/opengauss/DDLStatement.g4 b/parser/sql/dialect/opengauss/src/main/antlr4/imports/opengauss/DDLStatement.g4 index 770d7f87b8b84..6ecf6fbdde074 100644 --- a/parser/sql/dialect/opengauss/src/main/antlr4/imports/opengauss/DDLStatement.g4 +++ b/parser/sql/dialect/opengauss/src/main/antlr4/imports/opengauss/DDLStatement.g4 @@ -361,6 +361,7 @@ partitionCmd alterIndexDefinitionClause : renameIndexSpecification | alterIndexDependsOnExtension | alterIndexSetTableSpace | alterTableCmds | indexPartitionCmd + | alterIndexMovePartition ; indexPartitionCmd @@ -379,6 +380,10 @@ alterIndexSetTableSpace : (OWNED BY ignoredIdentifiers)? SET TABLESPACE name (NOWAIT)? ; +alterIndexMovePartition + : MOVE PARTITION indexPartitionName TABLESPACE name + ; + tableNamesClause : tableNameClause (COMMA_ tableNameClause)* ; diff --git a/parser/sql/dialect/opengauss/src/main/java/org/apache/shardingsphere/sql/parser/opengauss/visitor/statement/OpenGaussStatementVisitor.java b/parser/sql/dialect/opengauss/src/main/java/org/apache/shardingsphere/sql/parser/opengauss/visitor/statement/OpenGaussStatementVisitor.java index 7ffe20a705f25..dd9a6c149cad9 100644 --- a/parser/sql/dialect/opengauss/src/main/java/org/apache/shardingsphere/sql/parser/opengauss/visitor/statement/OpenGaussStatementVisitor.java +++ b/parser/sql/dialect/opengauss/src/main/java/org/apache/shardingsphere/sql/parser/opengauss/visitor/statement/OpenGaussStatementVisitor.java @@ -120,6 +120,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.partition.PartitionNameSegment; import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.tablespace.TablespaceSegment; import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.ReturningSegment; import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.assignment.AssignmentSegment; @@ -205,6 +206,7 @@ import org.apache.shardingsphere.sql.parser.sql.dialect.statement.opengauss.segment.IndexPartitionSegment; import org.apache.shardingsphere.sql.parser.sql.dialect.statement.opengauss.segment.IndexPartitionTypeEnum; import org.apache.shardingsphere.sql.parser.sql.dialect.statement.opengauss.segment.IndexPartitionsSegment; +import org.apache.shardingsphere.sql.parser.sql.dialect.statement.opengauss.segment.MovePartitionSegment; /** * Statement visitor for openGauss. @@ -1441,7 +1443,9 @@ public ASTNode visitIndexPartitionElemList(final OpenGaussStatementParser.IndexP @Override public ASTNode visitIndexPartitionElem(final OpenGaussStatementParser.IndexPartitionElemContext ctx) { - IndexPartitionSegment result = new IndexPartitionSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), (IdentifierValue) visit(ctx.indexPartitionName())); + PartitionNameSegment partitionName = + new PartitionNameSegment(ctx.indexPartitionName().getStart().getStartIndex(), ctx.indexPartitionName().getStop().getStopIndex(), (IdentifierValue) visit(ctx.indexPartitionName())); + IndexPartitionSegment result = new IndexPartitionSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), partitionName); if (null != ctx.tableSpace()) { result.setTablespace((TablespaceSegment) visit(ctx.tableSpace())); } @@ -1452,4 +1456,12 @@ public ASTNode visitIndexPartitionElem(final OpenGaussStatementParser.IndexParti public ASTNode visitTableSpace(final OpenGaussStatementParser.TableSpaceContext ctx) { return new TablespaceSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), (IdentifierValue) visit(ctx.name())); } + + @Override + public ASTNode visitAlterIndexMovePartition(final OpenGaussStatementParser.AlterIndexMovePartitionContext ctx) { + PartitionNameSegment partitionName = new PartitionNameSegment(ctx.indexPartitionName().getStart().getStartIndex(), ctx.indexPartitionName().getStop().getStopIndex(), + (IdentifierValue) visit(ctx.indexPartitionName().identifier())); + TablespaceSegment tablespace = new TablespaceSegment(ctx.name().getStart().getStartIndex(), ctx.name().getStop().getStopIndex(), (IdentifierValue) visit(ctx.name().identifier())); + return new MovePartitionSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), partitionName, tablespace); + } } diff --git a/parser/sql/dialect/opengauss/src/main/java/org/apache/shardingsphere/sql/parser/opengauss/visitor/statement/type/OpenGaussDDLStatementVisitor.java b/parser/sql/dialect/opengauss/src/main/java/org/apache/shardingsphere/sql/parser/opengauss/visitor/statement/type/OpenGaussDDLStatementVisitor.java index 7baf6a38f20bc..9b8483d5851de 100644 --- a/parser/sql/dialect/opengauss/src/main/java/org/apache/shardingsphere/sql/parser/opengauss/visitor/statement/type/OpenGaussDDLStatementVisitor.java +++ b/parser/sql/dialect/opengauss/src/main/java/org/apache/shardingsphere/sql/parser/opengauss/visitor/statement/type/OpenGaussDDLStatementVisitor.java @@ -255,6 +255,7 @@ import java.util.Optional; import java.util.stream.Collectors; import org.apache.shardingsphere.sql.parser.sql.dialect.statement.opengauss.segment.IndexPartitionsSegment; +import org.apache.shardingsphere.sql.parser.sql.dialect.statement.opengauss.segment.MovePartitionSegment; /** * DDL statement visitor for openGauss. @@ -579,6 +580,9 @@ public ASTNode visitAlterIndex(final AlterIndexContext ctx) { if (null != ctx.alterIndexDefinitionClause().renameIndexSpecification()) { result.setRenameIndex((IndexSegment) visit(ctx.alterIndexDefinitionClause().renameIndexSpecification().indexName())); } + if (null != ctx.alterIndexDefinitionClause().alterIndexMovePartition()) { + result.setMovePartition((MovePartitionSegment) visit(ctx.alterIndexDefinitionClause().alterIndexMovePartition())); + } return result; } diff --git a/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/segment/ddl/partition/PartitionNameSegment.java b/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/segment/ddl/partition/PartitionNameSegment.java new file mode 100644 index 0000000000000..93662ec78aef8 --- /dev/null +++ b/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/segment/ddl/partition/PartitionNameSegment.java @@ -0,0 +1,38 @@ +/* + * 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.common.segment.ddl.partition; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import org.apache.shardingsphere.sql.parser.sql.common.segment.SQLSegment; +import org.apache.shardingsphere.sql.parser.sql.common.value.identifier.IdentifierValue; + +/** + * Partition name segment. + */ +@RequiredArgsConstructor +@Getter +public class PartitionNameSegment implements SQLSegment { + + private final int startIndex; + + private final int stopIndex; + + private final IdentifierValue identifier; + +} diff --git a/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/opengauss/ddl/OpenGaussAlterIndexStatement.java b/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/opengauss/ddl/OpenGaussAlterIndexStatement.java index e3c3ecb38e06c..731269fafc516 100644 --- a/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/opengauss/ddl/OpenGaussAlterIndexStatement.java +++ b/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/opengauss/ddl/OpenGaussAlterIndexStatement.java @@ -23,6 +23,7 @@ import org.apache.shardingsphere.sql.parser.sql.dialect.statement.opengauss.OpenGaussStatement; import java.util.Optional; +import org.apache.shardingsphere.sql.parser.sql.dialect.statement.opengauss.segment.MovePartitionSegment; /** * OpenGauss alter index statement. @@ -32,6 +33,8 @@ public final class OpenGaussAlterIndexStatement extends AlterIndexStatement impl private IndexSegment renameIndex; + private MovePartitionSegment movePartition; + /** * Get rename index segment. * @@ -40,4 +43,12 @@ public final class OpenGaussAlterIndexStatement extends AlterIndexStatement impl public Optional getRenameIndex() { return Optional.ofNullable(renameIndex); } + + /** + * Get move partition segment. + * @return move partition segment + */ + public Optional getMovePartition() { + return Optional.ofNullable(movePartition); + } } diff --git a/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/opengauss/segment/IndexPartitionSegment.java b/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/opengauss/segment/IndexPartitionSegment.java index d6430532a69af..ff03d847af5b8 100644 --- a/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/opengauss/segment/IndexPartitionSegment.java +++ b/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/opengauss/segment/IndexPartitionSegment.java @@ -22,8 +22,8 @@ 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.partition.PartitionNameSegment; import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.tablespace.TablespaceSegment; -import org.apache.shardingsphere.sql.parser.sql.common.value.identifier.IdentifierValue; @RequiredArgsConstructor @Getter @@ -34,7 +34,7 @@ public class IndexPartitionSegment implements SQLSegment { private final int stopIndex; - private final IdentifierValue indexPartitionName; + private final PartitionNameSegment partitionName; private TablespaceSegment tablespace; diff --git a/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/opengauss/segment/MovePartitionSegment.java b/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/opengauss/segment/MovePartitionSegment.java new file mode 100644 index 0000000000000..b4b9865d1f206 --- /dev/null +++ b/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/opengauss/segment/MovePartitionSegment.java @@ -0,0 +1,39 @@ +/* + * 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.opengauss.segment; + +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.partition.PartitionNameSegment; +import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.tablespace.TablespaceSegment; + +@RequiredArgsConstructor +@Getter +@Setter +public class MovePartitionSegment implements SQLSegment { + + private final int startIndex; + + private final int stopIndex; + + private final PartitionNameSegment partitionName; + + private final TablespaceSegment tablespace; +} diff --git a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/segment/index/IndexPartitionsAssert.java b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/segment/index/IndexPartitionsAssert.java index 3ed8eb773ace7..d168afb9716f8 100644 --- a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/segment/index/IndexPartitionsAssert.java +++ b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/segment/index/IndexPartitionsAssert.java @@ -58,7 +58,7 @@ public static void assertIs(final SQLCaseAssertContext assertContext, final Inde private static void assertIs(final SQLCaseAssertContext assertContext, final IndexPartitionSegment actual, final ExpectedIndexPartition expected) { assertNotNull(expected, assertContext.getText("Index partition should exist.")); assertNotNull(actual, assertContext.getText("Index partition should exist.")); - IdentifierValueAssert.assertIs(assertContext, actual.getIndexPartitionName(), expected, "Index Partition"); + IdentifierValueAssert.assertIs(assertContext, actual.getPartitionName().getIdentifier(), expected, "Index Partition"); if (null == expected.getTablespace()) { assertFalse(actual.getTablespace().isPresent(), assertContext.getText("Actual tablespace should not exist.")); } else { diff --git a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/statement/ddl/impl/AlterIndexStatementAssert.java b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/statement/ddl/impl/AlterIndexStatementAssert.java index d2286c47ab64e..1b849ec6793df 100644 --- a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/statement/ddl/impl/AlterIndexStatementAssert.java +++ b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/statement/ddl/impl/AlterIndexStatementAssert.java @@ -19,18 +19,32 @@ import lombok.AccessLevel; import lombok.NoArgsConstructor; +import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.partition.PartitionNameSegment; +import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.tablespace.TablespaceSegment; import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.SimpleTableSegment; import org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.AlterIndexStatement; import org.apache.shardingsphere.sql.parser.sql.dialect.handler.ddl.AlterIndexStatementHandler; +import org.apache.shardingsphere.sql.parser.sql.dialect.handler.ddl.CreateIndexStatementHandler; +import org.apache.shardingsphere.sql.parser.sql.dialect.statement.opengauss.ddl.OpenGaussAlterIndexStatement; +import org.apache.shardingsphere.sql.parser.sql.dialect.statement.opengauss.segment.MovePartitionSegment; import org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.ddl.OracleAlterIndexStatement; 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.index.IndexAssert; +import org.apache.shardingsphere.test.it.sql.parser.internal.asserts.segment.index.IndexPartitionsAssert; import org.apache.shardingsphere.test.it.sql.parser.internal.asserts.segment.table.TableAssert; +import org.apache.shardingsphere.test.it.sql.parser.internal.asserts.segment.tablespace.TablespaceAssert; +import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.segment.impl.index.ExpectedPartition; +import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.segment.impl.tablespace.ExpectedTablespace; import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.ddl.AlterIndexStatementTestCase; import java.util.Optional; +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertTrue; /** @@ -49,6 +63,7 @@ public final class AlterIndexStatementAssert { public static void assertIs(final SQLCaseAssertContext assertContext, final AlterIndexStatement actual, final AlterIndexStatementTestCase expected) { assertTable(assertContext, actual, expected); assertIndex(assertContext, actual, expected); + assertMovePartition(assertContext, actual, expected); } private static void assertTable(final SQLCaseAssertContext assertContext, final AlterIndexStatement actual, final AlterIndexStatementTestCase expected) { @@ -67,4 +82,40 @@ private static void assertIndex(final SQLCaseAssertContext assertContext, final IndexAssert.assertIs(assertContext, actual.getIndex().get(), expected.getIndex()); } } + + private static void assertMovePartition(final SQLCaseAssertContext assertContext, final AlterIndexStatement actual, final AlterIndexStatementTestCase expected) { + if (actual instanceof OpenGaussAlterIndexStatement) { + OpenGaussAlterIndexStatement ogActual = (OpenGaussAlterIndexStatement) actual; + if (null == expected.getMovePartition()) { + assertFalse(ogActual.getMovePartition().isPresent(), assertContext.getText("Actual move partition should not exist.")); + } else { + assertTrue(ogActual.getMovePartition().isPresent(), assertContext.getText("Actual move partition should exist.")); + MovePartitionSegment actualMovePartition = ogActual.getMovePartition().get(); + // assert partition + assertPartition(assertContext, actualMovePartition.getPartitionName(), expected.getMovePartition().getPartition()); + // assert tablespace + assertTablespace(assertContext, actualMovePartition.getTablespace(), expected.getMovePartition().getTablespace()); + SQLSegmentAssert.assertIs(assertContext, actualMovePartition, expected.getMovePartition()); + } + } + } + + private static void assertPartition(final SQLCaseAssertContext assertContext, final PartitionNameSegment actual, final ExpectedPartition expected) { + if (null == expected) { + assertNull(actual, assertContext.getText("Actual partition name should not exist.")); + } else { + assertNotNull(actual, assertContext.getText("Actual partition name should exist.")); + assertThat(assertContext.getText("partition name assertion error: "), actual.getIdentifier().getValue(), is(expected.getName())); + SQLSegmentAssert.assertIs(assertContext, actual, expected); + } + } + + private static void assertTablespace(final SQLCaseAssertContext assertContext, final TablespaceSegment actual, final ExpectedTablespace expected) { + if (null == expected) { + assertNull(actual, assertContext.getText("Actual tablespace segments should not exist.")); + } else { + assertNotNull(actual, assertContext.getText("Actual tablespace segments should exist.")); + TablespaceAssert.assertIs(assertContext, actual, expected); + } + } } diff --git a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/statement/ddl/impl/CreateIndexStatementAssert.java b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/statement/ddl/impl/CreateIndexStatementAssert.java index 2ffc3af895045..b53cc557a0572 100644 --- a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/statement/ddl/impl/CreateIndexStatementAssert.java +++ b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/statement/ddl/impl/CreateIndexStatementAssert.java @@ -119,7 +119,7 @@ private static void assertTablespace(final SQLCaseAssertContext assertContext, f TablespaceAssert.assertIs(assertContext, tablespaceSegment, expected.getTablespace()); } } - + } private static void assertIndexPartitions(final SQLCaseAssertContext assertContext, final CreateIndexStatement actual, final CreateIndexStatementTestCase expected) { diff --git a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/segment/impl/index/ExpectedMovePartition.java b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/segment/impl/index/ExpectedMovePartition.java new file mode 100644 index 0000000000000..c60c042407bdb --- /dev/null +++ b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/segment/impl/index/ExpectedMovePartition.java @@ -0,0 +1,35 @@ +/* + * 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.index; + +import javax.xml.bind.annotation.XmlElement; +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.tablespace.ExpectedTablespace; + +@Getter +@Setter +public class ExpectedMovePartition extends AbstractExpectedSQLSegment { + + @XmlElement + private ExpectedPartition partition; + + @XmlElement + private ExpectedTablespace tablespace; +} diff --git a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/statement/ddl/AlterIndexStatementTestCase.java b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/statement/ddl/AlterIndexStatementTestCase.java index fd38ad1483dd0..8f31c5fb6a4f3 100644 --- a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/statement/ddl/AlterIndexStatementTestCase.java +++ b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/statement/ddl/AlterIndexStatementTestCase.java @@ -20,6 +20,7 @@ import lombok.Getter; import lombok.Setter; import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.segment.impl.index.ExpectedIndex; +import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.segment.impl.index.ExpectedMovePartition; import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.segment.impl.table.ExpectedSimpleTable; import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.SQLParserTestCase; @@ -37,4 +38,7 @@ public final class AlterIndexStatementTestCase extends SQLParserTestCase { @XmlElement private ExpectedSimpleTable table; + + @XmlElement(name = "move-partition") + private ExpectedMovePartition movePartition; } diff --git a/test/it/parser/src/main/resources/case/ddl/alter-index.xml b/test/it/parser/src/main/resources/case/ddl/alter-index.xml index 92a457fb9187a..88245f8026c59 100644 --- a/test/it/parser/src/main/resources/case/ddl/alter-index.xml +++ b/test/it/parser/src/main/resources/case/ddl/alter-index.xml @@ -145,4 +145,13 @@ + + + + + + + + + diff --git a/test/it/parser/src/main/resources/sql/supported/ddl/alter-index.xml b/test/it/parser/src/main/resources/sql/supported/ddl/alter-index.xml index 74acfc84b4711..6e963e315149a 100644 --- a/test/it/parser/src/main/resources/sql/supported/ddl/alter-index.xml +++ b/test/it/parser/src/main/resources/sql/supported/ddl/alter-index.xml @@ -53,4 +53,5 @@ + From 5ba126b8442a5f7a16b6d757250e3a5d0a913dcb Mon Sep 17 00:00:00 2001 From: tmyVvit Date: Mon, 28 Aug 2023 21:35:06 +0800 Subject: [PATCH 07/11] opengauss add alter index rename partition syntax parse --- .../antlr4/imports/opengauss/DDLStatement.g4 | 6 +++++- .../statement/OpenGaussStatementVisitor.java | 8 +++++++ .../type/OpenGaussDDLStatementVisitor.java | 4 ++++ .../ddl/OpenGaussAlterIndexStatement.java | 13 ++++++++++++ .../segment/RenamePartitionSegment.java | 21 +++++++++++++++++++ .../parser/internal/InternalSQLParserIT.java | 2 +- .../ddl/impl/AlterIndexStatementAssert.java | 2 -- .../impl/index/ExpectedRenamePartition.java | 17 +++++++++++++++ .../ddl/AlterIndexStatementTestCase.java | 4 ++++ .../main/resources/case/ddl/alter-index.xml | 9 ++++++++ .../sql/supported/ddl/alter-index.xml | 1 + 11 files changed, 83 insertions(+), 4 deletions(-) create mode 100644 parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/opengauss/segment/RenamePartitionSegment.java create mode 100644 test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/segment/impl/index/ExpectedRenamePartition.java diff --git a/parser/sql/dialect/opengauss/src/main/antlr4/imports/opengauss/DDLStatement.g4 b/parser/sql/dialect/opengauss/src/main/antlr4/imports/opengauss/DDLStatement.g4 index 6ecf6fbdde074..d6a48de2101e6 100644 --- a/parser/sql/dialect/opengauss/src/main/antlr4/imports/opengauss/DDLStatement.g4 +++ b/parser/sql/dialect/opengauss/src/main/antlr4/imports/opengauss/DDLStatement.g4 @@ -361,7 +361,7 @@ partitionCmd alterIndexDefinitionClause : renameIndexSpecification | alterIndexDependsOnExtension | alterIndexSetTableSpace | alterTableCmds | indexPartitionCmd - | alterIndexMovePartition + | alterIndexMovePartition | alterIndexRenamePartition ; indexPartitionCmd @@ -384,6 +384,10 @@ alterIndexMovePartition : MOVE PARTITION indexPartitionName TABLESPACE name ; +alterIndexRenamePartition + : RENAME PARTITION indexPartitionName TO indexPartitionName + ; + tableNamesClause : tableNameClause (COMMA_ tableNameClause)* ; diff --git a/parser/sql/dialect/opengauss/src/main/java/org/apache/shardingsphere/sql/parser/opengauss/visitor/statement/OpenGaussStatementVisitor.java b/parser/sql/dialect/opengauss/src/main/java/org/apache/shardingsphere/sql/parser/opengauss/visitor/statement/OpenGaussStatementVisitor.java index dd9a6c149cad9..bc7b528ac9fbf 100644 --- a/parser/sql/dialect/opengauss/src/main/java/org/apache/shardingsphere/sql/parser/opengauss/visitor/statement/OpenGaussStatementVisitor.java +++ b/parser/sql/dialect/opengauss/src/main/java/org/apache/shardingsphere/sql/parser/opengauss/visitor/statement/OpenGaussStatementVisitor.java @@ -207,6 +207,7 @@ import org.apache.shardingsphere.sql.parser.sql.dialect.statement.opengauss.segment.IndexPartitionTypeEnum; import org.apache.shardingsphere.sql.parser.sql.dialect.statement.opengauss.segment.IndexPartitionsSegment; import org.apache.shardingsphere.sql.parser.sql.dialect.statement.opengauss.segment.MovePartitionSegment; +import org.apache.shardingsphere.sql.parser.sql.dialect.statement.opengauss.segment.RenamePartitionSegment; /** * Statement visitor for openGauss. @@ -1464,4 +1465,11 @@ public ASTNode visitAlterIndexMovePartition(final OpenGaussStatementParser.Alter TablespaceSegment tablespace = new TablespaceSegment(ctx.name().getStart().getStartIndex(), ctx.name().getStop().getStopIndex(), (IdentifierValue) visit(ctx.name().identifier())); return new MovePartitionSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), partitionName, tablespace); } + + @Override + public ASTNode visitAlterIndexRenamePartition(final OpenGaussStatementParser.AlterIndexRenamePartitionContext ctx) { + PartitionNameSegment oldPartition = new PartitionNameSegment(ctx.indexPartitionName(0).getStart().getStartIndex(), ctx.indexPartitionName(0).getStop().getStopIndex(), (IdentifierValue) visit(ctx.indexPartitionName(0).identifier())); + PartitionNameSegment newPartition = new PartitionNameSegment(ctx.indexPartitionName(1).getStart().getStartIndex(), ctx.indexPartitionName(1).getStop().getStopIndex(), (IdentifierValue) visit(ctx.indexPartitionName(1).identifier())); + return new RenamePartitionSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), oldPartition, newPartition); + } } diff --git a/parser/sql/dialect/opengauss/src/main/java/org/apache/shardingsphere/sql/parser/opengauss/visitor/statement/type/OpenGaussDDLStatementVisitor.java b/parser/sql/dialect/opengauss/src/main/java/org/apache/shardingsphere/sql/parser/opengauss/visitor/statement/type/OpenGaussDDLStatementVisitor.java index 9b8483d5851de..b7c830511228e 100644 --- a/parser/sql/dialect/opengauss/src/main/java/org/apache/shardingsphere/sql/parser/opengauss/visitor/statement/type/OpenGaussDDLStatementVisitor.java +++ b/parser/sql/dialect/opengauss/src/main/java/org/apache/shardingsphere/sql/parser/opengauss/visitor/statement/type/OpenGaussDDLStatementVisitor.java @@ -256,6 +256,7 @@ import java.util.stream.Collectors; import org.apache.shardingsphere.sql.parser.sql.dialect.statement.opengauss.segment.IndexPartitionsSegment; import org.apache.shardingsphere.sql.parser.sql.dialect.statement.opengauss.segment.MovePartitionSegment; +import org.apache.shardingsphere.sql.parser.sql.dialect.statement.opengauss.segment.RenamePartitionSegment; /** * DDL statement visitor for openGauss. @@ -583,6 +584,9 @@ public ASTNode visitAlterIndex(final AlterIndexContext ctx) { if (null != ctx.alterIndexDefinitionClause().alterIndexMovePartition()) { result.setMovePartition((MovePartitionSegment) visit(ctx.alterIndexDefinitionClause().alterIndexMovePartition())); } + if (null != ctx.alterIndexDefinitionClause().alterIndexRenamePartition()) { + result.setRenamePartition((RenamePartitionSegment) visit(ctx.alterIndexDefinitionClause().alterIndexRenamePartition())); + } return result; } diff --git a/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/opengauss/ddl/OpenGaussAlterIndexStatement.java b/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/opengauss/ddl/OpenGaussAlterIndexStatement.java index 731269fafc516..0e9950a688eec 100644 --- a/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/opengauss/ddl/OpenGaussAlterIndexStatement.java +++ b/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/opengauss/ddl/OpenGaussAlterIndexStatement.java @@ -24,6 +24,7 @@ import java.util.Optional; import org.apache.shardingsphere.sql.parser.sql.dialect.statement.opengauss.segment.MovePartitionSegment; +import org.apache.shardingsphere.sql.parser.sql.dialect.statement.opengauss.segment.RenamePartitionSegment; /** * OpenGauss alter index statement. @@ -34,6 +35,8 @@ public final class OpenGaussAlterIndexStatement extends AlterIndexStatement impl private IndexSegment renameIndex; private MovePartitionSegment movePartition; + + private RenamePartitionSegment renamePartition; /** * Get rename index segment. @@ -46,9 +49,19 @@ public Optional getRenameIndex() { /** * Get move partition segment. + * * @return move partition segment */ public Optional getMovePartition() { return Optional.ofNullable(movePartition); } + + /** + * Get rename partition segment. + * + * @return rename partition segment + */ + public Optional getRenamePartition() { + return Optional.ofNullable(renamePartition); + } } diff --git a/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/opengauss/segment/RenamePartitionSegment.java b/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/opengauss/segment/RenamePartitionSegment.java new file mode 100644 index 0000000000000..039a55fdbc12f --- /dev/null +++ b/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/opengauss/segment/RenamePartitionSegment.java @@ -0,0 +1,21 @@ +package org.apache.shardingsphere.sql.parser.sql.dialect.statement.opengauss.segment; + +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.partition.PartitionNameSegment; + +@RequiredArgsConstructor +@Getter +@Setter +public class RenamePartitionSegment implements SQLSegment { + + private final int startIndex; + + private final int stopIndex; + + private final PartitionNameSegment oldPartition; + + private final PartitionNameSegment newPartition; +} diff --git a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/InternalSQLParserIT.java b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/InternalSQLParserIT.java index 57d90ee3672a2..b7280eb0c9af7 100644 --- a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/InternalSQLParserIT.java +++ b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/InternalSQLParserIT.java @@ -80,7 +80,7 @@ private Collection getTestParameters(final String... databaseTypes) { result.add(Arguments.arguments(each.getSqlCaseId(), each.getSqlCaseType(), each.getDatabaseType())); } } - return result; + return result.stream().filter(e -> "alter_index_rename_partition02".equals(e.get()[0])).collect(Collectors.toList()); } private boolean isPlaceholderWithoutParameter(final InternalSQLParserTestParameter testParam) { diff --git a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/statement/ddl/impl/AlterIndexStatementAssert.java b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/statement/ddl/impl/AlterIndexStatementAssert.java index 1b849ec6793df..6df1d81bfacac 100644 --- a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/statement/ddl/impl/AlterIndexStatementAssert.java +++ b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/statement/ddl/impl/AlterIndexStatementAssert.java @@ -24,14 +24,12 @@ import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.SimpleTableSegment; import org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.AlterIndexStatement; import org.apache.shardingsphere.sql.parser.sql.dialect.handler.ddl.AlterIndexStatementHandler; -import org.apache.shardingsphere.sql.parser.sql.dialect.handler.ddl.CreateIndexStatementHandler; import org.apache.shardingsphere.sql.parser.sql.dialect.statement.opengauss.ddl.OpenGaussAlterIndexStatement; import org.apache.shardingsphere.sql.parser.sql.dialect.statement.opengauss.segment.MovePartitionSegment; import org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.ddl.OracleAlterIndexStatement; 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.index.IndexAssert; -import org.apache.shardingsphere.test.it.sql.parser.internal.asserts.segment.index.IndexPartitionsAssert; import org.apache.shardingsphere.test.it.sql.parser.internal.asserts.segment.table.TableAssert; import org.apache.shardingsphere.test.it.sql.parser.internal.asserts.segment.tablespace.TablespaceAssert; import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.segment.impl.index.ExpectedPartition; diff --git a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/segment/impl/index/ExpectedRenamePartition.java b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/segment/impl/index/ExpectedRenamePartition.java new file mode 100644 index 0000000000000..6193ca46a5dcf --- /dev/null +++ b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/segment/impl/index/ExpectedRenamePartition.java @@ -0,0 +1,17 @@ +package org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.segment.impl.index; + +import javax.xml.bind.annotation.XmlElement; +import lombok.Getter; +import lombok.Setter; +import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.segment.AbstractExpectedSQLSegment; + +@Getter +@Setter +public class ExpectedRenamePartition extends AbstractExpectedSQLSegment { + + @XmlElement(name = "old-partition") + private ExpectedPartition oldPartition; + + @XmlElement(name = "new-partition") + private ExpectedPartition newPartition; +} diff --git a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/statement/ddl/AlterIndexStatementTestCase.java b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/statement/ddl/AlterIndexStatementTestCase.java index 8f31c5fb6a4f3..f0256ab83fd27 100644 --- a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/statement/ddl/AlterIndexStatementTestCase.java +++ b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/statement/ddl/AlterIndexStatementTestCase.java @@ -21,6 +21,7 @@ import lombok.Setter; import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.segment.impl.index.ExpectedIndex; import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.segment.impl.index.ExpectedMovePartition; +import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.segment.impl.index.ExpectedRenamePartition; import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.segment.impl.table.ExpectedSimpleTable; import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.SQLParserTestCase; @@ -41,4 +42,7 @@ public final class AlterIndexStatementTestCase extends SQLParserTestCase { @XmlElement(name = "move-partition") private ExpectedMovePartition movePartition; + + @XmlElement(name = "rename-partition") + private ExpectedRenamePartition renamePartition; } diff --git a/test/it/parser/src/main/resources/case/ddl/alter-index.xml b/test/it/parser/src/main/resources/case/ddl/alter-index.xml index 88245f8026c59..ce9ee3e72b537 100644 --- a/test/it/parser/src/main/resources/case/ddl/alter-index.xml +++ b/test/it/parser/src/main/resources/case/ddl/alter-index.xml @@ -154,4 +154,13 @@ + + + + + + + + + diff --git a/test/it/parser/src/main/resources/sql/supported/ddl/alter-index.xml b/test/it/parser/src/main/resources/sql/supported/ddl/alter-index.xml index 6e963e315149a..7f45fa29c7955 100644 --- a/test/it/parser/src/main/resources/sql/supported/ddl/alter-index.xml +++ b/test/it/parser/src/main/resources/sql/supported/ddl/alter-index.xml @@ -54,4 +54,5 @@ + From 7257061d2ae18fd114cf15c532e27bdd24f0a664 Mon Sep 17 00:00:00 2001 From: tmyVvit Date: Mon, 28 Aug 2023 22:08:17 +0800 Subject: [PATCH 08/11] opengauss add alter index rename partition syntax parse --- .../statement/OpenGaussStatementVisitor.java | 8 +++--- .../ddl/OpenGaussAlterIndexStatement.java | 4 +-- .../segment/RenamePartitionSegment.java | 25 ++++++++++++++++--- .../parser/internal/InternalSQLParserIT.java | 1 + .../ddl/impl/AlterIndexStatementAssert.java | 17 +++++++++++++ .../impl/index/ExpectedRenamePartition.java | 21 ++++++++++++++-- .../ddl/AlterIndexStatementTestCase.java | 2 +- 7 files changed, 66 insertions(+), 12 deletions(-) diff --git a/parser/sql/dialect/opengauss/src/main/java/org/apache/shardingsphere/sql/parser/opengauss/visitor/statement/OpenGaussStatementVisitor.java b/parser/sql/dialect/opengauss/src/main/java/org/apache/shardingsphere/sql/parser/opengauss/visitor/statement/OpenGaussStatementVisitor.java index bc7b528ac9fbf..c0531d75ea884 100644 --- a/parser/sql/dialect/opengauss/src/main/java/org/apache/shardingsphere/sql/parser/opengauss/visitor/statement/OpenGaussStatementVisitor.java +++ b/parser/sql/dialect/opengauss/src/main/java/org/apache/shardingsphere/sql/parser/opengauss/visitor/statement/OpenGaussStatementVisitor.java @@ -1465,11 +1465,13 @@ public ASTNode visitAlterIndexMovePartition(final OpenGaussStatementParser.Alter TablespaceSegment tablespace = new TablespaceSegment(ctx.name().getStart().getStartIndex(), ctx.name().getStop().getStopIndex(), (IdentifierValue) visit(ctx.name().identifier())); return new MovePartitionSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), partitionName, tablespace); } - + @Override public ASTNode visitAlterIndexRenamePartition(final OpenGaussStatementParser.AlterIndexRenamePartitionContext ctx) { - PartitionNameSegment oldPartition = new PartitionNameSegment(ctx.indexPartitionName(0).getStart().getStartIndex(), ctx.indexPartitionName(0).getStop().getStopIndex(), (IdentifierValue) visit(ctx.indexPartitionName(0).identifier())); - PartitionNameSegment newPartition = new PartitionNameSegment(ctx.indexPartitionName(1).getStart().getStartIndex(), ctx.indexPartitionName(1).getStop().getStopIndex(), (IdentifierValue) visit(ctx.indexPartitionName(1).identifier())); + PartitionNameSegment oldPartition = new PartitionNameSegment(ctx.indexPartitionName(0).getStart().getStartIndex(), + ctx.indexPartitionName(0).getStop().getStopIndex(), (IdentifierValue) visit(ctx.indexPartitionName(0).identifier())); + PartitionNameSegment newPartition = new PartitionNameSegment(ctx.indexPartitionName(1).getStart().getStartIndex(), + ctx.indexPartitionName(1).getStop().getStopIndex(), (IdentifierValue) visit(ctx.indexPartitionName(1).identifier())); return new RenamePartitionSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), oldPartition, newPartition); } } diff --git a/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/opengauss/ddl/OpenGaussAlterIndexStatement.java b/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/opengauss/ddl/OpenGaussAlterIndexStatement.java index 0e9950a688eec..1d920826a6a82 100644 --- a/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/opengauss/ddl/OpenGaussAlterIndexStatement.java +++ b/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/opengauss/ddl/OpenGaussAlterIndexStatement.java @@ -35,7 +35,7 @@ public final class OpenGaussAlterIndexStatement extends AlterIndexStatement impl private IndexSegment renameIndex; private MovePartitionSegment movePartition; - + private RenamePartitionSegment renamePartition; /** @@ -55,7 +55,7 @@ public Optional getRenameIndex() { public Optional getMovePartition() { return Optional.ofNullable(movePartition); } - + /** * Get rename partition segment. * diff --git a/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/opengauss/segment/RenamePartitionSegment.java b/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/opengauss/segment/RenamePartitionSegment.java index 039a55fdbc12f..aac388b75d800 100644 --- a/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/opengauss/segment/RenamePartitionSegment.java +++ b/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/opengauss/segment/RenamePartitionSegment.java @@ -1,3 +1,20 @@ +/* + * 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.opengauss.segment; import lombok.Getter; @@ -10,12 +27,12 @@ @Getter @Setter public class RenamePartitionSegment implements SQLSegment { - + private final int startIndex; - + private final int stopIndex; - + private final PartitionNameSegment oldPartition; - + private final PartitionNameSegment newPartition; } diff --git a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/InternalSQLParserIT.java b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/InternalSQLParserIT.java index b7280eb0c9af7..1c1c92abe6b94 100644 --- a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/InternalSQLParserIT.java +++ b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/InternalSQLParserIT.java @@ -80,6 +80,7 @@ private Collection getTestParameters(final String... databaseTypes) { result.add(Arguments.arguments(each.getSqlCaseId(), each.getSqlCaseType(), each.getDatabaseType())); } } +// return result; return result.stream().filter(e -> "alter_index_rename_partition02".equals(e.get()[0])).collect(Collectors.toList()); } diff --git a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/statement/ddl/impl/AlterIndexStatementAssert.java b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/statement/ddl/impl/AlterIndexStatementAssert.java index 6df1d81bfacac..def1a9dfb27dd 100644 --- a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/statement/ddl/impl/AlterIndexStatementAssert.java +++ b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/statement/ddl/impl/AlterIndexStatementAssert.java @@ -26,6 +26,7 @@ import org.apache.shardingsphere.sql.parser.sql.dialect.handler.ddl.AlterIndexStatementHandler; import org.apache.shardingsphere.sql.parser.sql.dialect.statement.opengauss.ddl.OpenGaussAlterIndexStatement; import org.apache.shardingsphere.sql.parser.sql.dialect.statement.opengauss.segment.MovePartitionSegment; +import org.apache.shardingsphere.sql.parser.sql.dialect.statement.opengauss.segment.RenamePartitionSegment; import org.apache.shardingsphere.sql.parser.sql.dialect.statement.oracle.ddl.OracleAlterIndexStatement; import org.apache.shardingsphere.test.it.sql.parser.internal.asserts.SQLCaseAssertContext; import org.apache.shardingsphere.test.it.sql.parser.internal.asserts.segment.SQLSegmentAssert; @@ -62,6 +63,7 @@ public static void assertIs(final SQLCaseAssertContext assertContext, final Alte assertTable(assertContext, actual, expected); assertIndex(assertContext, actual, expected); assertMovePartition(assertContext, actual, expected); + assertRenamePartition(assertContext, actual, expected); } private static void assertTable(final SQLCaseAssertContext assertContext, final AlterIndexStatement actual, final AlterIndexStatementTestCase expected) { @@ -116,4 +118,19 @@ private static void assertTablespace(final SQLCaseAssertContext assertContext, f TablespaceAssert.assertIs(assertContext, actual, expected); } } + + private static void assertRenamePartition(final SQLCaseAssertContext assertContext, final AlterIndexStatement actual, final AlterIndexStatementTestCase expected) { + if (actual instanceof OpenGaussAlterIndexStatement) { + OpenGaussAlterIndexStatement ogActual = (OpenGaussAlterIndexStatement) actual; + if (null == expected.getRenamePartition()) { + assertFalse(ogActual.getRenamePartition().isPresent(), assertContext.getText("Actual rename partition should not exist.")); + } else { + assertTrue(ogActual.getRenamePartition().isPresent(), assertContext.getText("Actual rename partition should exist.")); + RenamePartitionSegment renamePartition = ogActual.getRenamePartition().get(); + assertPartition(assertContext, renamePartition.getOldPartition(), expected.getRenamePartition().getOldPartition()); + assertPartition(assertContext, renamePartition.getNewPartition(), expected.getRenamePartition().getNewPartition()); + SQLSegmentAssert.assertIs(assertContext, renamePartition, expected.getRenamePartition()); + } + } + } } diff --git a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/segment/impl/index/ExpectedRenamePartition.java b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/segment/impl/index/ExpectedRenamePartition.java index 6193ca46a5dcf..bbdfa5324145e 100644 --- a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/segment/impl/index/ExpectedRenamePartition.java +++ b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/segment/impl/index/ExpectedRenamePartition.java @@ -1,3 +1,20 @@ +/* + * 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.index; import javax.xml.bind.annotation.XmlElement; @@ -8,10 +25,10 @@ @Getter @Setter public class ExpectedRenamePartition extends AbstractExpectedSQLSegment { - + @XmlElement(name = "old-partition") private ExpectedPartition oldPartition; - + @XmlElement(name = "new-partition") private ExpectedPartition newPartition; } diff --git a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/statement/ddl/AlterIndexStatementTestCase.java b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/statement/ddl/AlterIndexStatementTestCase.java index f0256ab83fd27..5ebe725a7f1d9 100644 --- a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/statement/ddl/AlterIndexStatementTestCase.java +++ b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/statement/ddl/AlterIndexStatementTestCase.java @@ -42,7 +42,7 @@ public final class AlterIndexStatementTestCase extends SQLParserTestCase { @XmlElement(name = "move-partition") private ExpectedMovePartition movePartition; - + @XmlElement(name = "rename-partition") private ExpectedRenamePartition renamePartition; } From e0a5c18a70546def15a033b77ab5a36915e8f159 Mon Sep 17 00:00:00 2001 From: tmyVvit Date: Mon, 28 Aug 2023 22:50:23 +0800 Subject: [PATCH 09/11] fix test --- .../test/it/sql/parser/internal/InternalSQLParserIT.java | 3 +-- .../asserts/statement/ddl/impl/AlterIndexStatementAssert.java | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/InternalSQLParserIT.java b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/InternalSQLParserIT.java index 1c1c92abe6b94..57d90ee3672a2 100644 --- a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/InternalSQLParserIT.java +++ b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/InternalSQLParserIT.java @@ -80,8 +80,7 @@ private Collection getTestParameters(final String... databaseTypes) { result.add(Arguments.arguments(each.getSqlCaseId(), each.getSqlCaseType(), each.getDatabaseType())); } } -// return result; - return result.stream().filter(e -> "alter_index_rename_partition02".equals(e.get()[0])).collect(Collectors.toList()); + return result; } private boolean isPlaceholderWithoutParameter(final InternalSQLParserTestParameter testParam) { diff --git a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/statement/ddl/impl/AlterIndexStatementAssert.java b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/statement/ddl/impl/AlterIndexStatementAssert.java index def1a9dfb27dd..5f9a3c3ebee0d 100644 --- a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/statement/ddl/impl/AlterIndexStatementAssert.java +++ b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/statement/ddl/impl/AlterIndexStatementAssert.java @@ -118,7 +118,7 @@ private static void assertTablespace(final SQLCaseAssertContext assertContext, f TablespaceAssert.assertIs(assertContext, actual, expected); } } - + private static void assertRenamePartition(final SQLCaseAssertContext assertContext, final AlterIndexStatement actual, final AlterIndexStatementTestCase expected) { if (actual instanceof OpenGaussAlterIndexStatement) { OpenGaussAlterIndexStatement ogActual = (OpenGaussAlterIndexStatement) actual; From e8743b67503bb992c14cfeb9c927f24ecc027db6 Mon Sep 17 00:00:00 2001 From: tmyVvit Date: Wed, 18 Oct 2023 20:55:29 +0800 Subject: [PATCH 10/11] fix some minor code issues --- .../antlr4/imports/opengauss/DDLStatement.g4 | 9 +++-- .../statement/OpenGaussStatementVisitor.java | 33 +++++++++++-------- .../ddl/partition/PartitionNameSegment.java | 1 - .../segment/IndexPartitionSegment.java | 11 +++++-- .../segment/IndexPartitionTypeEnum.java | 3 ++ .../segment/IndexPartitionsSegment.java | 5 ++- .../segment/MovePartitionSegment.java | 5 ++- .../segment/RenamePartitionSegment.java | 5 ++- .../ddl/impl/AlterIndexStatementAssert.java | 2 -- 9 files changed, 50 insertions(+), 24 deletions(-) diff --git a/parser/sql/dialect/opengauss/src/main/antlr4/imports/opengauss/DDLStatement.g4 b/parser/sql/dialect/opengauss/src/main/antlr4/imports/opengauss/DDLStatement.g4 index 766295a10ff97..8515b729ece34 100644 --- a/parser/sql/dialect/opengauss/src/main/antlr4/imports/opengauss/DDLStatement.g4 +++ b/parser/sql/dialect/opengauss/src/main/antlr4/imports/opengauss/DDLStatement.g4 @@ -360,8 +360,13 @@ partitionCmd ; alterIndexDefinitionClause - : renameIndexSpecification | alterIndexDependsOnExtension | alterIndexSetTableSpace | alterTableCmds | indexPartitionCmd - | alterIndexMovePartition | alterIndexRenamePartition + : renameIndexSpecification + | alterIndexDependsOnExtension + | alterIndexSetTableSpace + | alterTableCmds + | indexPartitionCmd + | alterIndexMovePartition + | alterIndexRenamePartition ; indexPartitionCmd diff --git a/parser/sql/dialect/opengauss/src/main/java/org/apache/shardingsphere/sql/parser/opengauss/visitor/statement/OpenGaussStatementVisitor.java b/parser/sql/dialect/opengauss/src/main/java/org/apache/shardingsphere/sql/parser/opengauss/visitor/statement/OpenGaussStatementVisitor.java index fbb25cda10357..370018bc57986 100644 --- a/parser/sql/dialect/opengauss/src/main/java/org/apache/shardingsphere/sql/parser/opengauss/visitor/statement/OpenGaussStatementVisitor.java +++ b/parser/sql/dialect/opengauss/src/main/java/org/apache/shardingsphere/sql/parser/opengauss/visitor/statement/OpenGaussStatementVisitor.java @@ -17,6 +17,12 @@ package org.apache.shardingsphere.sql.parser.opengauss.visitor.statement; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.LinkedList; +import java.util.List; +import java.util.Optional; import lombok.AccessLevel; import lombok.Getter; import org.antlr.v4.runtime.ParserRuleContext; @@ -30,6 +36,8 @@ import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.AExprContext; import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.AexprConstContext; import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.AliasClauseContext; +import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.AlterIndexMovePartitionContext; +import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.AlterIndexRenamePartitionContext; import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.AnyNameContext; import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.AscDescContext; import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.AssignmentContext; @@ -43,6 +51,7 @@ import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.ColumnNamesContext; import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.ColumnrefContext; import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.ConstraintNameContext; +import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.CreateIndexPartitionClauseContext; import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.DataTypeContext; import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.DataTypeLengthContext; import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.DataTypeNameContext; @@ -62,6 +71,8 @@ import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.IdentifierContext; import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.InExprContext; import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.IndexNameContext; +import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.IndexPartitionElemContext; +import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.IndexPartitionElemListContext; import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.IndirectionContext; import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.InsertColumnItemContext; import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.InsertColumnListContext; @@ -101,6 +112,7 @@ import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.TableNameContext; import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.TableNamesContext; import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.TableReferenceContext; +import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.TableSpaceContext; import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.TargetElContext; import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.TargetListContext; import org.apache.shardingsphere.sql.parser.autogen.OpenGaussStatementParser.UnreservedWordContext; @@ -197,13 +209,6 @@ import org.apache.shardingsphere.sql.parser.sql.dialect.statement.opengauss.dml.OpenGaussInsertStatement; import org.apache.shardingsphere.sql.parser.sql.dialect.statement.opengauss.dml.OpenGaussSelectStatement; import org.apache.shardingsphere.sql.parser.sql.dialect.statement.opengauss.dml.OpenGaussUpdateStatement; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.LinkedList; -import java.util.List; -import java.util.Optional; import org.apache.shardingsphere.sql.parser.sql.dialect.statement.opengauss.segment.IndexPartitionSegment; import org.apache.shardingsphere.sql.parser.sql.dialect.statement.opengauss.segment.IndexPartitionTypeEnum; import org.apache.shardingsphere.sql.parser.sql.dialect.statement.opengauss.segment.IndexPartitionsSegment; @@ -1423,9 +1428,9 @@ public ASTNode visitSignedIconst(final SignedIconstContext ctx) { @SuppressWarnings("unchecked") @Override - public ASTNode visitCreateIndexPartitionClause(final OpenGaussStatementParser.CreateIndexPartitionClauseContext ctx) { + public ASTNode visitCreateIndexPartitionClause(final CreateIndexPartitionClauseContext ctx) { IndexPartitionTypeEnum indexPartitionType = null; - if (ctx.LOCAL() != null || ctx.GLOBAL() != null) { + if (null != ctx.LOCAL() || null != ctx.GLOBAL()) { indexPartitionType = ctx.LOCAL() != null ? IndexPartitionTypeEnum.LOCAL : IndexPartitionTypeEnum.GLOBAL; } IndexPartitionsSegment result = new IndexPartitionsSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), indexPartitionType); @@ -1436,7 +1441,7 @@ public ASTNode visitCreateIndexPartitionClause(final OpenGaussStatementParser.Cr } @Override - public ASTNode visitIndexPartitionElemList(final OpenGaussStatementParser.IndexPartitionElemListContext ctx) { + public ASTNode visitIndexPartitionElemList(final IndexPartitionElemListContext ctx) { CollectionValue result = new CollectionValue<>(); for (OpenGaussStatementParser.IndexPartitionElemContext each : ctx.indexPartitionElem()) { result.getValue().add((IndexPartitionSegment) visit(each)); @@ -1445,7 +1450,7 @@ public ASTNode visitIndexPartitionElemList(final OpenGaussStatementParser.IndexP } @Override - public ASTNode visitIndexPartitionElem(final OpenGaussStatementParser.IndexPartitionElemContext ctx) { + public ASTNode visitIndexPartitionElem(final IndexPartitionElemContext ctx) { PartitionNameSegment partitionName = new PartitionNameSegment(ctx.indexPartitionName().getStart().getStartIndex(), ctx.indexPartitionName().getStop().getStopIndex(), (IdentifierValue) visit(ctx.indexPartitionName())); IndexPartitionSegment result = new IndexPartitionSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), partitionName); @@ -1456,12 +1461,12 @@ public ASTNode visitIndexPartitionElem(final OpenGaussStatementParser.IndexParti } @Override - public ASTNode visitTableSpace(final OpenGaussStatementParser.TableSpaceContext ctx) { + public ASTNode visitTableSpace(final TableSpaceContext ctx) { return new TablespaceSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), (IdentifierValue) visit(ctx.name())); } @Override - public ASTNode visitAlterIndexMovePartition(final OpenGaussStatementParser.AlterIndexMovePartitionContext ctx) { + public ASTNode visitAlterIndexMovePartition(final AlterIndexMovePartitionContext ctx) { PartitionNameSegment partitionName = new PartitionNameSegment(ctx.indexPartitionName().getStart().getStartIndex(), ctx.indexPartitionName().getStop().getStopIndex(), (IdentifierValue) visit(ctx.indexPartitionName().identifier())); TablespaceSegment tablespace = new TablespaceSegment(ctx.name().getStart().getStartIndex(), ctx.name().getStop().getStopIndex(), (IdentifierValue) visit(ctx.name().identifier())); @@ -1469,7 +1474,7 @@ public ASTNode visitAlterIndexMovePartition(final OpenGaussStatementParser.Alter } @Override - public ASTNode visitAlterIndexRenamePartition(final OpenGaussStatementParser.AlterIndexRenamePartitionContext ctx) { + public ASTNode visitAlterIndexRenamePartition(final AlterIndexRenamePartitionContext ctx) { PartitionNameSegment oldPartition = new PartitionNameSegment(ctx.indexPartitionName(0).getStart().getStartIndex(), ctx.indexPartitionName(0).getStop().getStopIndex(), (IdentifierValue) visit(ctx.indexPartitionName(0).identifier())); PartitionNameSegment newPartition = new PartitionNameSegment(ctx.indexPartitionName(1).getStart().getStartIndex(), diff --git a/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/segment/ddl/partition/PartitionNameSegment.java b/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/segment/ddl/partition/PartitionNameSegment.java index 93662ec78aef8..d2da140988eb5 100644 --- a/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/segment/ddl/partition/PartitionNameSegment.java +++ b/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/segment/ddl/partition/PartitionNameSegment.java @@ -34,5 +34,4 @@ public class PartitionNameSegment implements SQLSegment { private final int stopIndex; private final IdentifierValue identifier; - } diff --git a/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/opengauss/segment/IndexPartitionSegment.java b/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/opengauss/segment/IndexPartitionSegment.java index ff03d847af5b8..a2494521044ab 100644 --- a/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/opengauss/segment/IndexPartitionSegment.java +++ b/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/opengauss/segment/IndexPartitionSegment.java @@ -25,10 +25,13 @@ import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.partition.PartitionNameSegment; import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.tablespace.TablespaceSegment; +/** + * Index partition segment. + */ @RequiredArgsConstructor @Getter @Setter -public class IndexPartitionSegment implements SQLSegment { +public final class IndexPartitionSegment implements SQLSegment { private final int startIndex; @@ -37,7 +40,11 @@ public class IndexPartitionSegment implements SQLSegment { private final PartitionNameSegment partitionName; private TablespaceSegment tablespace; - + + /** + * Get tablespace. + * @return tablespace + */ public Optional getTablespace() { return Optional.ofNullable(tablespace); } diff --git a/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/opengauss/segment/IndexPartitionTypeEnum.java b/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/opengauss/segment/IndexPartitionTypeEnum.java index ba145887394d3..9aa6cccdfb3b2 100644 --- a/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/opengauss/segment/IndexPartitionTypeEnum.java +++ b/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/opengauss/segment/IndexPartitionTypeEnum.java @@ -17,6 +17,9 @@ package org.apache.shardingsphere.sql.parser.sql.dialect.statement.opengauss.segment; +/** + * Index partition type enum. + */ public enum IndexPartitionTypeEnum { GLOBAL, LOCAL } diff --git a/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/opengauss/segment/IndexPartitionsSegment.java b/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/opengauss/segment/IndexPartitionsSegment.java index 7c7d019d749f7..1988a1cf0dcf6 100644 --- a/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/opengauss/segment/IndexPartitionsSegment.java +++ b/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/opengauss/segment/IndexPartitionsSegment.java @@ -23,9 +23,12 @@ import lombok.RequiredArgsConstructor; import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.AlterDefinitionSegment; +/** + * Index partitions segment. + */ @RequiredArgsConstructor @Getter -public class IndexPartitionsSegment implements AlterDefinitionSegment { +public final class IndexPartitionsSegment implements AlterDefinitionSegment { private final int startIndex; diff --git a/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/opengauss/segment/MovePartitionSegment.java b/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/opengauss/segment/MovePartitionSegment.java index b4b9865d1f206..cc582572f569a 100644 --- a/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/opengauss/segment/MovePartitionSegment.java +++ b/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/opengauss/segment/MovePartitionSegment.java @@ -24,10 +24,13 @@ import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.partition.PartitionNameSegment; import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.tablespace.TablespaceSegment; +/** + * Move partition segment. + */ @RequiredArgsConstructor @Getter @Setter -public class MovePartitionSegment implements SQLSegment { +public final class MovePartitionSegment implements SQLSegment { private final int startIndex; diff --git a/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/opengauss/segment/RenamePartitionSegment.java b/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/opengauss/segment/RenamePartitionSegment.java index aac388b75d800..c14863bd493e1 100644 --- a/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/opengauss/segment/RenamePartitionSegment.java +++ b/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/opengauss/segment/RenamePartitionSegment.java @@ -23,10 +23,13 @@ import org.apache.shardingsphere.sql.parser.sql.common.segment.SQLSegment; import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.partition.PartitionNameSegment; +/** + * Rename partition segment. + */ @RequiredArgsConstructor @Getter @Setter -public class RenamePartitionSegment implements SQLSegment { +public final class RenamePartitionSegment implements SQLSegment { private final int startIndex; diff --git a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/statement/ddl/impl/AlterIndexStatementAssert.java b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/statement/ddl/impl/AlterIndexStatementAssert.java index 5f9a3c3ebee0d..e3432f01a8479 100644 --- a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/statement/ddl/impl/AlterIndexStatementAssert.java +++ b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/statement/ddl/impl/AlterIndexStatementAssert.java @@ -91,9 +91,7 @@ private static void assertMovePartition(final SQLCaseAssertContext assertContext } else { assertTrue(ogActual.getMovePartition().isPresent(), assertContext.getText("Actual move partition should exist.")); MovePartitionSegment actualMovePartition = ogActual.getMovePartition().get(); - // assert partition assertPartition(assertContext, actualMovePartition.getPartitionName(), expected.getMovePartition().getPartition()); - // assert tablespace assertTablespace(assertContext, actualMovePartition.getTablespace(), expected.getMovePartition().getTablespace()); SQLSegmentAssert.assertIs(assertContext, actualMovePartition, expected.getMovePartition()); } From 3294591fbe8667e7b303ada5073e3d6d388c0ec5 Mon Sep 17 00:00:00 2001 From: tmyVvit Date: Thu, 19 Oct 2023 11:40:48 +0800 Subject: [PATCH 11/11] fix some minor code issues --- .../statement/opengauss/segment/IndexPartitionSegment.java | 1 + 1 file changed, 1 insertion(+) diff --git a/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/opengauss/segment/IndexPartitionSegment.java b/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/opengauss/segment/IndexPartitionSegment.java index a2494521044ab..f0b7bce09443a 100644 --- a/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/opengauss/segment/IndexPartitionSegment.java +++ b/parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/opengauss/segment/IndexPartitionSegment.java @@ -43,6 +43,7 @@ public final class IndexPartitionSegment implements SQLSegment { /** * Get tablespace. + * * @return tablespace */ public Optional getTablespace() {