Skip to content

Commit

Permalink
Merge pull request #804 from ebyhr/ebi/system-tables-comment-column
Browse files Browse the repository at this point in the history
Fix version check for system.tables.comment column in DatabaseMetaData.getTables
  • Loading branch information
zhicwu authored Jan 13, 2022
2 parents 75a6aa6 + 1299db9 commit fbe7d71
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -752,7 +752,7 @@ public ResultSet getTables(String catalog, String schemaPattern, String tableNam
List<ResultSet> results = new ArrayList<>(databases.size());
for (String database : databases) {
Map<String, String> 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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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());
}
}
}
}

0 comments on commit fbe7d71

Please sign in to comment.