From 3ec6042cf3250264f379b5cc106c23dc7fa4d0be Mon Sep 17 00:00:00 2001 From: Yuya Ebihara Date: Thu, 13 Jan 2022 16:35:58 +0900 Subject: [PATCH 1/2] Fix version check for system.tables.comment column in DatabaseMetaData.getTables --- .../java/com/clickhouse/jdbc/ClickHouseDatabaseMetaData.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clickhouse-jdbc/src/main/java/com/clickhouse/jdbc/ClickHouseDatabaseMetaData.java b/clickhouse-jdbc/src/main/java/com/clickhouse/jdbc/ClickHouseDatabaseMetaData.java index 5ef00239c..ab22d9ab7 100644 --- a/clickhouse-jdbc/src/main/java/com/clickhouse/jdbc/ClickHouseDatabaseMetaData.java +++ b/clickhouse-jdbc/src/main/java/com/clickhouse/jdbc/ClickHouseDatabaseMetaData.java @@ -752,7 +752,7 @@ public ResultSet getTables(String catalog, String schemaPattern, String tableNam List results = new ArrayList<>(databases.size()); for (String database : databases) { Map params = new HashMap<>(); - params.put("comment", connection.getServerVersion().check("[20.8,)") ? "t.comment" : "''"); + params.put("comment", connection.getServerVersion().check("[21.6,)") ? "t.comment" : "''"); params.put("database", ClickHouseValues.convertToQuotedString(database)); params.put("table", ClickHouseChecker.isNullOrEmpty(tableNamePattern) ? "'%'" : ClickHouseValues.convertToQuotedString(tableNamePattern)); From 1299db90045768daec6d3c4942f2880e6c40ba48 Mon Sep 17 00:00:00 2001 From: Zhichun Wu Date: Thu, 13 Jan 2022 21:01:30 +0800 Subject: [PATCH 2/2] Add integration test --- .../jdbc/ClickHouseDatabaseMetaDataTest.java | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/clickhouse-jdbc/src/test/java/com/clickhouse/jdbc/ClickHouseDatabaseMetaDataTest.java b/clickhouse-jdbc/src/test/java/com/clickhouse/jdbc/ClickHouseDatabaseMetaDataTest.java index bf294df05..fe8a16e6a 100644 --- a/clickhouse-jdbc/src/test/java/com/clickhouse/jdbc/ClickHouseDatabaseMetaDataTest.java +++ b/clickhouse-jdbc/src/test/java/com/clickhouse/jdbc/ClickHouseDatabaseMetaDataTest.java @@ -2,6 +2,8 @@ import java.sql.ResultSet; import java.sql.SQLException; +import java.sql.Statement; +import java.util.Locale; import java.util.Properties; import org.testng.Assert; @@ -18,4 +20,26 @@ public void testGetTypeInfo() throws SQLException { } } } + + @Test(groups = "integration") + public void testTableComment() throws SQLException { + String tableName = "test_table_comment"; + String tableComment = "table comments"; + try (ClickHouseConnection conn = newConnection(new Properties()); + Statement s = conn.createStatement()) { + // https://github.com/ClickHouse/ClickHouse/pull/30852 + if (!conn.getServerVersion().check("[21.6,)")) { + return; + } + + s.execute(String.format(Locale.ROOT, + "drop table if exists %1$s; create table %1$s(s String) engine=Memory comment '%2$s'", + tableName, tableComment)); + try (ResultSet rs = conn.getMetaData().getTables(null, "%", tableName, null)) { + Assert.assertTrue(rs.next()); + Assert.assertEquals(rs.getString("remarks"), tableComment); + Assert.assertFalse(rs.next()); + } + } + } }