From a46a368ab3c4bb8d0d02996aa12eee7a07775558 Mon Sep 17 00:00:00 2001 From: Zhichun Wu Date: Tue, 20 Apr 2021 13:27:43 +0800 Subject: [PATCH 1/3] Add more query parameters --- .../settings/ClickHouseQueryParam.java | 12 ++++-- .../ClickHouseLargeNumberTest.java | 40 +++++++++++++++++++ .../integration/ClickHouseMapTest.java | 39 ++++++++++++++++++ 3 files changed, 88 insertions(+), 3 deletions(-) diff --git a/clickhouse-jdbc/src/main/java/ru/yandex/clickhouse/settings/ClickHouseQueryParam.java b/clickhouse-jdbc/src/main/java/ru/yandex/clickhouse/settings/ClickHouseQueryParam.java index 4d6e57baa..f33564093 100644 --- a/clickhouse-jdbc/src/main/java/ru/yandex/clickhouse/settings/ClickHouseQueryParam.java +++ b/clickhouse-jdbc/src/main/java/ru/yandex/clickhouse/settings/ClickHouseQueryParam.java @@ -11,6 +11,10 @@ public enum ClickHouseQueryParam implements DriverPropertyCreator { AGGREGATION_MEMORY_EFFICIENT_MERGE_THREADS("aggregation_memory_efficient_merge_threads", null, Long.class, ""), + ALLOW_EXPERIMENTAL_BIGINT_TYPES("allow_experimental_bigint_types", null, Integer.class, "Enables or disables integer values exceeding the range that is supported by the int data type."), + + ALLOW_EXPERIMENTAL_MAP_TYPE("allow_experimental_map_type", null, Integer.class, "Enables or disables Map data type."), + BACKGROUND_POOL_SIZE("background_pool_size", null, Long.class, ""), AUTHORIZATION("authorization", null, String.class, "Authorization header content for HTTP transport"), @@ -78,6 +82,8 @@ public enum ClickHouseQueryParam implements DriverPropertyCreator { INTERACTIVE_DELAY("interactive_delay", null, Long.class, ""), + JOIN_ALGORITHM("join_algorithm", null, String.class, ""), + LOAD_BALANCING("load_balancing", null, String.class, ""), LOG_QUERIES("log_queries", false, Boolean.class, ""), @@ -245,9 +251,9 @@ public enum ClickHouseQueryParam implements DriverPropertyCreator { QUOTA_KEY("quota_key", null, String.class, "quota is calculated for each quota_key value. For example here may be some user name."), + @Deprecated use_client_time_zone("use_client_time_zone", false, Boolean.class, ""), - USE_UNCOMPRESSED_CACHE("use_uncompressed_cache", true, Boolean.class, "Whether to use the cache of uncompressed blocks."), USER("user", null, String.class, "user name, by default - default"), @@ -261,7 +267,7 @@ public enum ClickHouseQueryParam implements DriverPropertyCreator { private final String key; private final Object defaultValue; - private final Class clazz; + private final Class clazz; private final String description; ClickHouseQueryParam(String key, T defaultValue, Class clazz, String description) { @@ -279,7 +285,7 @@ public Object getDefaultValue() { return defaultValue; } - public Class getClazz() { + public Class getClazz() { return clazz; } diff --git a/clickhouse-jdbc/src/test/java/ru/yandex/clickhouse/integration/ClickHouseLargeNumberTest.java b/clickhouse-jdbc/src/test/java/ru/yandex/clickhouse/integration/ClickHouseLargeNumberTest.java index 7c972f410..8f2354779 100644 --- a/clickhouse-jdbc/src/test/java/ru/yandex/clickhouse/integration/ClickHouseLargeNumberTest.java +++ b/clickhouse-jdbc/src/test/java/ru/yandex/clickhouse/integration/ClickHouseLargeNumberTest.java @@ -1,23 +1,32 @@ package ru.yandex.clickhouse.integration; import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertFalse; +import static org.testng.Assert.assertNull; import static org.testng.Assert.assertTrue; +import static org.testng.Assert.fail; import java.math.BigDecimal; import java.math.BigInteger; import java.sql.Connection; import java.sql.ResultSet; +import java.sql.SQLException; import java.sql.Statement; +import java.util.EnumMap; +import java.util.Map; import java.util.UUID; import org.testng.annotations.AfterTest; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; +import ru.yandex.clickhouse.ClickHouseConnection; import ru.yandex.clickhouse.ClickHouseContainerForTest; import ru.yandex.clickhouse.ClickHouseDataSource; +import ru.yandex.clickhouse.ClickHouseStatement; import ru.yandex.clickhouse.except.ClickHouseException; import ru.yandex.clickhouse.settings.ClickHouseProperties; +import ru.yandex.clickhouse.settings.ClickHouseQueryParam; public class ClickHouseLargeNumberTest { private Connection conn; @@ -46,6 +55,37 @@ public void tearDown() throws Exception { } } + @Test + public void testBigIntSupport() throws SQLException { + String testSql = "create table if not exists system.test_bigint_support(i Int256) engine=Memory;" + + "drop table if exists system.test_bigint_support;"; + try (Connection conn = ClickHouseContainerForTest.newDataSource().getConnection(); + Statement s = conn.createStatement()) { + s.execute("set allow_experimental_bigint_types=0;" + testSql); + fail("Should fail without enabling bigint support"); + } catch (SQLException e) { + assertEquals(e.getErrorCode(), 44); + } + + try (Connection conn = ClickHouseContainerForTest.newDataSource().getConnection(); + Statement s = conn.createStatement()) { + assertFalse(s.execute("set allow_experimental_bigint_types=1;" + testSql)); + } + + try (ClickHouseConnection conn = ClickHouseContainerForTest.newDataSource().getConnection(); + ClickHouseStatement s = conn.createStatement()) { + Map params = new EnumMap<>(ClickHouseQueryParam.class); + params.put(ClickHouseQueryParam.ALLOW_EXPERIMENTAL_BIGINT_TYPES, "1"); + assertNull(s.executeQuery(testSql, params)); + + params.put(ClickHouseQueryParam.ALLOW_EXPERIMENTAL_BIGINT_TYPES, "0"); + s.executeQuery(testSql, params); + fail("Should fail without enabling bigint support"); + } catch (SQLException e) { + assertEquals(e.getErrorCode(), 44); + } + } + @Test public void testSignedIntegers() throws Exception { if (conn == null) { diff --git a/clickhouse-jdbc/src/test/java/ru/yandex/clickhouse/integration/ClickHouseMapTest.java b/clickhouse-jdbc/src/test/java/ru/yandex/clickhouse/integration/ClickHouseMapTest.java index 562793928..39db2b370 100644 --- a/clickhouse-jdbc/src/test/java/ru/yandex/clickhouse/integration/ClickHouseMapTest.java +++ b/clickhouse-jdbc/src/test/java/ru/yandex/clickhouse/integration/ClickHouseMapTest.java @@ -2,12 +2,17 @@ import static org.junit.Assert.assertArrayEquals; import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertFalse; +import static org.testng.Assert.assertNull; import static org.testng.Assert.assertTrue; +import static org.testng.Assert.fail; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; +import java.sql.SQLException; import java.sql.Statement; +import java.util.EnumMap; import java.util.Map; import java.util.UUID; @@ -15,10 +20,13 @@ import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; +import ru.yandex.clickhouse.ClickHouseConnection; import ru.yandex.clickhouse.ClickHouseContainerForTest; import ru.yandex.clickhouse.ClickHouseDataSource; +import ru.yandex.clickhouse.ClickHouseStatement; import ru.yandex.clickhouse.except.ClickHouseException; import ru.yandex.clickhouse.settings.ClickHouseProperties; +import ru.yandex.clickhouse.settings.ClickHouseQueryParam; import ru.yandex.clickhouse.util.Utils; public class ClickHouseMapTest { @@ -61,6 +69,37 @@ private void assertMap(Object actual, Object expected) { } } + @Test + public void testMapSupport() throws SQLException { + String testSql = "create table if not exists system.test_map_support(m Map(UInt8, String)) engine=Memory;" + + "drop table if exists system.test_map_support;"; + try (Connection conn = ClickHouseContainerForTest.newDataSource().getConnection(); + Statement s = conn.createStatement()) { + s.execute("set allow_experimental_map_type=0;" + testSql); + fail("Should fail without enabling map support"); + } catch (SQLException e) { + assertEquals(e.getErrorCode(), 44); + } + + try (Connection conn = ClickHouseContainerForTest.newDataSource().getConnection(); + Statement s = conn.createStatement()) { + assertFalse(s.execute("set allow_experimental_map_type=1;" + testSql)); + } + + try (ClickHouseConnection conn = ClickHouseContainerForTest.newDataSource().getConnection(); + ClickHouseStatement s = conn.createStatement()) { + Map params = new EnumMap<>(ClickHouseQueryParam.class); + params.put(ClickHouseQueryParam.ALLOW_EXPERIMENTAL_MAP_TYPE, "1"); + assertNull(s.executeQuery(testSql, params)); + + params.put(ClickHouseQueryParam.ALLOW_EXPERIMENTAL_MAP_TYPE, "0"); + s.executeQuery(testSql, params); + fail("Should fail without enabling map support"); + } catch (SQLException e) { + assertEquals(e.getErrorCode(), 44); + } + } + @Test public void testMaps() throws Exception { if (conn == null) { From f2a2b6c3ae76dc9fb981416fdf57134109a0974f Mon Sep 17 00:00:00 2001 From: Zhichun Wu Date: Tue, 20 Apr 2021 13:36:36 +0800 Subject: [PATCH 2/3] Fix build break found on 20.8 --- .../ru/yandex/clickhouse/integration/ClickHouseMapTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clickhouse-jdbc/src/test/java/ru/yandex/clickhouse/integration/ClickHouseMapTest.java b/clickhouse-jdbc/src/test/java/ru/yandex/clickhouse/integration/ClickHouseMapTest.java index 39db2b370..20aa22b83 100644 --- a/clickhouse-jdbc/src/test/java/ru/yandex/clickhouse/integration/ClickHouseMapTest.java +++ b/clickhouse-jdbc/src/test/java/ru/yandex/clickhouse/integration/ClickHouseMapTest.java @@ -78,7 +78,7 @@ public void testMapSupport() throws SQLException { s.execute("set allow_experimental_map_type=0;" + testSql); fail("Should fail without enabling map support"); } catch (SQLException e) { - assertEquals(e.getErrorCode(), 44); + assertTrue(e.getErrorCode() == 44 || e.getErrorCode() == 115); } try (Connection conn = ClickHouseContainerForTest.newDataSource().getConnection(); @@ -96,7 +96,7 @@ public void testMapSupport() throws SQLException { s.executeQuery(testSql, params); fail("Should fail without enabling map support"); } catch (SQLException e) { - assertEquals(e.getErrorCode(), 44); + assertTrue(e.getErrorCode() == 44 || e.getErrorCode() == 115); } } From 8a3f25c6baca25f4c5edb9bca32df87304280e7a Mon Sep 17 00:00:00 2001 From: Zhichun Wu Date: Tue, 20 Apr 2021 13:43:18 +0800 Subject: [PATCH 3/3] Disable bigint/map tests when they're not supported --- .../clickhouse/integration/ClickHouseLargeNumberTest.java | 4 ++++ .../yandex/clickhouse/integration/ClickHouseMapTest.java | 8 ++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/clickhouse-jdbc/src/test/java/ru/yandex/clickhouse/integration/ClickHouseLargeNumberTest.java b/clickhouse-jdbc/src/test/java/ru/yandex/clickhouse/integration/ClickHouseLargeNumberTest.java index 8f2354779..e0eb722e3 100644 --- a/clickhouse-jdbc/src/test/java/ru/yandex/clickhouse/integration/ClickHouseLargeNumberTest.java +++ b/clickhouse-jdbc/src/test/java/ru/yandex/clickhouse/integration/ClickHouseLargeNumberTest.java @@ -57,6 +57,10 @@ public void tearDown() throws Exception { @Test public void testBigIntSupport() throws SQLException { + if (conn == null) { + return; + } + String testSql = "create table if not exists system.test_bigint_support(i Int256) engine=Memory;" + "drop table if exists system.test_bigint_support;"; try (Connection conn = ClickHouseContainerForTest.newDataSource().getConnection(); diff --git a/clickhouse-jdbc/src/test/java/ru/yandex/clickhouse/integration/ClickHouseMapTest.java b/clickhouse-jdbc/src/test/java/ru/yandex/clickhouse/integration/ClickHouseMapTest.java index 20aa22b83..32bc30537 100644 --- a/clickhouse-jdbc/src/test/java/ru/yandex/clickhouse/integration/ClickHouseMapTest.java +++ b/clickhouse-jdbc/src/test/java/ru/yandex/clickhouse/integration/ClickHouseMapTest.java @@ -71,6 +71,10 @@ private void assertMap(Object actual, Object expected) { @Test public void testMapSupport() throws SQLException { + if (conn == null) { + return; + } + String testSql = "create table if not exists system.test_map_support(m Map(UInt8, String)) engine=Memory;" + "drop table if exists system.test_map_support;"; try (Connection conn = ClickHouseContainerForTest.newDataSource().getConnection(); @@ -78,7 +82,7 @@ public void testMapSupport() throws SQLException { s.execute("set allow_experimental_map_type=0;" + testSql); fail("Should fail without enabling map support"); } catch (SQLException e) { - assertTrue(e.getErrorCode() == 44 || e.getErrorCode() == 115); + assertEquals(e.getErrorCode(), 44); } try (Connection conn = ClickHouseContainerForTest.newDataSource().getConnection(); @@ -96,7 +100,7 @@ public void testMapSupport() throws SQLException { s.executeQuery(testSql, params); fail("Should fail without enabling map support"); } catch (SQLException e) { - assertTrue(e.getErrorCode() == 44 || e.getErrorCode() == 115); + assertEquals(e.getErrorCode(), 44); } }