-
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 show create table, show columns, show index statement bind
- Loading branch information
1 parent
faae23d
commit 93465fa
Showing
12 changed files
with
419 additions
and
0 deletions.
There are no files selected for viewing
52 changes: 52 additions & 0 deletions
52
...apache/shardingsphere/infra/binder/engine/segment/dal/filter/ShowFilterSegmentBinder.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,52 @@ | ||
/* | ||
* 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.segment.dal.filter; | ||
|
||
import com.cedarsoftware.util.CaseInsensitiveMap.CaseInsensitiveString; | ||
import com.google.common.collect.Multimap; | ||
import lombok.AccessLevel; | ||
import lombok.NoArgsConstructor; | ||
import org.apache.shardingsphere.infra.binder.engine.segment.dml.from.context.TableSegmentBinderContext; | ||
import org.apache.shardingsphere.infra.binder.engine.segment.dml.predicate.WhereSegmentBinder; | ||
import org.apache.shardingsphere.infra.binder.engine.statement.SQLStatementBinderContext; | ||
import org.apache.shardingsphere.sql.parser.statement.core.segment.dal.ShowFilterSegment; | ||
|
||
/** | ||
* Show filter segment binder. | ||
*/ | ||
@NoArgsConstructor(access = AccessLevel.PRIVATE) | ||
public final class ShowFilterSegmentBinder { | ||
|
||
/** | ||
* Bind show filter segment. | ||
* | ||
* @param segment show filter segment | ||
* @param binderContext SQL statement binder context | ||
* @param tableBinderContexts table binder contexts | ||
* @param outerTableBinderContexts outer table binder contexts | ||
* @return bound show filter segment | ||
*/ | ||
public static ShowFilterSegment bind(final ShowFilterSegment segment, final SQLStatementBinderContext binderContext, | ||
final Multimap<CaseInsensitiveString, TableSegmentBinderContext> tableBinderContexts, | ||
final Multimap<CaseInsensitiveString, TableSegmentBinderContext> outerTableBinderContexts) { | ||
ShowFilterSegment result = new ShowFilterSegment(segment.getStartIndex(), segment.getStopIndex()); | ||
segment.getLike().ifPresent(result::setLike); | ||
segment.getWhere().ifPresent(optional -> result.setWhere(WhereSegmentBinder.bind(optional, binderContext, tableBinderContexts, outerTableBinderContexts))); | ||
return result; | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
...g/apache/shardingsphere/infra/binder/engine/statement/dal/ShowColumnsStatementBinder.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.dal; | ||
|
||
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.dal.filter.ShowFilterSegmentBinder; | ||
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.dal.ShowColumnsStatement; | ||
|
||
/** | ||
* Show columns statement binder. | ||
*/ | ||
public final class ShowColumnsStatementBinder implements SQLStatementBinder<ShowColumnsStatement> { | ||
|
||
@Override | ||
public ShowColumnsStatement bind(final ShowColumnsStatement sqlStatement, final SQLStatementBinderContext binderContext) { | ||
ShowColumnsStatement result = copy(sqlStatement); | ||
Multimap<CaseInsensitiveString, TableSegmentBinderContext> tableBinderContexts = LinkedHashMultimap.create(); | ||
result.setTable(SimpleTableSegmentBinder.bind(sqlStatement.getTable(), binderContext, tableBinderContexts)); | ||
sqlStatement.getFromDatabase().ifPresent(result::setFromDatabase); | ||
sqlStatement.getFilter().ifPresent(optional -> result.setFilter(ShowFilterSegmentBinder.bind(optional, binderContext, tableBinderContexts, LinkedHashMultimap.create()))); | ||
return result; | ||
} | ||
|
||
@SneakyThrows(ReflectiveOperationException.class) | ||
private static ShowColumnsStatement copy(final ShowColumnsStatement sqlStatement) { | ||
ShowColumnsStatement result = sqlStatement.getClass().getDeclaredConstructor().newInstance(); | ||
result.addParameterMarkerSegments(sqlStatement.getParameterMarkerSegments()); | ||
result.getCommentSegments().addAll(sqlStatement.getCommentSegments()); | ||
result.getVariableNames().addAll(sqlStatement.getVariableNames()); | ||
return result; | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
...ache/shardingsphere/infra/binder/engine/statement/dal/ShowCreateTableStatementBinder.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.dal; | ||
|
||
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.dal.ShowCreateTableStatement; | ||
|
||
/** | ||
* Show create table statement binder. | ||
*/ | ||
public final class ShowCreateTableStatementBinder implements SQLStatementBinder<ShowCreateTableStatement> { | ||
|
||
@Override | ||
public ShowCreateTableStatement bind(final ShowCreateTableStatement sqlStatement, final SQLStatementBinderContext binderContext) { | ||
ShowCreateTableStatement result = copy(sqlStatement); | ||
Multimap<CaseInsensitiveString, TableSegmentBinderContext> tableBinderContexts = LinkedHashMultimap.create(); | ||
result.setTable(SimpleTableSegmentBinder.bind(sqlStatement.getTable(), binderContext, tableBinderContexts)); | ||
return result; | ||
} | ||
|
||
@SneakyThrows(ReflectiveOperationException.class) | ||
private static ShowCreateTableStatement copy(final ShowCreateTableStatement sqlStatement) { | ||
ShowCreateTableStatement result = sqlStatement.getClass().getDeclaredConstructor().newInstance(); | ||
result.addParameterMarkerSegments(sqlStatement.getParameterMarkerSegments()); | ||
result.getCommentSegments().addAll(sqlStatement.getCommentSegments()); | ||
result.getVariableNames().addAll(sqlStatement.getVariableNames()); | ||
return result; | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
...org/apache/shardingsphere/infra/binder/engine/statement/dal/ShowIndexStatementBinder.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,52 @@ | ||
/* | ||
* 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.dal; | ||
|
||
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.dal.ShowIndexStatement; | ||
|
||
/** | ||
* Show index statement binder. | ||
*/ | ||
public final class ShowIndexStatementBinder implements SQLStatementBinder<ShowIndexStatement> { | ||
|
||
@Override | ||
public ShowIndexStatement bind(final ShowIndexStatement sqlStatement, final SQLStatementBinderContext binderContext) { | ||
ShowIndexStatement result = copy(sqlStatement); | ||
Multimap<CaseInsensitiveString, TableSegmentBinderContext> tableBinderContexts = LinkedHashMultimap.create(); | ||
result.setTable(SimpleTableSegmentBinder.bind(sqlStatement.getTable(), binderContext, tableBinderContexts)); | ||
sqlStatement.getFromDatabase().ifPresent(result::setFromDatabase); | ||
return result; | ||
} | ||
|
||
@SneakyThrows(ReflectiveOperationException.class) | ||
private static ShowIndexStatement copy(final ShowIndexStatement sqlStatement) { | ||
ShowIndexStatement 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
38 changes: 38 additions & 0 deletions
38
test/it/binder/src/test/resources/cases/dal/show-columns.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,38 @@ | ||
<?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> | ||
<show-columns sql-case-id="show_columns_from_table"> | ||
<table name="t_order" start-delimiter="`" end-delimiter="`" start-index="18" stop-index="26"> | ||
<table-bound> | ||
<original-database name="foo_db_1" /> | ||
<original-schema name="foo_db_1" /> | ||
</table-bound> | ||
</table> | ||
</show-columns> | ||
|
||
<show-columns sql-case-id="show_columns_from_table_with_owner"> | ||
<table name="t_product" start-delimiter="`" end-delimiter="`" start-index="18" stop-index="39"> | ||
<owner name="foo_db_2" start-delimiter="`" end-delimiter="`" start-index="18" stop-index="27" /> | ||
<table-bound> | ||
<original-database name="foo_db_2" /> | ||
<original-schema name="foo_db_2" start-delimiter="`" end-delimiter="`" /> | ||
</table-bound> | ||
</table> | ||
</show-columns> | ||
</sql-parser-test-cases> |
38 changes: 38 additions & 0 deletions
38
test/it/binder/src/test/resources/cases/dal/show-create-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,38 @@ | ||
<?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> | ||
<show-create-table sql-case-id="show_create_table"> | ||
<table name="t_order" start-delimiter="`" end-delimiter="`" start-index="18" stop-index="26"> | ||
<table-bound> | ||
<original-database name="foo_db_1" /> | ||
<original-schema name="foo_db_1" /> | ||
</table-bound> | ||
</table> | ||
</show-create-table> | ||
|
||
<show-create-table sql-case-id="show_create_table_with_owner"> | ||
<table name="t_product" start-delimiter="`" end-delimiter="`" start-index="18" stop-index="39"> | ||
<owner name="foo_db_2" start-delimiter="`" end-delimiter="`" start-index="18" stop-index="27" /> | ||
<table-bound> | ||
<original-database name="foo_db_2" /> | ||
<original-schema name="foo_db_2" start-delimiter="`" end-delimiter="`" /> | ||
</table-bound> | ||
</table> | ||
</show-create-table> | ||
</sql-parser-test-cases> |
48 changes: 48 additions & 0 deletions
48
test/it/binder/src/test/resources/cases/dal/show-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,48 @@ | ||
<?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> | ||
<show-index sql-case-id="show_index_with_index_with_table"> | ||
<table name="t_order" start-index="16" stop-index="22"> | ||
<table-bound> | ||
<original-database name="foo_db_1" /> | ||
<original-schema name="foo_db_1" /> | ||
</table-bound> | ||
</table> | ||
</show-index> | ||
|
||
<show-index sql-case-id="show_index_with_indexes_with_table_and_database"> | ||
<table name="t_order" start-index="18" stop-index="24"> | ||
<table-bound> | ||
<original-database name="foo_db_1" /> | ||
<original-schema name="foo_db_1" /> | ||
</table-bound> | ||
</table> | ||
<database name="foo_db_1" start-index="26" stop-index="38" /> | ||
</show-index> | ||
|
||
<show-index sql-case-id="show_index_with_keys_with_database_and_table"> | ||
<table name="t_order" start-index="15" stop-index="30"> | ||
<owner name="foo_db_1" start-index="15" stop-index="22" /> | ||
<table-bound> | ||
<original-database name="foo_db_1" /> | ||
<original-schema name="foo_db_1" /> | ||
</table-bound> | ||
</table> | ||
</show-index> | ||
</sql-parser-test-cases> |
22 changes: 22 additions & 0 deletions
22
test/it/binder/src/test/resources/sqls/dal/show-columns.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,22 @@ | ||
<?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="show_columns_from_table" value="SHOW COLUMNS FROM `t_order`" db-types="MySQL,Doris" /> | ||
<sql-case id="show_columns_from_table_with_owner" value="SHOW COLUMNS FROM `foo_db_2`.`t_product`" db-types="MySQL,Doris" /> | ||
</sql-cases> |
Oops, something went wrong.