-
Notifications
You must be signed in to change notification settings - Fork 6.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
support parse opengauss create index #28291
Changes from 10 commits
f1312bf
7ebfb6f
22f64f8
463f217
156a41c
00fe19e
5ba126b
7257061
e0a5c18
a974cf3
e8743b6
fbe67b2
3294591
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -524,6 +524,10 @@ collationName | |
; | ||
|
||
indexName | ||
: (owner DOT_)? name | ||
; | ||
|
||
indexPartitionName | ||
: identifier | ||
; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
|
@@ -120,6 +121,8 @@ | |
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; | ||
import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.assignment.ColumnAssignmentSegment; | ||
|
@@ -201,6 +204,11 @@ | |
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; | ||
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. | ||
|
@@ -261,8 +269,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 | ||
|
@@ -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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please put null codition on the left side. |
||
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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please import subclass directly. |
||
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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please import subclass directly. |
||
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())); | ||
} | ||
return result; | ||
} | ||
|
||
@Override | ||
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); | ||
} | ||
|
||
@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); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please remove useless blank line. |
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.