-
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.
Merge branch 'apache:master' into master
- Loading branch information
Showing
12 changed files
with
365 additions
and
0 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
56 changes: 56 additions & 0 deletions
56
...rg/apache/shardingsphere/infra/binder/engine/statement/ddl/AlterIndexStatementBinder.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; | ||
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.AlterIndexStatement; | ||
|
||
/** | ||
* Alter index statement binder. | ||
*/ | ||
public class AlterIndexStatementBinder implements SQLStatementBinder<AlterIndexStatement> { | ||
|
||
@Override | ||
public AlterIndexStatement bind(final AlterIndexStatement sqlStatement, final SQLStatementBinderContext binderContext) { | ||
if (!sqlStatement.getSimpleTable().isPresent()) { | ||
return sqlStatement; | ||
} | ||
AlterIndexStatement result = copy(sqlStatement); | ||
Multimap<CaseInsensitiveMap.CaseInsensitiveString, TableSegmentBinderContext> tableBinderContexts = LinkedHashMultimap.create(); | ||
result.setSimpleTable(SimpleTableSegmentBinder.bind(sqlStatement.getSimpleTable().get(), binderContext, tableBinderContexts)); | ||
return result; | ||
} | ||
|
||
@SneakyThrows(ReflectiveOperationException.class) | ||
private static AlterIndexStatement copy(final AlterIndexStatement sqlStatement) { | ||
AlterIndexStatement result = sqlStatement.getClass().getDeclaredConstructor().newInstance(); | ||
sqlStatement.getIndex().ifPresent(result::setIndex); | ||
sqlStatement.getSimpleTable().ifPresent(result::setSimpleTable); | ||
result.addParameterMarkerSegments(sqlStatement.getParameterMarkerSegments()); | ||
result.getCommentSegments().addAll(sqlStatement.getCommentSegments()); | ||
result.getVariableNames().addAll(sqlStatement.getVariableNames()); | ||
return result; | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
.../org/apache/shardingsphere/infra/binder/engine/statement/ddl/TruncateStatementBinder.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.TruncateStatement; | ||
|
||
/** | ||
* Truncate statement binder. | ||
*/ | ||
public final class TruncateStatementBinder implements SQLStatementBinder<TruncateStatement> { | ||
|
||
@Override | ||
public TruncateStatement bind(final TruncateStatement sqlStatement, final SQLStatementBinderContext binderContext) { | ||
TruncateStatement 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 TruncateStatement copy(final TruncateStatement sqlStatement) { | ||
TruncateStatement result = sqlStatement.getClass().getDeclaredConstructor().newInstance(); | ||
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
25 changes: 25 additions & 0 deletions
25
...ava/org/apache/shardingsphere/test/it/sql/binder/dialect/sqlserver/SQLServerBinderIT.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,25 @@ | ||
/* | ||
* 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.binder.dialect.sqlserver; | ||
|
||
import org.apache.shardingsphere.test.it.sql.binder.SQLBinderIT; | ||
import org.apache.shardingsphere.test.it.sql.binder.SQLBinderITSettings; | ||
|
||
@SQLBinderITSettings("SQLServer") | ||
class SQLServerBinderIT extends SQLBinderIT { | ||
} |
30 changes: 30 additions & 0 deletions
30
test/it/binder/src/test/resources/cases/ddl/alter-index.xml
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,30 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
~ 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. | ||
--> | ||
|
||
<sql-parser-test-cases> | ||
<alter-index sql-case-id="alter_index_with_schema"> | ||
<index name="idx_user_id" start-index="12" stop-index="22"/> | ||
<table name="t_order" start-index="27" stop-index="37"> | ||
<owner name="dbo" start-index="27" stop-index="29"/> | ||
<table-bound> | ||
<original-database name="foo_db_1"/> | ||
<original-schema name="dbo"/> | ||
</table-bound> | ||
</table> | ||
</alter-index> | ||
</sql-parser-test-cases> |
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,93 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
~ 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. | ||
--> | ||
|
||
<sql-parser-test-cases> | ||
<cursor sql-case-id="create_cursor"> | ||
<cursor-name name="t_order_cursor" start-index="7" stop-index="20" /> | ||
<select> | ||
<projections start-index="33" stop-index="33"> | ||
<shorthand-projection start-index="33" stop-index="33"> | ||
<actual-projections> | ||
<column-projection name="order_id" start-index="0" stop-index="0" start-delimiter=""" end-delimiter="""> | ||
<owner name="o" start-index="0" stop-index="0" /> | ||
<column-bound> | ||
<original-database name="foo_db_1" /> | ||
<original-schema name="public" /> | ||
<original-table name="t_order" /> | ||
<original-column name="order_id" start-delimiter=""" end-delimiter=""" /> | ||
</column-bound> | ||
</column-projection> | ||
<column-projection name="user_id" start-index="0" stop-index="0" start-delimiter=""" end-delimiter="""> | ||
<owner name="o" start-index="0" stop-index="0" /> | ||
<column-bound> | ||
<original-database name="foo_db_1" /> | ||
<original-schema name="public" /> | ||
<original-table name="t_order" /> | ||
<original-column name="user_id" start-delimiter=""" end-delimiter=""" /> | ||
</column-bound> | ||
</column-projection> | ||
<column-projection name="status" start-index="0" stop-index="0" start-delimiter=""" end-delimiter="""> | ||
<owner name="o" start-index="0" stop-index="0" /> | ||
<column-bound> | ||
<original-database name="foo_db_1" /> | ||
<original-schema name="public" /> | ||
<original-table name="t_order" /> | ||
<original-column name="status" start-delimiter=""" end-delimiter=""" /> | ||
</column-bound> | ||
</column-projection> | ||
<column-projection name="merchant_id" start-index="0" stop-index="0" start-delimiter=""" end-delimiter="""> | ||
<owner name="o" start-index="0" stop-index="0" /> | ||
<column-bound> | ||
<original-database name="foo_db_1" /> | ||
<original-schema name="public" /> | ||
<original-table name="t_order" /> | ||
<original-column name="merchant_id" start-delimiter=""" end-delimiter=""" /> | ||
</column-bound> | ||
</column-projection> | ||
<column-projection name="remark" start-index="0" stop-index="0" start-delimiter=""" end-delimiter="""> | ||
<owner name="o" start-index="0" stop-index="0" /> | ||
<column-bound> | ||
<original-database name="foo_db_1" /> | ||
<original-schema name="public" /> | ||
<original-table name="t_order" /> | ||
<original-column name="remark" start-delimiter=""" end-delimiter=""" /> | ||
</column-bound> | ||
</column-projection> | ||
<column-projection name="creation_date" start-index="0" stop-index="0" start-delimiter=""" end-delimiter="""> | ||
<owner name="o" start-index="0" stop-index="0" /> | ||
<column-bound> | ||
<original-database name="foo_db_1" /> | ||
<original-schema name="public" /> | ||
<original-table name="t_order" /> | ||
<original-column name="creation_date" start-delimiter=""" end-delimiter=""" /> | ||
</column-bound> | ||
</column-projection> | ||
</actual-projections> | ||
</shorthand-projection> | ||
</projections> | ||
<from> | ||
<simple-table name="t_order" start-index="40" stop-index="48" alias="o"> | ||
<table-bound> | ||
<original-database name="foo_db_1" /> | ||
<original-schema name="public" /> | ||
</table-bound> | ||
</simple-table> | ||
</from> | ||
</select> | ||
</cursor> | ||
</sql-parser-test-cases> |
28 changes: 28 additions & 0 deletions
28
test/it/binder/src/test/resources/cases/ddl/truncate-table.xml
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,28 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
~ 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. | ||
--> | ||
|
||
<sql-parser-test-cases> | ||
<truncate sql-case-id="truncate_table"> | ||
<table name="t_order" start-index="15" stop-index="21"> | ||
<table-bound> | ||
<original-database name="foo_db_1" /> | ||
<original-schema name="foo_db_1" /> | ||
</table-bound> | ||
</table> | ||
</truncate> | ||
</sql-parser-test-cases> |
21 changes: 21 additions & 0 deletions
21
test/it/binder/src/test/resources/sqls/ddl/alter-index.xml
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,21 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
~ 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. | ||
--> | ||
|
||
<sql-cases> | ||
<sql-case id="alter_index_with_schema" value="ALTER INDEX idx_user_id ON dbo.t_order REBUILD" db-types="SQLServer" /> | ||
</sql-cases> |
Oops, something went wrong.