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/08/23 23:56:10 UTC
[shardingsphere] branch master updated: Refactor
SELECT_PARTIAL_DISTINCT_AGGREGATION_SQL_FOR_SHARDING_TABLE statement with
shardingsphere-integration-test (#11950)
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 1975d8a Refactor SELECT_PARTIAL_DISTINCT_AGGREGATION_SQL_FOR_SHARDING_TABLE statement with shardingsphere-integration-test (#11950)
1975d8a is described below
commit 1975d8a1295f322e7d995a731d54251805c0706f
Author: liguoping <xd...@163.com>
AuthorDate: Tue Aug 24 07:55:39 2021 +0800
Refactor SELECT_PARTIAL_DISTINCT_AGGREGATION_SQL_FOR_SHARDING_TABLE statement with shardingsphere-integration-test (#11950)
* Refactor SELECT_PARTIAL_DISTINCT_AGGREGATION_SQL_FOR_SHARDING_TABLE statement with shardingsphere-integration-test
* rename column name
* rename column name secondly
---
.../statement/FederatePrepareStatementTest.java | 25 +--------------------
.../jdbc/core/statement/FederateStatementTest.java | 26 ++--------------------
...distinct_aggregation_sql_for_sharding_table.xml | 24 ++++++++++++++++++++
.../cases/dql/dql-integration-test-cases.xml | 4 ++++
4 files changed, 31 insertions(+), 48 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 bc863fe..1b4c659 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
@@ -60,9 +60,6 @@ public final class FederatePrepareStatementTest extends AbstractShardingSphereDa
private static final String SELECT_SUBQUEY_AGGREGATION_SQL_FOR_SHARDING_TABLE =
"SELECT (SELECT MAX(user_id) FROM t_order_federate_sharding) max_user_id, order_id_sharding, status FROM t_order_federate_sharding WHERE order_id_sharding > ?";
-
- private static final String SELECT_PARTIAL_DISTINCT_AGGREGATION_SQL_FOR_SHARDING_TABLE =
- "SELECT SUM(DISTINCT user_id), SUM(order_id_sharding) FROM t_order_federate_sharding WHERE order_id_sharding > ?";
@Test
public void assertQueryWithFederateInSingleAndShardingTableWithAliasByExecuteQuery() throws SQLException {
@@ -249,25 +246,5 @@ public final class FederatePrepareStatementTest extends AbstractShardingSphereDa
assertThat(resultSet.getString(3), is("init"));
assertNotNull(resultSet);
}
-
- @Test
- public void assertPartialDistinctAggregationForShardingTableWithFederateByExecuteQuery() throws SQLException {
- assertPartialDistinctAggregationForShardingTableWithFederate(true);
- }
-
- @Test
- public void assertPartialDistinctAggregationForShardingTableWithFederateByExecute() throws SQLException {
- assertPartialDistinctAggregationForShardingTableWithFederate(false);
- }
-
- private void assertPartialDistinctAggregationForShardingTableWithFederate(final boolean executeQuery) throws SQLException {
- PreparedStatement preparedStatement = getShardingSphereDataSource().getConnection().prepareStatement(SELECT_PARTIAL_DISTINCT_AGGREGATION_SQL_FOR_SHARDING_TABLE);
- preparedStatement.setInt(1, 1000);
- ResultSet resultSet = getResultSet(preparedStatement, executeQuery);
- assertNotNull(resultSet);
- assertTrue(resultSet.next());
- assertThat(resultSet.getInt(1), is(21));
- assertThat(resultSet.getInt(2), is(4222));
- assertNotNull(resultSet);
- }
+
}
diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/statement/FederateStatementTest.java b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/statement/FederateStatementTest.java
index fc40ffa..f9afb1e 100644
--- a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/statement/FederateStatementTest.java
+++ b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/statement/FederateStatementTest.java
@@ -63,10 +63,7 @@ public final class FederateStatementTest extends AbstractShardingSphereDataSourc
private static final String SELECT_SUBQUEY_AGGREGATION_SQL_FOR_SHARDING_TABLE =
"SELECT (SELECT MAX(user_id) FROM t_order_federate_sharding) max_user_id, order_id_sharding, status FROM t_order_federate_sharding WHERE order_id_sharding > 1100";
-
- private static final String SELECT_PARTIAL_DISTINCT_AGGREGATION_SQL_FOR_SHARDING_TABLE =
- "SELECT SUM(DISTINCT user_id), SUM(order_id_sharding) FROM t_order_federate_sharding WHERE order_id_sharding > 1000";
-
+
@Test
public void assertQueryWithFederateInSingleAndShardingTableWithAliasByExecuteQuery() throws SQLException {
assertQueryWithFederateInSingleAndShardingTableWithAlias(true);
@@ -283,24 +280,5 @@ public final class FederateStatementTest extends AbstractShardingSphereDataSourc
assertThat(resultSet.getString(3), is("init"));
assertNotNull(resultSet);
}
-
- @Test
- public void assertPartialDistinctAggregationForShardingTableWithFederateByExecuteQuery() throws SQLException {
- assertPartialDistinctAggregationForShardingTableWithFederate(true);
- }
-
- @Test
- public void assertPartialDistinctAggregationForShardingTableWithFederateByExecute() throws SQLException {
- assertPartialDistinctAggregationForShardingTableWithFederate(false);
- }
-
- private void assertPartialDistinctAggregationForShardingTableWithFederate(final boolean executeQuery) throws SQLException {
- Statement statement = getShardingSphereDataSource().getConnection().createStatement();
- ResultSet resultSet = getResultSet(statement, SELECT_PARTIAL_DISTINCT_AGGREGATION_SQL_FOR_SHARDING_TABLE, executeQuery);
- assertNotNull(resultSet);
- assertTrue(resultSet.next());
- assertThat(resultSet.getInt(1), is(21));
- assertThat(resultSet.getInt(2), is(4222));
- assertNotNull(resultSet);
- }
+
}
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/cases/dql/dataset/tbl/select_partial_distinct_aggregation_sql_for_sharding_table.xml b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/cases/dql/dataset/tbl/select_partial_distinct_aggregation_sql_for_sharding_table.xml
new file mode 100644
index 0000000..9b99ab1
--- /dev/null
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/cases/dql/dataset/tbl/select_partial_distinct_aggregation_sql_for_sharding_table.xml
@@ -0,0 +1,24 @@
+<!--
+ ~ 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="expr$0" />
+ <column name="expr$1" />
+ </metadata>
+ <row values="21, 4222" />
+</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 b623494..fc16cae 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
@@ -552,4 +552,8 @@
<assertion parameters="10001:int" expected-data-file="select_sql_by_id_across_single_and_sharding_tables_order_id.xml" />
</test-case>
+ <test-case sql="SELECT SUM(DISTINCT user_id), SUM(order_id_sharding) FROM t_order_federate_sharding WHERE order_id_sharding > ?" db-types="MySQL,PostgreSQL" scenario-types="tbl">
+ <assertion parameters="1000:int" expected-data-file="select_partial_distinct_aggregation_sql_for_sharding_table.xml" />
+ </test-case>
+
</integration-test-cases>