From 8a7d90f3bc38e34404d11fc6faaa12c94b002224 Mon Sep 17 00:00:00 2001 From: mzitnik Date: Thu, 21 Dec 2023 20:38:40 +0200 Subject: [PATCH] Adding new test for insert big chuncks --- .../com/clickhouse/jdbc/JdbcIssuesTest.java | 39 ++++++++++++++++++- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/clickhouse-jdbc/src/test/java/com/clickhouse/jdbc/JdbcIssuesTest.java b/clickhouse-jdbc/src/test/java/com/clickhouse/jdbc/JdbcIssuesTest.java index 5a819393a..0d529ccfb 100644 --- a/clickhouse-jdbc/src/test/java/com/clickhouse/jdbc/JdbcIssuesTest.java +++ b/clickhouse-jdbc/src/test/java/com/clickhouse/jdbc/JdbcIssuesTest.java @@ -19,9 +19,9 @@ public class JdbcIssuesTest extends JdbcIntegrationTest { @Test(groups = "integration") - public void testDecompress() throws SQLException { + public void test01Decompress() throws SQLException { String httpEndpoint = "http://" + getServerAddress(ClickHouseProtocol.HTTP) + "/"; - String TABLE_NAME = "decompress_issue"; + String TABLE_NAME = "decompress_issue_01"; Properties prop = new Properties(); prop.setProperty("decompress", "true"); prop.setProperty("decompress_algorithm", "lz4"); @@ -52,4 +52,39 @@ public void testDecompress() throws SQLException { } } + + @Test + public void test02Decompress() throws SQLException { + String httpEndpoint = "http://" + getServerAddress(ClickHouseProtocol.HTTP) + "/"; + String TABLE_NAME = "decompress_issue_02"; + Properties prop = new Properties(); + prop.setProperty("decompress", "true"); + prop.setProperty("decompress_algorithm", "lz4"); + String url = String.format("jdbc:ch:%s", httpEndpoint); + ClickHouseDataSource dataSource = new ClickHouseDataSource(url, prop); + String columnNames = "event_id"; + String columnValues = "('event_id String')"; + String sql = String.format("INSERT INTO %s (%s) SELECT %s FROM input %s", TABLE_NAME, columnNames, columnNames, columnValues); + + Connection conn = dataSource.getConnection("default", ""); + Statement st = conn.createStatement(); + st.execute(String.format("CREATE TABLE %s (`event_id` String) ENGINE = Log", TABLE_NAME)); + + int count = 1; + boolean failed = false; + + String content = StringUtils.repeat("*", count); + try (PreparedStatement ps = conn.prepareStatement(sql)) { + while (count <= 100000) { + ps.setString(1, content); + ps.addBatch(); + count *= 2; + } + ps.executeBatch(); + } catch (SQLException sqlException) { + sqlException.printStackTrace(); + failed = true; + } + Assert.assertFalse(failed, String.format("Failed when content size %d", count)); + } }