From 8f5a88a9f92900056f124853b5d150f5d9587a6c Mon Sep 17 00:00:00 2001 From: piyush15102003 Date: Fri, 23 Oct 2026 22:14:36 +0530 Subject: [PATCH] [jdbc-v2] Treat disable_frameworks_detection as a driver property The documented driver property had no DriverProperties entry, so buildFinalProperties forwarded it to client-v2, which rejects unknown keys and failed the connection. It was also read from the Properties argument before URL parameters were merged, so the URL form had no effect. Add the DriverProperties entry and read the flag from the merged driver properties. Correct the documented default to false. Fixes #3218 --- docs/clickhouse-docs/jdbc.mdx | 2 +- history/latest/3218.md | 5 +++ .../com/clickhouse/jdbc/DriverProperties.java | 6 ++++ .../jdbc/internal/JdbcConfiguration.java | 2 +- .../jdbc/internal/JdbcConfigurationTest.java | 33 +++++++++++++++++++ 5 files changed, 46 insertions(+), 2 deletions(-) create mode 100644 history/latest/3218.md diff --git a/docs/clickhouse-docs/jdbc.mdx b/docs/clickhouse-docs/jdbc.mdx index d24a75e97..54dfe4d84 100644 --- a/docs/clickhouse-docs/jdbc.mdx +++ b/docs/clickhouse-docs/jdbc.mdx @@ -76,7 +76,7 @@ as is to the driver. Driver has some own properties that aren't part of the clie **Driver properties**: | Property | Default | Description | |----------------------------------|---------|----------------------------------------------------------------| -| `disable_frameworks_detection` | `true` | Disable frameworks detection for User-Agent | +| `disable_frameworks_detection` | `false` | Disable frameworks detection for User-Agent | | `jdbc_ignore_unsupported_values` | `false` | Suppresses `SQLFeatureNotSupportedException` where is doesn't affect the driver work | | `clickhouse.jdbc.v1` | `false` | Use older JDBC implementation instead of new JDBC | | `default_query_settings` | `null` | Allows passing of default query settings with query operations | diff --git a/history/latest/3218.md b/history/latest/3218.md new file mode 100644 index 000000000..ccfc347f0 --- /dev/null +++ b/history/latest/3218.md @@ -0,0 +1,5 @@ +- **[jdbc-v2]** The documented driver property `disable_frameworks_detection` is now a driver property and is no + longer forwarded to the client, so setting it no longer fails the connection with + `Unknown and unmapped config properties`. The property is now also read from the connection URL, not only from the + `Properties` argument. The documented default is corrected to `false`. + (https://github.com/ClickHouse/clickhouse-java/issues/3218) diff --git a/jdbc-v2/src/main/java/com/clickhouse/jdbc/DriverProperties.java b/jdbc-v2/src/main/java/com/clickhouse/jdbc/DriverProperties.java index 4b27626d0..94ecd69be 100644 --- a/jdbc-v2/src/main/java/com/clickhouse/jdbc/DriverProperties.java +++ b/jdbc-v2/src/main/java/com/clickhouse/jdbc/DriverProperties.java @@ -171,6 +171,12 @@ public enum DriverProperties { */ METADATA_USE_SHOW_STATEMENTS("jdbc_metadata_use_show_statements", String.valueOf(Boolean.TRUE)), + /** + * Disables detection of application frameworks (for example Apache Spark) for the {@code User-Agent} header. + * Default: false + */ + DISABLE_FRAMEWORKS_DETECTION("disable_frameworks_detection", String.valueOf(Boolean.FALSE)), + ; diff --git a/jdbc-v2/src/main/java/com/clickhouse/jdbc/internal/JdbcConfiguration.java b/jdbc-v2/src/main/java/com/clickhouse/jdbc/internal/JdbcConfiguration.java index 2e4a85903..056bf0742 100644 --- a/jdbc-v2/src/main/java/com/clickhouse/jdbc/internal/JdbcConfiguration.java +++ b/jdbc-v2/src/main/java/com/clickhouse/jdbc/internal/JdbcConfiguration.java @@ -121,7 +121,6 @@ public Map> getTypeMap() { */ public JdbcConfiguration(String url, Properties info) throws SQLException { final Properties props = info == null ? new Properties() : info; - this.disableFrameworkDetection = Boolean.parseBoolean(props.getProperty("disable_frameworks_detection", "false")); this.clientProperties = new HashMap<>(); this.driverProperties = new HashMap<>(); @@ -131,6 +130,7 @@ public JdbcConfiguration(String url, Properties info) throws SQLException { Map urlProperties = parseUrl(url); String tmpConnectionUrl = urlProperties.remove(PARSE_URL_CONN_URL_PROP); buildFinalProperties(urlProperties, props); + this.disableFrameworkDetection = isSet(DriverProperties.DISABLE_FRAMEWORKS_DETECTION); // after initializing all properties - set final connection URL boolean useSSLInfo = Boolean.parseBoolean(props.getProperty(DriverProperties.SECURE_CONNECTION.getKey(), "false")); diff --git a/jdbc-v2/src/test/java/com/clickhouse/jdbc/internal/JdbcConfigurationTest.java b/jdbc-v2/src/test/java/com/clickhouse/jdbc/internal/JdbcConfigurationTest.java index 7085e3afb..c59b5e89a 100644 --- a/jdbc-v2/src/test/java/com/clickhouse/jdbc/internal/JdbcConfigurationTest.java +++ b/jdbc-v2/src/test/java/com/clickhouse/jdbc/internal/JdbcConfigurationTest.java @@ -224,6 +224,39 @@ public void testSSLModeInvalidValue() { () -> new JdbcConfiguration("jdbc:clickhouse://localhost:8123/?ssl_mode=insecure", new Properties())); } + @DataProvider(name = "disableFrameworksDetectionValues") + public Object[][] disableFrameworksDetectionValues() { + return new Object[][] { + {"", null, false}, + {"", "true", true}, + {"", "false", false}, + {"?disable_frameworks_detection=true", null, true}, + {"?disable_frameworks_detection=false", null, false}, + {"?disable_frameworks_detection=true", "false", true}, + }; + } + + @Test(dataProvider = "disableFrameworksDetectionValues") + public void testDisableFrameworksDetectionIsDriverProperty(String urlParams, String propertyValue, + boolean expected) throws Exception { + Properties properties = new Properties(); + if (propertyValue != null) { + properties.setProperty(DriverProperties.DISABLE_FRAMEWORKS_DETECTION.getKey(), propertyValue); + } + JdbcConfiguration configuration = new JdbcConfiguration("jdbc:clickhouse://localhost:8123/" + urlParams, + properties); + assertEquals(configuration.isDisableFrameworkDetection(), expected); + Assert.assertFalse(configuration.getClientProperties() + .containsKey(DriverProperties.DISABLE_FRAMEWORKS_DETECTION.getKey())); + } + + @Test + public void testUnknownPropertyForwardedToClientProperties() throws Exception { + JdbcConfiguration configuration = new JdbcConfiguration( + "jdbc:clickhouse://localhost:8123/?unknown_test_property=1", new Properties()); + assertEquals(configuration.getClientProperties().get("unknown_test_property"), "1"); + } + @Test public void testSSLCipherSuitesForwardedToClientProperties() throws Exception { String cipherSuites = "TLS_AES_256_GCM_SHA384,TLS_AES_128_GCM_SHA256";