You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by du...@apache.org on 2021/09/27 08:02:43 UTC
[shardingsphere] branch master updated: Refactor
SELECT_SQL_BY_ID_ACROSS_SINGLE_AND_SHARDING_TABLES_REWRITE statement with
shardingsphere-integration-test (#12769)
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 b1fe639 Refactor SELECT_SQL_BY_ID_ACROSS_SINGLE_AND_SHARDING_TABLES_REWRITE statement with shardingsphere-integration-test (#12769)
b1fe639 is described below
commit b1fe6396651e0ce09f2227be666c0b8ebf10531e
Author: liguoping <xd...@163.com>
AuthorDate: Mon Sep 27 16:01:48 2021 +0800
Refactor SELECT_SQL_BY_ID_ACROSS_SINGLE_AND_SHARDING_TABLES_REWRITE statement with shardingsphere-integration-test (#12769)
* add dql-integration-test-cases.xml
* remove SELECT_SQL_BY_ID_ACROSS_SINGLE_AND_SHARDING_TABLES_REWRITE
---
.../statement/FederatePrepareStatementTest.java | 44 +---------------------
.../core/statement/FederationStatementTest.java | 37 +-----------------
...d_across_single_and_sharding_tables_rewrite.xml | 31 +++++++++++++++
...d_across_single_and_sharding_tables_rewrite.xml | 31 +++++++++++++++
...d_across_single_and_sharding_tables_rewrite.xml | 31 +++++++++++++++
.../cases/dql/dql-integration-test-cases.xml | 4 ++
6 files changed, 99 insertions(+), 79 deletions(-)
diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/statement/FederatePrepareStatementTest.java b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/statement/FederatePrepareStatementTest.java
index aeaebf1..8bd41c9 100644
--- a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/statement/FederatePrepareStatementTest.java
+++ b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/statement/FederatePrepareStatementTest.java
@@ -34,14 +34,7 @@ public final class FederatePrepareStatementTest extends AbstractShardingSphereDa
private static final String SELECT_SQL_BY_ID_ACROSS_SINGLE_AND_SHARDING_TABLES_ALIAS =
"select o.*, i.* from t_order_federate o, t_order_item_federate_sharding i "
+ "where o.order_id = i.item_id AND i.order_id = ?";
-
- private static final String SELECT_SQL_BY_ID_ACROSS_SINGLE_AND_SHARDING_TABLES_REWRITE =
- "select t_order_federate.*, t_order_item_federate_sharding.* "
- + "from t_order_federate, t_order_item_federate_sharding "
- + "where t_order_federate.order_id = t_order_item_federate_sharding.item_id "
- + "AND t_order_item_federate_sharding.remarks = 't_order_item_federate_sharding' "
- + "AND t_order_item_federate_sharding.user_id = ?";
-
+
@Test
public void assertQueryWithFederateInSingleAndShardingTableWithAliasByExecuteQuery() throws SQLException {
assertQueryWithFederateInSingleAndShardingTableWithAlias(true);
@@ -66,39 +59,4 @@ public final class FederatePrepareStatementTest extends AbstractShardingSphereDa
assertThat(resultSet.getInt(5), is(10001));
assertFalse(resultSet.next());
}
-
- @Test
- public void assertQueryWithFederateInSingleAndShardingTableRewriteByExecuteQuery() throws SQLException {
- assertQueryWithFederateInSingleAndShardingTableRewrite(true);
- }
-
- @Test
- public void assertQueryWithFederateInSingleAndShardingTableRewriteByExecute() throws SQLException {
- assertQueryWithFederateInSingleAndShardingTableRewrite(false);
- }
-
- private void assertQueryWithFederateInSingleAndShardingTableRewrite(final boolean executeQuery) throws SQLException {
- ShardingSpherePreparedStatement preparedStatement = (ShardingSpherePreparedStatement) getShardingSphereDataSource()
- .getConnection().prepareStatement(SELECT_SQL_BY_ID_ACROSS_SINGLE_AND_SHARDING_TABLES_REWRITE);
- preparedStatement.setInt(1, 11);
- ResultSet resultSet = getResultSet(preparedStatement, executeQuery);
- assertNotNull(resultSet);
- assertTrue(resultSet.next());
- assertThat(resultSet.getInt(1), is(1001));
- assertThat(resultSet.getInt(2), is(11));
- assertThat(resultSet.getString(3), is("init"));
- assertThat(resultSet.getInt(4), is(1001));
- assertThat(resultSet.getInt(5), is(10001));
- assertFalse(resultSet.next());
- preparedStatement.setInt(1, 10);
- ResultSet resultSet1 = getResultSet(preparedStatement, executeQuery);
- assertNotNull(resultSet1);
- assertTrue(resultSet1.next());
- assertThat(resultSet1.getInt(1), is(1000));
- assertThat(resultSet1.getInt(2), is(10));
- assertThat(resultSet1.getString(3), is("init"));
- assertThat(resultSet1.getInt(4), is(1000));
- assertThat(resultSet1.getInt(5), is(10000));
- assertFalse(resultSet1.next());
- }
}
diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/statement/FederationStatementTest.java b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/statement/FederationStatementTest.java
index b47a57d..5e4022e 100644
--- a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/statement/FederationStatementTest.java
+++ b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/statement/FederationStatementTest.java
@@ -33,13 +33,7 @@ public final class FederationStatementTest extends AbstractShardingSphereDataSou
private static final String SELECT_SQL_BY_ID_ACROSS_SINGLE_AND_SHARDING_TABLES_ALIAS = "select o.*, i.* from"
+ " t_order_federate o, t_order_item_federate_sharding i where o.order_id = i.item_id";
-
- private static final String SELECT_SQL_BY_ID_ACROSS_SINGLE_AND_SHARDING_TABLES_REWRITE =
- "select t_order_federate.*, t_order_item_federate_sharding.* from "
- + "t_order_federate, t_order_item_federate_sharding "
- + "where t_order_federate.order_id = t_order_item_federate_sharding.item_id "
- + "AND t_order_item_federate_sharding.remarks = 't_order_item_federate_sharding'";
-
+
@Test
public void assertQueryWithFederateInSingleAndShardingTableWithAliasByExecuteQuery() throws SQLException {
assertQueryWithFederationInSingleAndShardingTableWithAlias(true);
@@ -68,33 +62,4 @@ public final class FederationStatementTest extends AbstractShardingSphereDataSou
assertThat(resultSet.getInt(5), is(10001));
assertFalse(resultSet.next());
}
-
- @Test
- public void assertQueryWithFederationInSingleAndShardingTableRewriteByExecuteQuery() throws SQLException {
- assertQueryWithFederationInSingleAndShardingTableRewrite(true);
- }
-
- @Test
- public void assertQueryWithFederationInSingleAndShardingTableRewriteByExecute() throws SQLException {
- assertQueryWithFederationInSingleAndShardingTableRewrite(false);
- }
-
- private void assertQueryWithFederationInSingleAndShardingTableRewrite(final boolean executeQuery) throws SQLException {
- ShardingSphereStatement statement = (ShardingSphereStatement) getShardingSphereDataSource().getConnection().createStatement();
- ResultSet resultSet = getResultSet(statement, SELECT_SQL_BY_ID_ACROSS_SINGLE_AND_SHARDING_TABLES_REWRITE, executeQuery);
- assertNotNull(resultSet);
- assertTrue(resultSet.next());
- assertThat(resultSet.getInt(1), is(1000));
- assertThat(resultSet.getInt(2), is(10));
- assertThat(resultSet.getString(3), is("init"));
- assertThat(resultSet.getInt(4), is(1000));
- assertThat(resultSet.getInt(5), is(10000));
- assertTrue(resultSet.next());
- assertThat(resultSet.getInt(1), is(1001));
- assertThat(resultSet.getInt(2), is(11));
- assertThat(resultSet.getString(3), is("init"));
- assertThat(resultSet.getInt(4), is(1001));
- assertThat(resultSet.getInt(5), is(10001));
- assertFalse(resultSet.next());
- }
}
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/cases/dql/dataset/db/select_sql_by_id_across_single_and_sharding_tables_rewrite.xml b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/cases/dql/dataset/db/select_sql_by_id_across_single_and_sharding_tables_rewrite.xml
new file mode 100644
index 0000000..a8d1fb5
--- /dev/null
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/cases/dql/dataset/db/select_sql_by_id_across_single_and_sharding_tables_rewrite.xml
@@ -0,0 +1,31 @@
+<!--
+ ~ 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.
+ -->
+
+<dataset>
+ <metadata>
+ <column name="order_id" />
+ <column name="user_id" />
+ <column name="status" />
+ <column name="item_id" />
+ <column name="order_id0"/>
+ <column name="user_id0"/>
+ <column name="status0" />
+ <column name="remarks" />
+ </metadata>
+ <row values="1000, 10, init, 1000, 10000, 10, init, t_order_item_federate_sharding" />
+ <row values="1001, 11, init, 1001, 10001, 11, init, t_order_item_federate_sharding " />
+</dataset>
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/cases/dql/dataset/dbtbl_with_readwrite_splitting/select_sql_by_id_across_single_and_sharding_tables_rewrite.xml b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/cases/dql/dataset/dbtbl_with_readwrite_splitting/select_sql_by_id_across_single_and_sharding_tables_rewrite.xml
new file mode 100644
index 0000000..a8d1fb5
--- /dev/null
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/cases/dql/dataset/dbtbl_with_readwrite_splitting/select_sql_by_id_across_single_and_sharding_tables_rewrite.xml
@@ -0,0 +1,31 @@
+<!--
+ ~ 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.
+ -->
+
+<dataset>
+ <metadata>
+ <column name="order_id" />
+ <column name="user_id" />
+ <column name="status" />
+ <column name="item_id" />
+ <column name="order_id0"/>
+ <column name="user_id0"/>
+ <column name="status0" />
+ <column name="remarks" />
+ </metadata>
+ <row values="1000, 10, init, 1000, 10000, 10, init, t_order_item_federate_sharding" />
+ <row values="1001, 11, init, 1001, 10001, 11, init, t_order_item_federate_sharding " />
+</dataset>
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/cases/dql/dataset/dbtbl_with_readwrite_splitting_and_encrypt/select_sql_by_id_across_single_and_sharding_tables_rewrite.xml b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/cases/dql/dataset/dbtbl_with_readwrite_splitting_and_encrypt/select_sql_by_id_across_single_and_sharding_tables_rewrite.xml
new file mode 100644
index 0000000..a8d1fb5
--- /dev/null
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/cases/dql/dataset/dbtbl_with_readwrite_splitting_and_encrypt/select_sql_by_id_across_single_and_sharding_tables_rewrite.xml
@@ -0,0 +1,31 @@
+<!--
+ ~ 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.
+ -->
+
+<dataset>
+ <metadata>
+ <column name="order_id" />
+ <column name="user_id" />
+ <column name="status" />
+ <column name="item_id" />
+ <column name="order_id0"/>
+ <column name="user_id0"/>
+ <column name="status0" />
+ <column name="remarks" />
+ </metadata>
+ <row values="1000, 10, init, 1000, 10000, 10, init, t_order_item_federate_sharding" />
+ <row values="1001, 11, init, 1001, 10001, 11, init, t_order_item_federate_sharding " />
+</dataset>
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/cases/dql/dql-integration-test-cases.xml b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/cases/dql/dql-integration-test-cases.xml
index 5195dd2..1bd748c 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/cases/dql/dql-integration-test-cases.xml
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/cases/dql/dql-integration-test-cases.xml
@@ -608,4 +608,8 @@
<assertion expected-data-file="select_with_data_type_across_single_and_sharding_tables.xml"/>
</test-case>
+ <test-case sql="select t_order_federate.*, t_order_item_federate_sharding.* from t_order_federate, t_order_item_federate_sharding where t_order_federate.order_id = t_order_item_federate_sharding.item_id AND t_order_item_federate_sharding.remarks = 't_order_item_federate_sharding' " scenario-types="db,dbtbl_with_readwrite_splitting,dbtbl_with_readwrite_splitting_and_encrypt">
+ <assertion expected-data-file="select_sql_by_id_across_single_and_sharding_tables_rewrite.xml"/>
+ </test-case>
+
</integration-test-cases>