From a350788358d683f1dc76150c2994c3f063bcd239 Mon Sep 17 00:00:00 2001 From: linghengqian Date: Fri, 31 May 2024 13:31:32 +0800 Subject: [PATCH] Add GraalVM Reachability Metadata and corresponding nativeTest for Hive --- pom.xml | 23 +++- test/native/pom.xml | 31 +++++ .../jdbc/commons/TestShardingService.java | 82 ++++++++---- .../commons/repository/AddressRepository.java | 41 +++++- .../repository/OrderItemRepository.java | 43 +++--- .../commons/repository/OrderRepository.java | 46 ++++--- .../jdbc/databases/ClickHouseTest.java | 8 +- .../test/natived/jdbc/databases/HiveTest.java | 124 ++++++++++++++++++ .../natived/jdbc/databases/MySQLTest.java | 13 +- .../natived/jdbc/databases/OpenGaussTest.java | 13 +- .../natived/jdbc/databases/PostgresTest.java | 2 +- .../natived/jdbc/features/EncryptTest.java | 2 +- .../test/natived/jdbc/features/MaskTest.java | 2 +- .../jdbc/features/ReadWriteSplittingTest.java | 2 +- .../natived/jdbc/features/ShadowTest.java | 2 +- .../natived/jdbc/features/ShardingTest.java | 2 +- .../natived/jdbc/modes/cluster/EtcdTest.java | 24 +--- .../jdbc/modes/cluster/ZookeeperTest.java | 2 +- .../jdbc/transactions/base/SeataTest.java | 4 +- .../jdbc/transactions/xa/AtomikosTest.java | 2 +- .../jdbc/transactions/xa/NarayanaTest.java | 2 +- .../sql/test-native-databases-hive.sql | 54 ++++++++ .../test-native/yaml/databases/hive.yaml | 72 ++++++++++ 23 files changed, 484 insertions(+), 112 deletions(-) create mode 100644 test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/databases/HiveTest.java create mode 100644 test/native/src/test/resources/test-native/sql/test-native-databases-hive.sql create mode 100644 test/native/src/test/resources/test-native/yaml/databases/hive.yaml diff --git a/pom.xml b/pom.xml index d539451795a734..35741c24ff8806 100644 --- a/pom.xml +++ b/pom.xml @@ -126,6 +126,8 @@ 3.1.0-og 2.4.2 0.6.0-patch5 + 4.0.0 + 3.3.6 4.0.3 @@ -479,6 +481,24 @@ http test + + org.apache.hive + hive-jdbc + ${hive.version} + test + + + org.apache.hive + hive-service + ${hive.version} + test + + + org.apache.hadoop + hadoop-client-runtime + ${hadoop.version} + test + com.zaxxer @@ -970,7 +990,8 @@ maven-surefire-plugin false - --add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.lang.reflect=ALL-UNNAMED + + --add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.lang.reflect=ALL-UNNAMED --add-opens=java.base/java.net=ALL-UNNAMED diff --git a/test/native/pom.xml b/test/native/pom.xml index 1266875230cdda..cd180ca9460f8a 100644 --- a/test/native/pom.xml +++ b/test/native/pom.xml @@ -123,6 +123,12 @@ using Seata Client under GraalVM Native Image requires using the version release ${project.version} test + + org.apache.shardingsphere + shardingsphere-parser-sql-hive + ${project.version} + test + org.awaitility @@ -155,6 +161,31 @@ using Seata Client under GraalVM Native Image requires using the version release http test + + org.apache.hive + hive-jdbc + test + + + org.apache.hive + hive-service + test + + + org.apache.logging.log4j + log4j-slf4j-impl + + + org.slf4j + slf4j-reload4j + + + + + org.apache.hadoop + hadoop-client-runtime + test + org.testcontainers postgresql diff --git a/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/commons/TestShardingService.java b/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/commons/TestShardingService.java index 8e577b480b3f18..53c8bda28fd56f 100644 --- a/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/commons/TestShardingService.java +++ b/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/commons/TestShardingService.java @@ -27,6 +27,7 @@ import javax.sql.DataSource; import java.sql.SQLException; +import java.sql.Statement; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; @@ -38,6 +39,7 @@ import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.notNullValue; import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.greaterThanOrEqualTo; @Getter public final class TestShardingService { @@ -60,7 +62,7 @@ public TestShardingService(final DataSource dataSource) { * @throws SQLException An exception that provides information on a database access error or other errors. */ public void processSuccess() throws SQLException { - final Collection orderIds = insertData(); + final Collection orderIds = insertData(Statement.RETURN_GENERATED_KEYS); Collection orders = orderRepository.selectAll(); assertThat(orders.stream().map(Order::getOrderType).collect(Collectors.toList()), equalTo(Arrays.asList(1, 1, 1, 1, 1, 0, 0, 0, 0, 0))); @@ -89,12 +91,12 @@ public void processSuccess() throws SQLException { /** * Process success in ClickHouse. * ClickHouse has not fully supported transactions. Refer to ClickHouse/clickhouse-docs#2300. - * So ShardingSphere should not use {@code orderItemRepository.assertRollbackWithTransactions()} in the method here. + * So ShardingSphere should not use {@link OrderItemRepository#assertRollbackWithTransactions()} in the method here. * * @throws SQLException An exception that provides information on a database access error or other errors. */ public void processSuccessInClickHouse() throws SQLException { - Collection orderIds = insertDataInClickHouse(); + Collection orderIds = insertData(Statement.NO_GENERATED_KEYS); assertThat(orderIds, notNullValue()); Collection orders = orderRepository.selectAll(); assertThat(orders.stream().map(Order::getOrderType).collect(Collectors.toList()), @@ -121,40 +123,36 @@ public void processSuccessInClickHouse() throws SQLException { } /** - * Insert data. + * Process success in Hive. + * Hive has not fully supported BEGIN, COMMIT, and ROLLBACK. Refer to Hive Transactions. + * So ShardingSphere should not use {@link OrderItemRepository#assertRollbackWithTransactions()} + * TODO It seems that there is no way to force all HiveServer2 insert statements to complete. This results in the following assertion always failing, which needs to be investigated on the apache/hive side. + *
+     * insertDataInHive();
+     * assertThat(addressRepository.selectAll(),
+     *     equalTo(LongStream.range(1L, 11L).mapToObj(each -> new Address(each, "address_test_" + each)).collect(Collectors.toList())));
+     * 
* - * @return orderId of the insert statement. * @throws SQLException An exception that provides information on a database access error or other errors. */ - public Collection insertData() throws SQLException { - Collection result = new ArrayList<>(10); - for (int i = 1; i <= 10; i++) { - Order order = new Order(); - order.setUserId(i); - order.setOrderType(i % 2); - order.setAddressId(i); - order.setStatus("INSERT_TEST"); - orderRepository.insert(order); - OrderItem orderItem = new OrderItem(); - orderItem.setOrderId(order.getOrderId()); - orderItem.setUserId(i); - orderItem.setPhone("13800000001"); - orderItem.setStatus("INSERT_TEST"); - orderItemRepository.insert(orderItem); - Address address = new Address((long) i, "address_test_" + i); - addressRepository.insert(address); - result.add(order.getOrderId()); - } - return result; + public void processSuccessInHive() throws SQLException { + insertDataInHive(); + assertThat(addressRepository.selectAll().size(), greaterThanOrEqualTo(1)); + deleteDataInHive(); + assertThat(addressRepository.selectAll(), equalTo(Collections.emptyList())); } /** - * Insert data in ClickHouse. + * Insert data. * + * @param autoGeneratedKeys a flag indicating whether auto-generated keys + * should be returned; one of + * {@code Statement.RETURN_GENERATED_KEYS} or + * {@code Statement.NO_GENERATED_KEYS} * @return orderId of the insert statement. * @throws SQLException An exception that provides information on a database access error or other errors. */ - public Collection insertDataInClickHouse() throws SQLException { + public Collection insertData(final int autoGeneratedKeys) throws SQLException { Collection result = new ArrayList<>(10); for (int i = 1; i <= 10; i++) { Order order = new Order(); @@ -162,13 +160,13 @@ public Collection insertDataInClickHouse() throws SQLException { order.setOrderType(i % 2); order.setAddressId(i); order.setStatus("INSERT_TEST"); - orderRepository.insertWithoutAutoGeneratedKey(order); + orderRepository.insert(order, autoGeneratedKeys); OrderItem orderItem = new OrderItem(); orderItem.setOrderId(order.getOrderId()); orderItem.setUserId(i); orderItem.setPhone("13800000001"); orderItem.setStatus("INSERT_TEST"); - orderItemRepository.insertWithoutAutoGeneratedKey(orderItem); + orderItemRepository.insert(orderItem, autoGeneratedKeys); Address address = new Address((long) i, "address_test_" + i); addressRepository.insert(address); result.add(order.getOrderId()); @@ -176,6 +174,20 @@ public Collection insertDataInClickHouse() throws SQLException { return result; } + /** + * Insert data in Hive. + */ + public void insertDataInHive() { + LongStream.range(1L, 11L).forEach(action -> { + Address address = new Address(action, "address_test_" + action); + try { + addressRepository.insert(address); + } catch (final SQLException ex) { + throw new RuntimeException(ex); + } + }); + } + /** * Delete data. * @@ -206,6 +218,18 @@ public void deleteDataInClickHouse(final Collection orderIds) throws SQLEx } } + /** + * Delete data in Hive. + * + * @throws SQLException An exception that provides information on a database access error or other errors. + */ + public void deleteDataInHive() throws SQLException { + long count = 1L; + for (int i = 1; i <= 10; i++) { + addressRepository.deleteInHive(count++); + } + } + /** * Clean environment. * diff --git a/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/commons/repository/AddressRepository.java b/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/commons/repository/AddressRepository.java index 1e519f617a7582..ce0712efed868b 100644 --- a/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/commons/repository/AddressRepository.java +++ b/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/commons/repository/AddressRepository.java @@ -38,11 +38,11 @@ public AddressRepository(final DataSource dataSource) { } /** - * create table t_address if not exists. + * create table t_address if not exists in MySQL. * * @throws SQLException SQL exception */ - public void createTableIfNotExists() throws SQLException { + public void createTableIfNotExistsInMySQL() throws SQLException { String sql = "CREATE TABLE IF NOT EXISTS t_address (address_id BIGINT NOT NULL, address_name VARCHAR(100) NOT NULL, PRIMARY KEY (address_id))"; try ( Connection connection = dataSource.getConnection(); @@ -62,7 +62,26 @@ public void createTableInSQLServer() throws SQLException { + " address_id bigint NOT NULL,\n" + " address_name varchar(100) NOT NULL,\n" + " PRIMARY KEY (address_id)\n" - + ");"; + + ")"; + try ( + Connection connection = dataSource.getConnection(); + Statement statement = connection.createStatement()) { + statement.executeUpdate(sql); + } + } + + /** + * create table t_address if not exists in Hive. + * + * @throws SQLException SQL exception + */ + public void createTableIfNotExistsInHive() throws SQLException { + String sql = "CREATE TABLE IF NOT EXISTS t_address\n" + + "(\n" + + " address_id BIGINT NOT NULL,\n" + + " address_name VARCHAR(100) NOT NULL,\n" + + " PRIMARY KEY (address_id) disable novalidate\n" + + ") CLUSTERED BY (address_id) INTO 2 BUCKETS STORED AS ORC TBLPROPERTIES ('transactional'='true')"; try ( Connection connection = dataSource.getConnection(); Statement statement = connection.createStatement()) { @@ -133,6 +152,22 @@ public void delete(final Long id) throws SQLException { } } + /** + * delete by id. + * + * @param id id + * @throws SQLException SQL exception + */ + public void deleteInHive(final Long id) throws SQLException { + String sql = "DELETE FROM t_address WHERE address_id=?"; + try ( + Connection connection = dataSource.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement(sql)) { + preparedStatement.setLong(1, id); + preparedStatement.executeUpdate(); + } + } + /** * delete by id in ClickHouse. * diff --git a/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/commons/repository/OrderItemRepository.java b/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/commons/repository/OrderItemRepository.java index 8979e284eff261..d9b32cbc462284 100644 --- a/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/commons/repository/OrderItemRepository.java +++ b/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/commons/repository/OrderItemRepository.java @@ -52,7 +52,7 @@ public void createTableIfNotExistsInMySQL() throws SQLException { + "user_id INT NOT NULL,\n" + "phone VARCHAR(50),\n" + "status VARCHAR(50),\n" - + "PRIMARY KEY (order_item_id));"; + + "PRIMARY KEY (order_item_id))"; try ( Connection connection = dataSource.getConnection(); Statement statement = connection.createStatement()) { @@ -72,7 +72,7 @@ public void createTableIfNotExistsInPostgres() throws SQLException { + " user_id INTEGER NOT NULL,\n" + " phone VARCHAR(50),\n" + " status VARCHAR(50)\n" - + ");"; + + ")"; try ( Connection connection = dataSource.getConnection(); Statement statement = connection.createStatement()) { @@ -94,7 +94,7 @@ public void createTableInSQLServer() throws SQLException { + " phone varchar(50),\n" + " status varchar(50),\n" + " PRIMARY KEY (order_item_id)\n" - + ");"; + + ")"; try ( Connection connection = dataSource.getConnection(); Statement statement = connection.createStatement()) { @@ -104,6 +104,7 @@ public void createTableInSQLServer() throws SQLException { /** * create table if not exists in ClickHouse. + * ClickHouse does not support `AUTO_INCREMENT`, refer to ClickHouse/ClickHouse#56228 . * * @throws SQLException SQL exception */ @@ -124,6 +125,28 @@ public void createTableIfNotExistsInClickHouse() throws SQLException { } } + /** + * create table if not exists in Hive. + * Hive does not support `AUTO_INCREMENT`, refer to HIVE-6905 . + * + * @throws SQLException SQL exception + */ + public void createTableIfNotExistsInHive() throws SQLException { + String sql = "CREATE TABLE IF NOT EXISTS t_order_item\n" + + "(order_item_id BIGINT,\n" + + " order_id BIGINT NOT NULL,\n" + + " user_id INT NOT NULL,\n" + + " phone VARCHAR(50),\n" + + " status VARCHAR(50),\n" + + " PRIMARY KEY (order_item_id) disable novalidate\n" + + ") CLUSTERED BY (order_item_id) INTO 2 BUCKETS STORED AS ORC TBLPROPERTIES ('transactional'='true')"; + try ( + Connection connection = dataSource.getConnection(); + Statement statement = connection.createStatement()) { + statement.executeUpdate(sql); + } + } + /** * drop table. * @@ -208,7 +231,8 @@ public Long insert(final OrderItem orderItem) throws SQLException { } /** - * insert OrderItem to table. + * insert OrderItem to table. Databases like ClickHouse do not support returning auto generated keys after executing SQL, + * see ClickHouse/ClickHouse#56228 . * * @param orderItem orderItem * @param autoGeneratedKeys a flag indicating whether auto-generated keys @@ -237,17 +261,6 @@ public Long insert(final OrderItem orderItem, final int autoGeneratedKeys) throw return orderItem.getOrderItemId(); } - /** - * insert OrderItem to table without auto generated key. Databases like ClickHouse do not support returning auto generated keys after executing SQL, - * see ClickHouse/ClickHouse#56228 . - * - * @param orderItem orderItem - * @throws SQLException SQL Exception - */ - public void insertWithoutAutoGeneratedKey(final OrderItem orderItem) throws SQLException { - insert(orderItem, Statement.NO_GENERATED_KEYS); - } - /** * delete by orderItemId. * diff --git a/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/commons/repository/OrderRepository.java b/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/commons/repository/OrderRepository.java index 0919940a716618..b595b672190ba4 100644 --- a/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/commons/repository/OrderRepository.java +++ b/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/commons/repository/OrderRepository.java @@ -49,7 +49,7 @@ public void createTableIfNotExistsInMySQL() throws SQLException { + "user_id INT NOT NULL,\n" + "address_id BIGINT NOT NULL,\n" + "status VARCHAR(50),\n" - + "PRIMARY KEY (order_id));"; + + "PRIMARY KEY (order_id))"; try ( Connection connection = dataSource.getConnection(); Statement statement = connection.createStatement()) { @@ -69,7 +69,7 @@ public void createTableIfNotExistsInPostgres() throws SQLException { + " user_id INTEGER NOT NULL,\n" + " address_id BIGINT NOT NULL,\n" + " status VARCHAR(50)\n" - + ");"; + + ")"; try ( Connection connection = dataSource.getConnection(); Statement statement = connection.createStatement()) { @@ -91,7 +91,7 @@ public void createTableInSQLServer() throws SQLException { + " address_id bigint NOT NULL,\n" + " status varchar(50),\n" + " PRIMARY KEY (order_id)\n" - + ");"; + + ")"; try ( Connection connection = dataSource.getConnection(); Statement statement = connection.createStatement()) { @@ -101,6 +101,7 @@ public void createTableInSQLServer() throws SQLException { /** * create table in ClickHouse. + * ClickHouse does not support `AUTO_INCREMENT`, refer to ClickHouse/ClickHouse#56228 . * * @throws SQLException SQL exception */ @@ -113,7 +114,30 @@ public void createTableIfNotExistsInClickHouse() throws SQLException { + "status String\n" + ") engine = MergeTree \n" + "primary key (order_id)\n" - + "order by(order_id); "; + + "order by(order_id)"; + try ( + Connection connection = dataSource.getConnection(); + Statement statement = connection.createStatement()) { + statement.executeUpdate(sql); + } + } + + /** + * create table in Hive. + * Hive does not support `AUTO_INCREMENT`, refer to HIVE-6905 . + * + * @throws SQLException SQL exception + */ + public void createTableIfNotExistsInHive() throws SQLException { + String sql = "CREATE TABLE IF NOT EXISTS t_order\n" + + "(\n" + + " order_id BIGINT,\n" + + " order_type INT,\n" + + " user_id INT NOT NULL,\n" + + " address_id BIGINT NOT NULL,\n" + + " status VARCHAR(50),\n" + + " PRIMARY KEY (order_id) disable novalidate\n" + + ") CLUSTERED BY (order_id) INTO 2 BUCKETS STORED AS ORC TBLPROPERTIES ('transactional'='true')"; try ( Connection connection = dataSource.getConnection(); Statement statement = connection.createStatement()) { @@ -234,7 +258,8 @@ public Long insert(final Order order) throws SQLException { } /** - * insert Order to table. + * insert Order to table. Databases like ClickHouse do not support returning auto generated keys after executing SQL, + * see ClickHouse/ClickHouse#56228 . * * @param order order * @param autoGeneratedKeys a flag indicating whether auto-generated keys @@ -263,17 +288,6 @@ public Long insert(final Order order, final int autoGeneratedKeys) throws SQLExc return order.getOrderId(); } - /** - * insert Order to table without auto generated key. Databases like ClickHouse do not support returning auto generated keys after executing SQL, - * see ClickHouse/ClickHouse#56228 . - * - * @param order order - * @throws SQLException SQL Exception - */ - public void insertWithoutAutoGeneratedKey(final Order order) throws SQLException { - insert(order, Statement.NO_GENERATED_KEYS); - } - /** * delete by orderId. * diff --git a/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/databases/ClickHouseTest.java b/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/databases/ClickHouseTest.java index 0c526f833d94df..6b2d46e673b712 100644 --- a/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/databases/ClickHouseTest.java +++ b/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/databases/ClickHouseTest.java @@ -31,8 +31,8 @@ class ClickHouseTest { private TestShardingService testShardingService; /** - * TODO Need to fix `shardingsphere-parser-sql-clickhouse` module to use `testShardingService.cleanEnvironment()` - * after `testShardingService.processSuccessInClickHouse()`. + * TODO Need to fix `shardingsphere-parser-sql-clickhouse` module to use {@link TestShardingService#cleanEnvironment()} + * after {@link TestShardingService#processSuccessInClickHouse()}. * * @throws SQLException An exception that provides information on a database access error or other errors. */ @@ -49,7 +49,7 @@ void assertShardingInLocalTransactions() throws SQLException { /** * TODO Need to fix `shardingsphere-parser-sql-clickhouse` module to use `initEnvironment()` - * before `testShardingService.processSuccess()`. + * before {@link TestShardingService#processSuccessInClickHouse()}. * * @throws SQLException An exception that provides information on a database access error or other errors. */ @@ -57,7 +57,7 @@ void assertShardingInLocalTransactions() throws SQLException { private void initEnvironment() throws SQLException { testShardingService.getOrderRepository().createTableIfNotExistsInClickHouse(); testShardingService.getOrderItemRepository().createTableIfNotExistsInClickHouse(); - testShardingService.getAddressRepository().createTableIfNotExists(); + testShardingService.getAddressRepository().createTableIfNotExistsInMySQL(); testShardingService.getOrderRepository().truncateTable(); testShardingService.getOrderItemRepository().truncateTable(); testShardingService.getAddressRepository().truncateTable(); diff --git a/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/databases/HiveTest.java b/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/databases/HiveTest.java new file mode 100644 index 00000000000000..b920bb3ac26344 --- /dev/null +++ b/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/databases/HiveTest.java @@ -0,0 +1,124 @@ +/* + * 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.test.natived.jdbc.databases; + +import com.zaxxer.hikari.HikariConfig; +import com.zaxxer.hikari.HikariDataSource; +import org.apache.shardingsphere.test.natived.jdbc.commons.TestShardingService; +import org.awaitility.Awaitility; +import org.junit.jupiter.api.Test; +import org.testcontainers.containers.GenericContainer; +import org.testcontainers.utility.DockerImageName; + +import javax.sql.DataSource; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.SQLException; +import java.sql.Statement; +import java.time.Duration; +import java.util.Objects; +import java.util.Properties; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.nullValue; + +@SuppressWarnings("SqlDialectInspection") +class HiveTest { + + private static final String SYSTEM_PROP_KEY_PREFIX = "fixture.test-native.yaml.database.hive."; + + // Due to https://issues.apache.org/jira/browse/HIVE-5867 , the `initFile` parameter of HiveServer2 JDBC Driver must be an absolute path. + private static final String ABSOLUTE_PATH = Objects.requireNonNull(HiveTest.class.getClassLoader().getResource("test-native/sql/test-native-databases-hive.sql")).getFile(); + + private String jdbcUrlPrefix; + + private TestShardingService testShardingService; + + /** + * TODO Need to fix `shardingsphere-parser-sql-hive` module to use {@link TestShardingService#cleanEnvironment()} + * after {@link TestShardingService#processSuccessInHive()}. + * + * @throws SQLException An exception that provides information on a database access error or other errors. + */ + @Test + void assertShardingInLocalTransactions() throws SQLException { + try (GenericContainer container = new GenericContainer<>(DockerImageName.parse("apache/hive:4.0.0"))) { + container.withEnv("SERVICE_NAME", "hiveserver2") + .withExposedPorts(10000, 10002) + .start(); + jdbcUrlPrefix = "jdbc:hive2://localhost:" + container.getMappedPort(10000) + "/"; + DataSource dataSource = createDataSource(); + testShardingService = new TestShardingService(dataSource); + testShardingService.processSuccessInHive(); + } + } + + /** + * TODO Need to fix `shardingsphere-parser-sql-hive` module to use `initEnvironment()` before {@link TestShardingService#processSuccessInHive()}. + * + * @throws SQLException An exception that provides information on a database access error or other errors. + */ + @SuppressWarnings("unused") + private void initEnvironment() throws SQLException { + testShardingService.getOrderRepository().createTableIfNotExistsInHive(); + testShardingService.getOrderItemRepository().createTableIfNotExistsInHive(); + testShardingService.getAddressRepository().createTableIfNotExistsInHive(); + testShardingService.getOrderRepository().truncateTable(); + testShardingService.getOrderItemRepository().truncateTable(); + testShardingService.getAddressRepository().truncateTable(); + } + + private Connection openConnection() throws SQLException { + Properties props = new Properties(); + return DriverManager.getConnection(jdbcUrlPrefix, props); + } + + private DataSource createDataSource() throws SQLException { + Awaitility.await().atMost(Duration.ofMinutes(1L)).ignoreExceptions().until(() -> { + openConnection().close(); + return true; + }); + try ( + Connection connection = openConnection(); + Statement statement = connection.createStatement()) { + statement.execute("set metastore.compactor.initiator.on=true"); + statement.execute("set metastore.compactor.cleaner.on=true"); + statement.execute("set metastore.compactor.worker.threads=5"); + statement.executeUpdate("CREATE DATABASE demo_ds_0"); + statement.executeUpdate("CREATE DATABASE demo_ds_1"); + statement.executeUpdate("CREATE DATABASE demo_ds_2"); + } + HikariConfig config = new HikariConfig(); + config.setDriverClassName("org.apache.shardingsphere.driver.ShardingSphereDriver"); + config.setJdbcUrl("jdbc:shardingsphere:classpath:test-native/yaml/databases/hive.yaml?placeholder-type=system_props"); + try { + assertThat(System.getProperty(SYSTEM_PROP_KEY_PREFIX + "ds0.jdbc-url"), is(nullValue())); + assertThat(System.getProperty(SYSTEM_PROP_KEY_PREFIX + "ds1.jdbc-url"), is(nullValue())); + assertThat(System.getProperty(SYSTEM_PROP_KEY_PREFIX + "ds2.jdbc-url"), is(nullValue())); + System.setProperty(SYSTEM_PROP_KEY_PREFIX + "ds0.jdbc-url", jdbcUrlPrefix + "demo_ds_0" + ";initFile=" + ABSOLUTE_PATH); + System.setProperty(SYSTEM_PROP_KEY_PREFIX + "ds1.jdbc-url", jdbcUrlPrefix + "demo_ds_1" + ";initFile=" + ABSOLUTE_PATH); + System.setProperty(SYSTEM_PROP_KEY_PREFIX + "ds2.jdbc-url", jdbcUrlPrefix + "demo_ds_2" + ";initFile=" + ABSOLUTE_PATH); + return new HikariDataSource(config); + } finally { + System.clearProperty(SYSTEM_PROP_KEY_PREFIX + "ds0.jdbc-url"); + System.clearProperty(SYSTEM_PROP_KEY_PREFIX + "ds1.jdbc-url"); + System.clearProperty(SYSTEM_PROP_KEY_PREFIX + "ds2.jdbc-url"); + } + } +} diff --git a/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/databases/MySQLTest.java b/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/databases/MySQLTest.java index 7e1a53706d69d7..6737510ceb8fee 100644 --- a/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/databases/MySQLTest.java +++ b/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/databases/MySQLTest.java @@ -31,6 +31,7 @@ import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; +import java.sql.Statement; import java.time.Duration; import java.util.Properties; @@ -78,7 +79,7 @@ void assertShardingInLocalTransactions() throws SQLException { private void initEnvironment() throws SQLException { testShardingService.getOrderRepository().createTableIfNotExistsInMySQL(); testShardingService.getOrderItemRepository().createTableIfNotExistsInMySQL(); - testShardingService.getAddressRepository().createTableIfNotExists(); + testShardingService.getAddressRepository().createTableIfNotExistsInMySQL(); testShardingService.getOrderRepository().truncateTable(); testShardingService.getOrderItemRepository().truncateTable(); testShardingService.getAddressRepository().truncateTable(); @@ -98,10 +99,12 @@ private DataSource createDataSource() { openConnection().close(); return true; }); - try (Connection connection = openConnection()) { - connection.createStatement().executeUpdate("CREATE DATABASE demo_ds_0;"); - connection.createStatement().executeUpdate("CREATE DATABASE demo_ds_1;"); - connection.createStatement().executeUpdate("CREATE DATABASE demo_ds_2;"); + try ( + Connection connection = openConnection(); + Statement statement = connection.createStatement()) { + statement.executeUpdate("CREATE DATABASE demo_ds_0"); + statement.executeUpdate("CREATE DATABASE demo_ds_1"); + statement.executeUpdate("CREATE DATABASE demo_ds_2"); } catch (final SQLException ex) { throw new RuntimeException(ex); } diff --git a/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/databases/OpenGaussTest.java b/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/databases/OpenGaussTest.java index edff542ce3e589..1f68af1efde6e2 100644 --- a/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/databases/OpenGaussTest.java +++ b/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/databases/OpenGaussTest.java @@ -30,6 +30,7 @@ import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; +import java.sql.Statement; import java.time.Duration; import java.util.Properties; @@ -72,7 +73,7 @@ void assertShardingInLocalTransactions() throws SQLException { private void initEnvironment() throws SQLException { testShardingService.getOrderRepository().createTableIfNotExistsInPostgres(); testShardingService.getOrderItemRepository().createTableIfNotExistsInPostgres(); - testShardingService.getAddressRepository().createTableIfNotExists(); + testShardingService.getAddressRepository().createTableIfNotExistsInMySQL(); testShardingService.getOrderRepository().truncateTable(); testShardingService.getOrderItemRepository().truncateTable(); testShardingService.getAddressRepository().truncateTable(); @@ -91,10 +92,12 @@ private DataSource createDataSource() { openConnection().close(); return true; }); - try (Connection connection = openConnection()) { - connection.createStatement().executeUpdate("CREATE DATABASE demo_ds_0;"); - connection.createStatement().executeUpdate("CREATE DATABASE demo_ds_1;"); - connection.createStatement().executeUpdate("CREATE DATABASE demo_ds_2;"); + try ( + Connection connection = openConnection(); + Statement statement = connection.createStatement()) { + statement.executeUpdate("CREATE DATABASE demo_ds_0"); + statement.executeUpdate("CREATE DATABASE demo_ds_1"); + statement.executeUpdate("CREATE DATABASE demo_ds_2"); } catch (final SQLException ex) { throw new RuntimeException(ex); } diff --git a/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/databases/PostgresTest.java b/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/databases/PostgresTest.java index a9852c3ca31dac..f2fd80218fbd08 100644 --- a/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/databases/PostgresTest.java +++ b/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/databases/PostgresTest.java @@ -46,7 +46,7 @@ void assertShardingInLocalTransactions() throws SQLException { private void initEnvironment() throws SQLException { testShardingService.getOrderRepository().createTableIfNotExistsInPostgres(); testShardingService.getOrderItemRepository().createTableIfNotExistsInPostgres(); - testShardingService.getAddressRepository().createTableIfNotExists(); + testShardingService.getAddressRepository().createTableIfNotExistsInMySQL(); testShardingService.getOrderRepository().truncateTable(); testShardingService.getOrderItemRepository().truncateTable(); testShardingService.getAddressRepository().truncateTable(); diff --git a/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/features/EncryptTest.java b/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/features/EncryptTest.java index bd6a2874ce42f1..31565acf931981 100644 --- a/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/features/EncryptTest.java +++ b/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/features/EncryptTest.java @@ -63,7 +63,7 @@ void assertEncryptInLocalTransactions() throws SQLException { private void initEnvironment() throws SQLException { orderRepository.createTableIfNotExistsInMySQL(); orderItemRepository.createTableIfNotExistsInMySQL(); - addressRepository.createTableIfNotExists(); + addressRepository.createTableIfNotExistsInMySQL(); orderRepository.truncateTable(); orderItemRepository.truncateTable(); addressRepository.truncateTable(); diff --git a/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/features/MaskTest.java b/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/features/MaskTest.java index f6fbd6320c48cf..660719488731ca 100644 --- a/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/features/MaskTest.java +++ b/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/features/MaskTest.java @@ -64,7 +64,7 @@ void assertMaskInLocalTransactions() throws SQLException { private void initEnvironment() throws SQLException { orderRepository.createTableIfNotExistsInMySQL(); orderItemRepository.createTableIfNotExistsInMySQL(); - addressRepository.createTableIfNotExists(); + addressRepository.createTableIfNotExistsInMySQL(); orderRepository.truncateTable(); orderItemRepository.truncateTable(); addressRepository.truncateTable(); diff --git a/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/features/ReadWriteSplittingTest.java b/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/features/ReadWriteSplittingTest.java index d2c52b66a6556a..2bb48c20d21a93 100644 --- a/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/features/ReadWriteSplittingTest.java +++ b/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/features/ReadWriteSplittingTest.java @@ -60,7 +60,7 @@ void assertReadWriteSplittingInLocalTransactions() throws SQLException { private void initEnvironment() throws SQLException { orderRepository.createTableIfNotExistsInMySQL(); orderItemRepository.createTableIfNotExistsInMySQL(); - addressRepository.createTableIfNotExists(); + addressRepository.createTableIfNotExistsInMySQL(); orderRepository.truncateTable(); orderItemRepository.truncateTable(); addressRepository.truncateTable(); diff --git a/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/features/ShadowTest.java b/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/features/ShadowTest.java index f195e623f0f00e..c7e29830dccf9e 100644 --- a/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/features/ShadowTest.java +++ b/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/features/ShadowTest.java @@ -64,7 +64,7 @@ void assertShadowInLocalTransactions() throws SQLException { private void initEnvironment() throws SQLException { orderRepository.createTableIfNotExistsInMySQL(); orderItemRepository.createTableIfNotExistsInMySQL(); - addressRepository.createTableIfNotExists(); + addressRepository.createTableIfNotExistsInMySQL(); orderRepository.truncateTable(); orderItemRepository.truncateTable(); addressRepository.truncateTable(); diff --git a/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/features/ShardingTest.java b/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/features/ShardingTest.java index 99d18af28438bf..32efaef02140c7 100644 --- a/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/features/ShardingTest.java +++ b/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/features/ShardingTest.java @@ -44,7 +44,7 @@ void assertShardingInLocalTransactions() throws SQLException { private void initEnvironment() throws SQLException { testShardingService.getOrderRepository().createTableIfNotExistsInMySQL(); testShardingService.getOrderItemRepository().createTableIfNotExistsInMySQL(); - testShardingService.getAddressRepository().createTableIfNotExists(); + testShardingService.getAddressRepository().createTableIfNotExistsInMySQL(); testShardingService.getOrderRepository().truncateTable(); testShardingService.getOrderItemRepository().truncateTable(); testShardingService.getAddressRepository().truncateTable(); diff --git a/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/modes/cluster/EtcdTest.java b/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/modes/cluster/EtcdTest.java index 325047d48ff760..f8ceff784eb38e 100644 --- a/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/modes/cluster/EtcdTest.java +++ b/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/modes/cluster/EtcdTest.java @@ -21,19 +21,12 @@ import com.zaxxer.hikari.HikariDataSource; import io.etcd.jetcd.launcher.Etcd; import io.etcd.jetcd.launcher.EtcdCluster; -import org.apache.hc.client5.http.classic.methods.HttpGet; -import org.apache.hc.client5.http.impl.classic.CloseableHttpClient; -import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse; -import org.apache.hc.client5.http.impl.classic.HttpClients; -import org.apache.hc.core5.http.HttpStatus; -import org.apache.hc.core5.http.io.entity.EntityUtils; import org.apache.shardingsphere.test.natived.jdbc.commons.TestShardingService; import org.awaitility.Awaitility; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.condition.EnabledInNativeImage; import javax.sql.DataSource; -import java.io.IOException; import java.net.URI; import java.sql.SQLException; import java.time.Duration; @@ -80,7 +73,7 @@ void assertShardingInLocalTransactions() throws SQLException { private void initEnvironment() throws SQLException { testShardingService.getOrderRepository().createTableIfNotExistsInMySQL(); testShardingService.getOrderItemRepository().createTableIfNotExistsInMySQL(); - testShardingService.getAddressRepository().createTableIfNotExists(); + testShardingService.getAddressRepository().createTableIfNotExistsInMySQL(); testShardingService.getOrderRepository().truncateTable(); testShardingService.getOrderItemRepository().truncateTable(); testShardingService.getAddressRepository().truncateTable(); @@ -88,7 +81,6 @@ private void initEnvironment() throws SQLException { private DataSource createDataSource(final List clientEndpoints) { URI clientEndpoint = clientEndpoints.get(0); - Awaitility.await().atMost(Duration.ofSeconds(30L)).ignoreExceptions().until(() -> verifyEtcdClusterRunning(clientEndpoint)); HikariConfig config = new HikariConfig(); config.setDriverClassName("org.apache.shardingsphere.driver.ShardingSphereDriver"); config.setJdbcUrl("jdbc:shardingsphere:classpath:test-native/yaml/modes/cluster/etcd.yaml?placeholder-type=system_props"); @@ -100,18 +92,4 @@ private DataSource createDataSource(final List clientEndpoints) { System.clearProperty(SYSTEM_PROP_KEY_PREFIX + "server-lists"); } } - - private Boolean verifyEtcdClusterRunning(final URI clientEndpoint) throws IOException { - boolean flag = false; - HttpGet httpGet = new HttpGet(clientEndpoint.toString() + "/health"); - try ( - CloseableHttpClient httpclient = HttpClients.createDefault(); - CloseableHttpResponse response = httpclient.execute(httpGet)) { - if (HttpStatus.SC_OK == response.getCode()) { - flag = true; - } - EntityUtils.consume(response.getEntity()); - } - return flag; - } } diff --git a/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/modes/cluster/ZookeeperTest.java b/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/modes/cluster/ZookeeperTest.java index 9c9d1d5617cefe..88836303e1a26c 100644 --- a/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/modes/cluster/ZookeeperTest.java +++ b/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/modes/cluster/ZookeeperTest.java @@ -68,7 +68,7 @@ void assertShardingInLocalTransactions() throws Exception { private void initEnvironment() throws SQLException { testShardingService.getOrderRepository().createTableIfNotExistsInMySQL(); testShardingService.getOrderItemRepository().createTableIfNotExistsInMySQL(); - testShardingService.getAddressRepository().createTableIfNotExists(); + testShardingService.getAddressRepository().createTableIfNotExistsInMySQL(); testShardingService.getOrderRepository().truncateTable(); testShardingService.getOrderItemRepository().truncateTable(); testShardingService.getAddressRepository().truncateTable(); diff --git a/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/transactions/base/SeataTest.java b/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/transactions/base/SeataTest.java index b3f0b73301adec..b0b4d4d44ddaa9 100644 --- a/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/transactions/base/SeataTest.java +++ b/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/transactions/base/SeataTest.java @@ -19,7 +19,7 @@ import com.zaxxer.hikari.HikariConfig; import com.zaxxer.hikari.HikariDataSource; -import org.apache.hc.core5.http.HttpStatus; +import org.apache.http.HttpStatus; import org.apache.shardingsphere.test.natived.jdbc.commons.TestShardingService; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.condition.EnabledInNativeImage; @@ -60,7 +60,7 @@ void assertShardingInSeataTransactions() throws SQLException { private void initEnvironment() throws SQLException { testShardingService.getOrderRepository().createTableIfNotExistsInPostgres(); testShardingService.getOrderItemRepository().createTableIfNotExistsInPostgres(); - testShardingService.getAddressRepository().createTableIfNotExists(); + testShardingService.getAddressRepository().createTableIfNotExistsInMySQL(); testShardingService.getOrderRepository().truncateTable(); testShardingService.getOrderItemRepository().truncateTable(); testShardingService.getAddressRepository().truncateTable(); diff --git a/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/transactions/xa/AtomikosTest.java b/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/transactions/xa/AtomikosTest.java index 9df766bec81e61..141c4f87d6dfe1 100644 --- a/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/transactions/xa/AtomikosTest.java +++ b/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/transactions/xa/AtomikosTest.java @@ -44,7 +44,7 @@ void assertShardingInAtomikosTransactions() throws SQLException { private void initEnvironment() throws SQLException { testShardingService.getOrderRepository().createTableIfNotExistsInMySQL(); testShardingService.getOrderItemRepository().createTableIfNotExistsInMySQL(); - testShardingService.getAddressRepository().createTableIfNotExists(); + testShardingService.getAddressRepository().createTableIfNotExistsInMySQL(); testShardingService.getOrderRepository().truncateTable(); testShardingService.getOrderItemRepository().truncateTable(); testShardingService.getAddressRepository().truncateTable(); diff --git a/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/transactions/xa/NarayanaTest.java b/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/transactions/xa/NarayanaTest.java index 87993a52150993..ba7103fd8851a2 100644 --- a/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/transactions/xa/NarayanaTest.java +++ b/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/transactions/xa/NarayanaTest.java @@ -47,7 +47,7 @@ void assertShardingInNarayanaTransactions() throws SQLException, CoreEnvironment private void initEnvironment() throws SQLException { testShardingService.getOrderRepository().createTableIfNotExistsInMySQL(); testShardingService.getOrderItemRepository().createTableIfNotExistsInMySQL(); - testShardingService.getAddressRepository().createTableIfNotExists(); + testShardingService.getAddressRepository().createTableIfNotExistsInMySQL(); testShardingService.getOrderRepository().truncateTable(); testShardingService.getOrderItemRepository().truncateTable(); testShardingService.getAddressRepository().truncateTable(); diff --git a/test/native/src/test/resources/test-native/sql/test-native-databases-hive.sql b/test/native/src/test/resources/test-native/sql/test-native-databases-hive.sql new file mode 100644 index 00000000000000..d23900f7d799c0 --- /dev/null +++ b/test/native/src/test/resources/test-native/sql/test-native-databases-hive.sql @@ -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. +-- + + +-- TODO To execute SQL like `DELETE FROM t_address WHERE address_id=?`, we always need to execute the following Hive Session-level SQL in the current `javax.sql.DataSource`. +-- `shardingsphere-parser-sql-hive` module does not support `CREATE`, `SET`, `TRUNCATE` statements yet. +set hive.support.concurrency=true; +set hive.exec.dynamic.partition.mode=nonstrict; +set hive.txn.manager=org.apache.hadoop.hive.ql.lockmgr.DbTxnManager; + +CREATE TABLE IF NOT EXISTS t_order +( + order_id BIGINT, + order_type INT, + user_id INT NOT NULL, + address_id BIGINT NOT NULL, + status VARCHAR(50), + PRIMARY KEY (order_id) disable novalidate +) CLUSTERED BY (order_id) INTO 2 BUCKETS STORED AS ORC TBLPROPERTIES ('transactional' = 'true'); + +CREATE TABLE IF NOT EXISTS t_order_item +( + order_item_id BIGINT, + order_id BIGINT NOT NULL, + user_id INT NOT NULL, + phone VARCHAR(50), + status VARCHAR(50), + PRIMARY KEY (order_item_id) disable novalidate +) CLUSTERED BY (order_item_id) INTO 2 BUCKETS STORED AS ORC TBLPROPERTIES ('transactional' = 'true'); + +CREATE TABLE IF NOT EXISTS t_address +( + address_id BIGINT NOT NULL, + address_name VARCHAR(100) NOT NULL, + PRIMARY KEY (address_id) disable novalidate +) CLUSTERED BY (address_id) INTO 2 BUCKETS STORED AS ORC TBLPROPERTIES ('transactional' = 'true'); + +TRUNCATE TABLE t_order; +TRUNCATE TABLE t_order_item; +TRUNCATE TABLE t_address; diff --git a/test/native/src/test/resources/test-native/yaml/databases/hive.yaml b/test/native/src/test/resources/test-native/yaml/databases/hive.yaml new file mode 100644 index 00000000000000..c44cd303bb3bc5 --- /dev/null +++ b/test/native/src/test/resources/test-native/yaml/databases/hive.yaml @@ -0,0 +1,72 @@ +# +# 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. +# + +mode: + type: Standalone + repository: + type: JDBC + +dataSources: + ds_0: + dataSourceClassName: com.zaxxer.hikari.HikariDataSource + driverClassName: org.apache.hive.jdbc.HiveDriver + jdbcUrl: $${fixture.test-native.yaml.database.hive.ds0.jdbc-url::} + ds_1: + dataSourceClassName: com.zaxxer.hikari.HikariDataSource + driverClassName: org.apache.hive.jdbc.HiveDriver + jdbcUrl: $${fixture.test-native.yaml.database.hive.ds1.jdbc-url::} + ds_2: + dataSourceClassName: com.zaxxer.hikari.HikariDataSource + driverClassName: org.apache.hive.jdbc.HiveDriver + jdbcUrl: $${fixture.test-native.yaml.database.hive.ds2.jdbc-url::} + +rules: +- !SHARDING + tables: + t_order: + actualDataNodes: + keyGenerateStrategy: + column: order_id + keyGeneratorName: snowflake + t_order_item: + actualDataNodes: + keyGenerateStrategy: + column: order_item_id + keyGeneratorName: snowflake + defaultDatabaseStrategy: + standard: + shardingColumn: user_id + shardingAlgorithmName: inline + shardingAlgorithms: + inline: + type: CLASS_BASED + props: + strategy: STANDARD + algorithmClassName: org.apache.shardingsphere.test.natived.jdbc.commons.algorithm.ClassBasedInlineShardingAlgorithmFixture + keyGenerators: + snowflake: + type: SNOWFLAKE + auditors: + sharding_key_required_auditor: + type: DML_SHARDING_CONDITIONS + +- !BROADCAST + tables: + - t_address + +props: + sql-show: false