-
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 create view, alter view, drop view sql bind logic (#34167)
* Support create view, alter view, drop view sql bind logic * Support create view, alter view, drop view sql bind logic * Support create view, alter view, drop view sql bind logic * update release note * fix rewrite it
- Loading branch information
1 parent
e95517c
commit 7f8fa57
Showing
24 changed files
with
442 additions
and
18 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
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
56 changes: 56 additions & 0 deletions
56
...org/apache/shardingsphere/infra/binder/engine/statement/ddl/AlterViewStatementBinder.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,56 @@ | ||
/* | ||
* 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.dml.from.context.TableSegmentBinderContext; | ||
import org.apache.shardingsphere.infra.binder.engine.segment.dml.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.infra.binder.engine.statement.dml.SelectStatementBinder; | ||
import org.apache.shardingsphere.sql.parser.statement.core.statement.ddl.AlterViewStatement; | ||
|
||
/** | ||
* Alter view statement binder. | ||
*/ | ||
public final class AlterViewStatementBinder implements SQLStatementBinder<AlterViewStatement> { | ||
|
||
@Override | ||
public AlterViewStatement bind(final AlterViewStatement sqlStatement, final SQLStatementBinderContext binderContext) { | ||
AlterViewStatement result = copy(sqlStatement); | ||
Multimap<CaseInsensitiveString, TableSegmentBinderContext> tableBinderContexts = LinkedHashMultimap.create(); | ||
result.setView(SimpleTableSegmentBinder.bind(sqlStatement.getView(), binderContext, tableBinderContexts)); | ||
sqlStatement.getSelect().ifPresent(optional -> result.setSelect(new SelectStatementBinder().bind(optional, binderContext))); | ||
sqlStatement.getRenameView().ifPresent(optional -> result.setRenameView(SimpleTableSegmentBinder.bind(optional, binderContext, tableBinderContexts))); | ||
return result; | ||
} | ||
|
||
@SneakyThrows(ReflectiveOperationException.class) | ||
private static AlterViewStatement copy(final AlterViewStatement sqlStatement) { | ||
AlterViewStatement result = sqlStatement.getClass().getDeclaredConstructor().newInstance(); | ||
sqlStatement.getViewDefinition().ifPresent(result::setViewDefinition); | ||
sqlStatement.getConstraintDefinition().ifPresent(result::setConstraintDefinition); | ||
result.addParameterMarkerSegments(sqlStatement.getParameterMarkerSegments()); | ||
result.getCommentSegments().addAll(sqlStatement.getCommentSegments()); | ||
result.getVariableNames().addAll(sqlStatement.getVariableNames()); | ||
return result; | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
...rg/apache/shardingsphere/infra/binder/engine/statement/ddl/CreateViewStatementBinder.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,54 @@ | ||
/* | ||
* 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.dml.from.context.TableSegmentBinderContext; | ||
import org.apache.shardingsphere.infra.binder.engine.segment.dml.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.infra.binder.engine.statement.dml.SelectStatementBinder; | ||
import org.apache.shardingsphere.sql.parser.statement.core.statement.ddl.CreateViewStatement; | ||
|
||
/** | ||
* Create view statement binder. | ||
*/ | ||
public final class CreateViewStatementBinder implements SQLStatementBinder<CreateViewStatement> { | ||
|
||
@Override | ||
public CreateViewStatement bind(final CreateViewStatement sqlStatement, final SQLStatementBinderContext binderContext) { | ||
CreateViewStatement result = copy(sqlStatement); | ||
Multimap<CaseInsensitiveString, TableSegmentBinderContext> tableBinderContexts = LinkedHashMultimap.create(); | ||
result.setView(SimpleTableSegmentBinder.bind(sqlStatement.getView(), binderContext, tableBinderContexts)); | ||
result.setSelect(new SelectStatementBinder().bind(sqlStatement.getSelect(), binderContext)); | ||
return result; | ||
} | ||
|
||
@SneakyThrows(ReflectiveOperationException.class) | ||
private static CreateViewStatement copy(final CreateViewStatement sqlStatement) { | ||
CreateViewStatement result = sqlStatement.getClass().getDeclaredConstructor().newInstance(); | ||
result.setViewDefinition(sqlStatement.getViewDefinition()); | ||
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
51 changes: 51 additions & 0 deletions
51
.../org/apache/shardingsphere/infra/binder/engine/statement/ddl/DropViewStatementBinder.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,51 @@ | ||
/* | ||
* 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.dml.from.context.TableSegmentBinderContext; | ||
import org.apache.shardingsphere.infra.binder.engine.segment.dml.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.DropViewStatement; | ||
|
||
/** | ||
* Drop view statement binder. | ||
*/ | ||
public final class DropViewStatementBinder implements SQLStatementBinder<DropViewStatement> { | ||
|
||
@Override | ||
public DropViewStatement bind(final DropViewStatement sqlStatement, final SQLStatementBinderContext binderContext) { | ||
DropViewStatement result = copy(sqlStatement); | ||
Multimap<CaseInsensitiveString, TableSegmentBinderContext> tableBinderContexts = LinkedHashMultimap.create(); | ||
sqlStatement.getViews().forEach(each -> result.getViews().add(SimpleTableSegmentBinder.bind(each, binderContext, tableBinderContexts))); | ||
return result; | ||
} | ||
|
||
@SneakyThrows(ReflectiveOperationException.class) | ||
private static DropViewStatement copy(final DropViewStatement sqlStatement) { | ||
DropViewStatement result = sqlStatement.getClass().getDeclaredConstructor().newInstance(); | ||
result.addParameterMarkerSegments(sqlStatement.getParameterMarkerSegments()); | ||
result.getCommentSegments().addAll(sqlStatement.getCommentSegments()); | ||
result.getVariableNames().addAll(sqlStatement.getVariableNames()); | ||
return result; | ||
} | ||
} |
Oops, something went wrong.