This is an automated email from the ASF dual-hosted git repository.
duanzhengqiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new fe79fc6 Issue 11386 2 (#11535)
fe79fc6 is described below
commit fe79fc6e4db4b87f6655507c6adf03c3332250a9
Author: tuichenchuxin <[email protected]>
AuthorDate: Fri Jul 30 09:34:37 2021 +0800
Issue 11386 2 (#11535)
* union mysql route
* union mysql route one data node support
* union mysql route one data node support
* union mysql route one data node support
* union mysql route one data node support
* union mysql route one data node support
* union mysql route one data node support
---
.../engine/validator/dml/impl/ShardingSelectStatementValidator.java | 4 ++++
.../sql/parser/sql/common/extractor/TableExtractor.java | 3 +++
.../scenario/ShardingSQLRewriterParameterizedTest.java | 1 +
.../src/test/resources/scenario/sharding/case/select.xml | 6 +++++-
4 files changed, 13 insertions(+), 1 deletion(-)
diff --git
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/dml/impl/ShardingSelectStatementValidator.java
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/dml/impl/ShardingSelectStatementValidator.java
index 44e0ec4..698654d 100644
---
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/dml/impl/ShardingSelectStatementValidator.java
+++
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/dml/impl/ShardingSelectStatementValidator.java
@@ -19,6 +19,7 @@ package
org.apache.shardingsphere.sharding.route.engine.validator.dml.impl;
import com.google.common.base.Preconditions;
import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext;
+import org.apache.shardingsphere.infra.exception.ShardingSphereException;
import org.apache.shardingsphere.infra.metadata.schema.ShardingSphereSchema;
import org.apache.shardingsphere.infra.route.context.RouteContext;
import
org.apache.shardingsphere.sharding.route.engine.validator.dml.ShardingDMLStatementValidator;
@@ -40,6 +41,9 @@ public final class ShardingSelectStatementValidator extends
ShardingDMLStatement
if (isNeedMergeShardingValues(sqlStatementContext, shardingRule)) {
needCheckDatabaseInstance =
checkSubqueryShardingValues(shardingRule, sqlStatementContext, parameters,
schema);
}
+ if
(!sqlStatementContext.getSqlStatement().getUnionSegments().isEmpty() &&
!shardingRule.getShardingBroadcastTableNames(sqlStatementContext.getTablesContext().getTableNames()).isEmpty())
{
+ throw new ShardingSphereException("SELECT ... UNION statement can
not support sharding tables or broadcast tables.");
+ }
}
@Override
diff --git
a/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/extractor/TableExtractor.java
b/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/extractor/TableExtractor.java
index cecdcca..54ad8be 100644
---
a/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/extractor/TableExtractor.java
+++
b/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/extractor/TableExtractor.java
@@ -87,6 +87,9 @@ public final class TableExtractor {
if
(SelectStatementHandler.getLockSegment(selectStatement).isPresent()) {
extractTablesFromLock(SelectStatementHandler.getLockSegment(selectStatement).get());
}
+ if (!selectStatement.getUnionSegments().isEmpty()) {
+ selectStatement.getUnionSegments().forEach(each ->
extractTablesFromSelect(each.getSelectStatement()));
+ }
}
/**
diff --git
a/shardingsphere-test/shardingsphere-rewrite-test/src/test/java/org/apache/shardingsphere/sharding/rewrite/parameterized/scenario/ShardingSQLRewriterParameterizedTest.java
b/shardingsphere-test/shardingsphere-rewrite-test/src/test/java/org/apache/shardingsphere/sharding/rewrite/parameterized/scenario/ShardingSQLRewriterParameterizedTest.java
index cf4617c..d06842d 100644
---
a/shardingsphere-test/shardingsphere-rewrite-test/src/test/java/org/apache/shardingsphere/sharding/rewrite/parameterized/scenario/ShardingSQLRewriterParameterizedTest.java
+++
b/shardingsphere-test/shardingsphere-rewrite-test/src/test/java/org/apache/shardingsphere/sharding/rewrite/parameterized/scenario/ShardingSQLRewriterParameterizedTest.java
@@ -130,6 +130,7 @@ public final class ShardingSQLRewriterParameterizedTest
extends AbstractSQLRewri
when(result.get("t_account")).thenReturn(accountTableMetaData);
when(result.get("t_account_detail")).thenReturn(mock(TableMetaData.class));
when(result.getAllColumnNames("t_account")).thenReturn(Arrays.asList("account_id",
"amount", "status"));
+ when(result.containsColumn("t_account",
"account_id")).thenReturn(true);
return result;
}
diff --git
a/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/sharding/case/select.xml
b/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/sharding/case/select.xml
index 86786d3..6884e16 100644
---
a/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/sharding/case/select.xml
+++
b/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/sharding/case/select.xml
@@ -30,7 +30,6 @@
<rewrite-assertion id="select_with_not_exists" db-type="MySQL">
<input sql="SELECT * FROM t_account a WHERE not exists (select * from
t_account_detail where a.account_id=account_id and account_id=1000) and
account_id = 100" />
<output sql="SELECT * FROM t_account_0 a WHERE not exists (select *
from t_account_detail_0 where a.account_id=account_id and account_id=1000) and
account_id = 100" />
- <output sql="SELECT * FROM t_account_1 a WHERE not exists (select *
from t_account_detail_1 where a.account_id=account_id and account_id=1000) and
account_id = 100" />
</rewrite-assertion>
<rewrite-assertion id="select_with_sum_fun">
@@ -477,4 +476,9 @@
<input sql="SELECT * FROM t_account join t_account_detail on
t_account.account_id = t_account_detail.account_id and t_account.account_id in
( ? )" parameters="1"/>
<output sql="SELECT * FROM t_account_1 join t_account_detail_1 on
t_account_1.account_id = t_account_detail_1.account_id and
t_account_1.account_id in ( ? )" parameters="1"/>
</rewrite-assertion>
+
+ <rewrite-assertion id="select_union_single_table" db-type="MySQL">
+ <input sql="SELECT id FROM t_single UNION SELECT id FROM
t_single_extend"/>
+ <output sql="SELECT id FROM t_single UNION SELECT id FROM
t_single_extend"/>
+ </rewrite-assertion>
</rewrite-assertions>