strongduanmu commented on code in PR #28291:
URL: https://github.com/apache/shardingsphere/pull/28291#discussion_r1363227224


##########
parser/sql/dialect/opengauss/src/main/java/org/apache/shardingsphere/sql/parser/opengauss/visitor/statement/OpenGaussStatementVisitor.java:
##########
@@ -1407,4 +1420,60 @@ 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) {

Review Comment:
   Please put null codition on the left side.



##########
parser/sql/dialect/opengauss/src/main/antlr4/imports/opengauss/DDLStatement.g4:
##########
@@ -348,6 +361,7 @@ partitionCmd
 
 alterIndexDefinitionClause
     : renameIndexSpecification | alterIndexDependsOnExtension | 
alterIndexSetTableSpace | alterTableCmds | indexPartitionCmd

Review Comment:
   Can you write the rules one by one? According to the code specification, 
when there are more than 5 branches, a rule needs to be written one line.



##########
parser/sql/dialect/opengauss/src/main/java/org/apache/shardingsphere/sql/parser/opengauss/visitor/statement/OpenGaussStatementVisitor.java:
##########
@@ -1407,4 +1420,60 @@ 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<IndexPartitionSegment>)
 visit(ctx.indexPartitionElemList())).getValue());
+        }
+        return result;
+    }
+    
+    @Override
+    public ASTNode visitIndexPartitionElemList(final 
OpenGaussStatementParser.IndexPartitionElemListContext ctx) {

Review Comment:
   Please import subclass directly.



##########
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.partition.PartitionNameSegment;
+import 
org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.tablespace.TablespaceSegment;
+
+@RequiredArgsConstructor
+@Getter
+@Setter
+public class IndexPartitionSegment implements SQLSegment {

Review Comment:
   Please add final for this class.



##########
parser/sql/dialect/opengauss/src/main/java/org/apache/shardingsphere/sql/parser/opengauss/visitor/statement/OpenGaussStatementVisitor.java:
##########
@@ -1407,4 +1420,60 @@ 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<IndexPartitionSegment>)
 visit(ctx.indexPartitionElemList())).getValue());
+        }
+        return result;
+    }
+    
+    @Override
+    public ASTNode visitIndexPartitionElemList(final 
OpenGaussStatementParser.IndexPartitionElemListContext ctx) {
+        CollectionValue<IndexPartitionSegment> 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) {

Review Comment:
   Please import subclass directly.



##########
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.partition.PartitionNameSegment;
+import 
org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.tablespace.TablespaceSegment;
+
+@RequiredArgsConstructor
+@Getter
+@Setter
+public class IndexPartitionSegment implements SQLSegment {
+    
+    private final int startIndex;
+    
+    private final int stopIndex;
+    
+    private final PartitionNameSegment partitionName;
+    
+    private TablespaceSegment tablespace;
+    
+    public Optional<TablespaceSegment> getTablespace() {

Review Comment:
   Please add javadoc for public method.



##########
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 {

Review Comment:
   Please add final and javadoc for this class.



##########
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 {

Review Comment:
   Please add final and javadoc for this class.



##########
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;
+    

Review Comment:
   Please remove useless blank line.



##########
test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/statement/ddl/impl/AlterIndexStatementAssert.java:
##########
@@ -67,4 +82,55 @@ 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

Review Comment:
   Please remove useless inline comment.



##########
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 {

Review Comment:
   Please add javadoc for this class.



##########
parser/sql/statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/dialect/statement/opengauss/segment/RenamePartitionSegment.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.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 {

Review Comment:
   Please add final and javadoc for this class.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to