|
| 1 | +/* |
| 2 | + * Copyright 2025 Qiheng He |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package io.github.linghengqian.hive.server2.jdbc.driver.thin.iceberg; |
| 18 | + |
| 19 | +import org.junit.jupiter.api.Test; |
| 20 | +import org.testcontainers.containers.GenericContainer; |
| 21 | +import org.testcontainers.junit.jupiter.Container; |
| 22 | +import org.testcontainers.junit.jupiter.Testcontainers; |
| 23 | +import org.testcontainers.utility.DockerImageName; |
| 24 | + |
| 25 | +import java.sql.*; |
| 26 | +import java.time.Duration; |
| 27 | +import java.time.temporal.ChronoUnit; |
| 28 | + |
| 29 | +import static org.awaitility.Awaitility.await; |
| 30 | +import static org.hamcrest.MatcherAssert.assertThat; |
| 31 | +import static org.hamcrest.Matchers.is; |
| 32 | + |
| 33 | +@SuppressWarnings({"SqlNoDataSourceInspection", "resource"}) |
| 34 | +@Testcontainers |
| 35 | +public class ParquetTest { |
| 36 | + @Container |
| 37 | + public static final GenericContainer<?> CONTAINER = new GenericContainer<>(DockerImageName.parse("apache/hive:4.0.1")) |
| 38 | + .withEnv("SERVICE_NAME", "hiveserver2") |
| 39 | + .withExposedPorts(10000); |
| 40 | + |
| 41 | + @Test |
| 42 | + void test() throws SQLException { |
| 43 | + String jdbcUrlPrefix = "jdbc:hive2://" + CONTAINER.getHost() + ":" + CONTAINER.getMappedPort(10000); |
| 44 | + await().atMost(Duration.of(30L, ChronoUnit.SECONDS)).ignoreExceptions().until(() -> { |
| 45 | + DriverManager.getConnection(jdbcUrlPrefix).close(); |
| 46 | + return true; |
| 47 | + }); |
| 48 | + try (Connection connection = DriverManager.getConnection(jdbcUrlPrefix); |
| 49 | + Statement statement = connection.createStatement()) { |
| 50 | + statement.execute("CREATE DATABASE demo_ds_0"); |
| 51 | + } |
| 52 | + try (Connection connection = DriverManager.getConnection(jdbcUrlPrefix + "/demo_ds_0"); |
| 53 | + Statement statement = connection.createStatement()) { |
| 54 | + statement.execute("CREATE TABLE IF NOT EXISTS t_order (\n" + |
| 55 | + " order_id BIGINT NOT NULL,\n" + |
| 56 | + " order_type INT,\n" + |
| 57 | + " user_id INT NOT NULL,\n" + |
| 58 | + " address_id BIGINT NOT NULL,\n" + |
| 59 | + " status string,\n" + |
| 60 | + " PRIMARY KEY (order_id) disable novalidate\n" + |
| 61 | + ") STORED BY ICEBERG STORED AS Parquet TBLPROPERTIES ('format-version' = '2')"); |
| 62 | + statement.execute("TRUNCATE TABLE t_order"); |
| 63 | + statement.executeUpdate("INSERT INTO t_order (order_id, user_id, order_type, address_id, status) VALUES (1, 1, 1, 1, 'INSERT_TEST')"); |
| 64 | + ResultSet firstResultSet = statement.executeQuery("select * from t_order"); |
| 65 | + assertThat(firstResultSet.next(), is(true)); |
| 66 | + statement.executeUpdate("DELETE FROM t_order WHERE order_id=1"); |
| 67 | + ResultSet secondResultSet = statement.executeQuery("select * from t_order"); |
| 68 | + assertThat(secondResultSet.next(), is(false)); |
| 69 | + statement.execute("DROP TABLE IF EXISTS t_order"); |
| 70 | + } |
| 71 | + |
| 72 | + } |
| 73 | +} |
0 commit comments