-
Notifications
You must be signed in to change notification settings - Fork 6.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support alter table, drop table sql bind and add test case (#34154)
* Support sql bind for select with current select projection reference * update release note * fix unit test * fix unit test * fix unit test * fix unit test * Support alter table, drop table sql bind and add test case * update release note * fix rewrite it
- Loading branch information
1 parent
bca6f32
commit 8aaa7c7
Showing
31 changed files
with
526 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
...rg/apache/shardingsphere/infra/binder/engine/statement/ddl/AlterTableStatementBinder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
* 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.infra.binder.engine.statement.ddl; | ||
|
||
import com.cedarsoftware.util.CaseInsensitiveMap.CaseInsensitiveString; | ||
import com.google.common.collect.LinkedHashMultimap; | ||
import com.google.common.collect.Multimap; | ||
import lombok.SneakyThrows; | ||
import org.apache.shardingsphere.infra.binder.engine.segment.from.context.TableSegmentBinderContext; | ||
import org.apache.shardingsphere.infra.binder.engine.segment.from.type.SimpleTableSegmentBinder; | ||
import org.apache.shardingsphere.infra.binder.engine.statement.SQLStatementBinder; | ||
import org.apache.shardingsphere.infra.binder.engine.statement.SQLStatementBinderContext; | ||
import org.apache.shardingsphere.sql.parser.statement.core.statement.ddl.AlterTableStatement; | ||
|
||
/** | ||
* Alter table statement binder. | ||
*/ | ||
public final class AlterTableStatementBinder implements SQLStatementBinder<AlterTableStatement> { | ||
|
||
@Override | ||
public AlterTableStatement bind(final AlterTableStatement sqlStatement, final SQLStatementBinderContext binderContext) { | ||
AlterTableStatement result = copy(sqlStatement); | ||
Multimap<CaseInsensitiveString, TableSegmentBinderContext> tableBinderContexts = LinkedHashMultimap.create(); | ||
result.setTable(SimpleTableSegmentBinder.bind(sqlStatement.getTable(), binderContext, tableBinderContexts)); | ||
sqlStatement.getRenameTable().ifPresent(optional -> result.setRenameTable(SimpleTableSegmentBinder.bind(optional, binderContext, tableBinderContexts))); | ||
return result; | ||
} | ||
|
||
@SneakyThrows(ReflectiveOperationException.class) | ||
private static AlterTableStatement copy(final AlterTableStatement sqlStatement) { | ||
AlterTableStatement result = sqlStatement.getClass().getDeclaredConstructor().newInstance(); | ||
// TODO bind column and reference table if kernel need use them | ||
sqlStatement.getConvertTableDefinition().ifPresent(result::setConvertTableDefinition); | ||
result.getAddColumnDefinitions().addAll(sqlStatement.getAddColumnDefinitions()); | ||
result.getModifyColumnDefinitions().addAll(sqlStatement.getModifyColumnDefinitions()); | ||
result.getChangeColumnDefinitions().addAll(sqlStatement.getChangeColumnDefinitions()); | ||
result.getDropColumnDefinitions().addAll(sqlStatement.getDropColumnDefinitions()); | ||
result.getAddConstraintDefinitions().addAll(sqlStatement.getAddConstraintDefinitions()); | ||
result.getValidateConstraintDefinitions().addAll(sqlStatement.getValidateConstraintDefinitions()); | ||
result.getModifyConstraintDefinitions().addAll(sqlStatement.getModifyConstraintDefinitions()); | ||
result.getDropConstraintDefinitions().addAll(sqlStatement.getDropConstraintDefinitions()); | ||
result.getDropIndexDefinitions().addAll(sqlStatement.getDropIndexDefinitions()); | ||
result.getRenameColumnDefinitions().addAll(sqlStatement.getRenameColumnDefinitions()); | ||
result.getRenameIndexDefinitions().addAll(sqlStatement.getRenameIndexDefinitions()); | ||
sqlStatement.getModifyCollectionRetrieval().ifPresent(result::setModifyCollectionRetrieval); | ||
result.addParameterMarkerSegments(sqlStatement.getParameterMarkerSegments()); | ||
result.getCommentSegments().addAll(sqlStatement.getCommentSegments()); | ||
result.getVariableNames().addAll(sqlStatement.getVariableNames()); | ||
return result; | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
...org/apache/shardingsphere/infra/binder/engine/statement/ddl/DropTableStatementBinder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* 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.infra.binder.engine.statement.ddl; | ||
|
||
import com.cedarsoftware.util.CaseInsensitiveMap.CaseInsensitiveString; | ||
import com.google.common.collect.LinkedHashMultimap; | ||
import com.google.common.collect.Multimap; | ||
import lombok.SneakyThrows; | ||
import org.apache.shardingsphere.infra.binder.engine.segment.from.context.TableSegmentBinderContext; | ||
import org.apache.shardingsphere.infra.binder.engine.segment.from.type.SimpleTableSegmentBinder; | ||
import org.apache.shardingsphere.infra.binder.engine.statement.SQLStatementBinder; | ||
import org.apache.shardingsphere.infra.binder.engine.statement.SQLStatementBinderContext; | ||
import org.apache.shardingsphere.sql.parser.statement.core.statement.ddl.DropTableStatement; | ||
|
||
/** | ||
* Drop table statement binder. | ||
*/ | ||
public final class DropTableStatementBinder implements SQLStatementBinder<DropTableStatement> { | ||
|
||
@Override | ||
public DropTableStatement bind(final DropTableStatement sqlStatement, final SQLStatementBinderContext binderContext) { | ||
DropTableStatement result = copy(sqlStatement); | ||
Multimap<CaseInsensitiveString, TableSegmentBinderContext> tableBinderContexts = LinkedHashMultimap.create(); | ||
sqlStatement.getTables().forEach(each -> result.getTables().add(SimpleTableSegmentBinder.bind(each, binderContext, tableBinderContexts))); | ||
return result; | ||
} | ||
|
||
@SneakyThrows(ReflectiveOperationException.class) | ||
private static DropTableStatement copy(final DropTableStatement sqlStatement) { | ||
DropTableStatement result = sqlStatement.getClass().getDeclaredConstructor().newInstance(); | ||
result.setIfExists(sqlStatement.isIfExists()); | ||
result.setContainsCascade(sqlStatement.isContainsCascade()); | ||
result.addParameterMarkerSegments(sqlStatement.getParameterMarkerSegments()); | ||
result.getCommentSegments().addAll(sqlStatement.getCommentSegments()); | ||
result.getVariableNames().addAll(sqlStatement.getVariableNames()); | ||
return result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.