This is an automated email from the ASF dual-hosted git repository.
zhangliang 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 3b6f06c7257 Refactor ScenarioDataPath.findActualDatabaseInitSQLFile()
(#36768)
3b6f06c7257 is described below
commit 3b6f06c72577ef371c9f0bac6f05c0ccff748c41
Author: Liang Zhang <[email protected]>
AuthorDate: Wed Oct 1 09:01:49 2025 +0800
Refactor ScenarioDataPath.findActualDatabaseInitSQLFile() (#36768)
---
.../type/scenario/path/ScenarioDataPath.java | 22 ++++++++---------
.../test/e2e/sql/env/SQLE2EEnvironmentEngine.java | 2 +-
.../init-sql/mysql/targets-logic_db-init.sql | 28 ++++++++++++++++++++++
.../init-sql/opengauss/targets-logic_db-init.sql | 28 ++++++++++++++++++++++
.../init-sql/postgresql/targets-logic_db-init.sql | 28 ++++++++++++++++++++++
5 files changed, 96 insertions(+), 12 deletions(-)
diff --git
a/test/e2e/env/src/test/java/org/apache/shardingsphere/test/e2e/env/runtime/type/scenario/path/ScenarioDataPath.java
b/test/e2e/env/src/test/java/org/apache/shardingsphere/test/e2e/env/runtime/type/scenario/path/ScenarioDataPath.java
index 6255fc2fbdc..eda6346b1be 100644
---
a/test/e2e/env/src/test/java/org/apache/shardingsphere/test/e2e/env/runtime/type/scenario/path/ScenarioDataPath.java
+++
b/test/e2e/env/src/test/java/org/apache/shardingsphere/test/e2e/env/runtime/type/scenario/path/ScenarioDataPath.java
@@ -69,28 +69,28 @@ public final class ScenarioDataPath {
}
/**
- * Find actual init SQL file by database name.
+ * Find target init SQL file by database name.
*
* @param databaseName database name
* @param databaseType database type
- * @return actual init SQL file
+ * @return target init SQL file
*/
- public Optional<String> findActualDatabaseInitSQLFile(final String
databaseName, final DatabaseType databaseType) {
- return isActualDatabaseInitSQLFileExisted(databaseName, databaseType)
? Optional.of(getActualDatabaseInitSQLFile(databaseName, databaseType)) :
Optional.empty();
+ public Optional<String> findTargetDatabaseInitSQLFile(final String
databaseName, final DatabaseType databaseType) {
+ return isTargetDatabaseInitSQLFileExisted(databaseName, databaseType)
? Optional.of(getTargetDatabaseInitSQLFile(databaseName, databaseType)) :
Optional.empty();
}
- private boolean isActualDatabaseInitSQLFileExisted(final String
databaseName, final DatabaseType databaseType) {
- String initSQLResourceFile =
getActualDatabaseInitSQLResourceFile(databaseName, databaseType);
+ private boolean isTargetDatabaseInitSQLFileExisted(final String
databaseName, final DatabaseType databaseType) {
+ String initSQLResourceFile =
getTargetDatabaseInitSQLResourceFile(databaseName, databaseType);
return null !=
Thread.currentThread().getContextClassLoader().getResource(initSQLResourceFile);
}
- private String getActualDatabaseInitSQLResourceFile(final String
databaseName, final DatabaseType databaseType) {
- String initSQLFileName = String.join("-",
Type.ACTUAL.name().toLowerCase(), databaseName, BASIC_INIT_SQL_FILE);
+ private String getTargetDatabaseInitSQLResourceFile(final String
databaseName, final DatabaseType databaseType) {
+ String initSQLFileName = String.join("-",
Type.TARGETS.name().toLowerCase(), databaseName, BASIC_INIT_SQL_FILE);
return String.join("/", getInitSQLResourcePath(databaseType),
initSQLFileName);
}
- private String getActualDatabaseInitSQLFile(final String databaseName,
final DatabaseType databaseType) {
- String resourceFile =
getActualDatabaseInitSQLResourceFile(databaseName, databaseType);
+ private String getTargetDatabaseInitSQLFile(final String databaseName,
final DatabaseType databaseType) {
+ String resourceFile =
getTargetDatabaseInitSQLResourceFile(databaseName, databaseType);
URL url =
Thread.currentThread().getContextClassLoader().getResource(resourceFile);
assertNotNull(url, String.format("File `%s` must exist.",
resourceFile));
return url.getFile();
@@ -110,6 +110,6 @@ public final class ScenarioDataPath {
* Data type.
*/
public enum Type {
- ACTUAL, EXPECTED
+ ACTUAL, EXPECTED, TARGETS
}
}
diff --git
a/test/e2e/sql/src/test/java/org/apache/shardingsphere/test/e2e/sql/env/SQLE2EEnvironmentEngine.java
b/test/e2e/sql/src/test/java/org/apache/shardingsphere/test/e2e/sql/env/SQLE2EEnvironmentEngine.java
index 133d15a6f8b..3262e4d2f2d 100644
---
a/test/e2e/sql/src/test/java/org/apache/shardingsphere/test/e2e/sql/env/SQLE2EEnvironmentEngine.java
+++
b/test/e2e/sql/src/test/java/org/apache/shardingsphere/test/e2e/sql/env/SQLE2EEnvironmentEngine.java
@@ -64,7 +64,7 @@ public final class SQLE2EEnvironmentEngine {
}
private void executeLogicDatabaseInitSQLFileOnlyOnce(final String key,
final String scenario, final DatabaseType databaseType) {
- Optional<String> logicDatabaseInitSQLFile = new
ScenarioDataPath(scenario,
Type.ACTUAL).findActualDatabaseInitSQLFile(DefaultDatabase.LOGIC_NAME,
databaseType);
+ Optional<String> logicDatabaseInitSQLFile = new
ScenarioDataPath(scenario,
Type.TARGETS).findTargetDatabaseInitSQLFile(DefaultDatabase.LOGIC_NAME,
databaseType);
if (!logicDatabaseInitSQLFile.isPresent()) {
return;
}
diff --git
a/test/e2e/sql/src/test/resources/env/scenario/db_tbl_sql_federation/data/targets/init-sql/mysql/targets-logic_db-init.sql
b/test/e2e/sql/src/test/resources/env/scenario/db_tbl_sql_federation/data/targets/init-sql/mysql/targets-logic_db-init.sql
new file mode 100644
index 00000000000..4c829182ad6
--- /dev/null
+++
b/test/e2e/sql/src/test/resources/env/scenario/db_tbl_sql_federation/data/targets/init-sql/mysql/targets-logic_db-init.sql
@@ -0,0 +1,28 @@
+--
+-- 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.
+--
+
+-- TODO open this comment when refresh metadata support view without push down
execute
+-- DROP VIEW IF EXISTS t_order_item_join_view;
+-- DROP VIEW IF EXISTS t_order_subquery_view;
+-- DROP VIEW IF EXISTS t_order_aggregation_view;
+-- DROP VIEW IF EXISTS t_order_union_view;
+
+-- CREATE VIEW t_order_item_join_view AS SELECT o.order_id, o.user_id,
i.item_id FROM t_order o INNER JOIN t_order_item i ON o.order_id = i.order_id
ORDER BY o.order_id, i.item_id;
+-- CREATE VIEW t_order_subquery_view AS SELECT * FROM t_order o WHERE
o.order_id IN (SELECT i.order_id FROM t_order_item i INNER JOIN t_product p ON
i.product_id = p.product_id WHERE p.product_id = 10);
+-- CREATE VIEW t_order_aggregation_view AS SELECT MAX(p.price) AS max_price,
MIN(p.price) AS min_price, SUM(p.price) AS sum_price, AVG(p.price) AS
avg_price, COUNT(1) AS count FROM t_order o INNER JOIN t_order_item i ON
o.order_id = i.order_id INNER JOIN t_product p ON i.product_id = p.product_id
GROUP BY o.order_id HAVING SUM(p.price) > 10000 ORDER BY max_price;
+-- CREATE VIEW t_order_union_view AS SELECT * FROM t_order WHERE order_id >
2000 UNION SELECT * FROM t_order WHERE order_id > 1500;
+DELETE FROM t_order WHERE order_id = 99999999;
diff --git
a/test/e2e/sql/src/test/resources/env/scenario/db_tbl_sql_federation/data/targets/init-sql/opengauss/targets-logic_db-init.sql
b/test/e2e/sql/src/test/resources/env/scenario/db_tbl_sql_federation/data/targets/init-sql/opengauss/targets-logic_db-init.sql
new file mode 100644
index 00000000000..4c829182ad6
--- /dev/null
+++
b/test/e2e/sql/src/test/resources/env/scenario/db_tbl_sql_federation/data/targets/init-sql/opengauss/targets-logic_db-init.sql
@@ -0,0 +1,28 @@
+--
+-- 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.
+--
+
+-- TODO open this comment when refresh metadata support view without push down
execute
+-- DROP VIEW IF EXISTS t_order_item_join_view;
+-- DROP VIEW IF EXISTS t_order_subquery_view;
+-- DROP VIEW IF EXISTS t_order_aggregation_view;
+-- DROP VIEW IF EXISTS t_order_union_view;
+
+-- CREATE VIEW t_order_item_join_view AS SELECT o.order_id, o.user_id,
i.item_id FROM t_order o INNER JOIN t_order_item i ON o.order_id = i.order_id
ORDER BY o.order_id, i.item_id;
+-- CREATE VIEW t_order_subquery_view AS SELECT * FROM t_order o WHERE
o.order_id IN (SELECT i.order_id FROM t_order_item i INNER JOIN t_product p ON
i.product_id = p.product_id WHERE p.product_id = 10);
+-- CREATE VIEW t_order_aggregation_view AS SELECT MAX(p.price) AS max_price,
MIN(p.price) AS min_price, SUM(p.price) AS sum_price, AVG(p.price) AS
avg_price, COUNT(1) AS count FROM t_order o INNER JOIN t_order_item i ON
o.order_id = i.order_id INNER JOIN t_product p ON i.product_id = p.product_id
GROUP BY o.order_id HAVING SUM(p.price) > 10000 ORDER BY max_price;
+-- CREATE VIEW t_order_union_view AS SELECT * FROM t_order WHERE order_id >
2000 UNION SELECT * FROM t_order WHERE order_id > 1500;
+DELETE FROM t_order WHERE order_id = 99999999;
diff --git
a/test/e2e/sql/src/test/resources/env/scenario/db_tbl_sql_federation/data/targets/init-sql/postgresql/targets-logic_db-init.sql
b/test/e2e/sql/src/test/resources/env/scenario/db_tbl_sql_federation/data/targets/init-sql/postgresql/targets-logic_db-init.sql
new file mode 100644
index 00000000000..4c829182ad6
--- /dev/null
+++
b/test/e2e/sql/src/test/resources/env/scenario/db_tbl_sql_federation/data/targets/init-sql/postgresql/targets-logic_db-init.sql
@@ -0,0 +1,28 @@
+--
+-- 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.
+--
+
+-- TODO open this comment when refresh metadata support view without push down
execute
+-- DROP VIEW IF EXISTS t_order_item_join_view;
+-- DROP VIEW IF EXISTS t_order_subquery_view;
+-- DROP VIEW IF EXISTS t_order_aggregation_view;
+-- DROP VIEW IF EXISTS t_order_union_view;
+
+-- CREATE VIEW t_order_item_join_view AS SELECT o.order_id, o.user_id,
i.item_id FROM t_order o INNER JOIN t_order_item i ON o.order_id = i.order_id
ORDER BY o.order_id, i.item_id;
+-- CREATE VIEW t_order_subquery_view AS SELECT * FROM t_order o WHERE
o.order_id IN (SELECT i.order_id FROM t_order_item i INNER JOIN t_product p ON
i.product_id = p.product_id WHERE p.product_id = 10);
+-- CREATE VIEW t_order_aggregation_view AS SELECT MAX(p.price) AS max_price,
MIN(p.price) AS min_price, SUM(p.price) AS sum_price, AVG(p.price) AS
avg_price, COUNT(1) AS count FROM t_order o INNER JOIN t_order_item i ON
o.order_id = i.order_id INNER JOIN t_product p ON i.product_id = p.product_id
GROUP BY o.order_id HAVING SUM(p.price) > 10000 ORDER BY max_price;
+-- CREATE VIEW t_order_union_view AS SELECT * FROM t_order WHERE order_id >
2000 UNION SELECT * FROM t_order WHERE order_id > 1500;
+DELETE FROM t_order WHERE order_id = 99999999;