Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -801,12 +801,12 @@ private static void buildAndCondition(StringBuilder dest, List<String> condition
@Override
public ResultSet getColumns(String catalog, String schemaPattern, String tableNamePattern, String columnNamePattern) throws SQLException {
StringBuilder query;
if (connection.getServerVersion().compareTo("1.1.54237") > 0) {
if (ClickHouseVersionNumberUtil.compare(connection.getServerVersion(), "18.16") >= 0) {
query = new StringBuilder(
"SELECT database, table, name, type, default_kind as default_type, default_expression, comment ");
} else {
query = new StringBuilder(
"SELECT database, table, name, type, default_type, default_expression, NULL AS comment ");
"SELECT database, table, name, type, default_kind as default_type, default_expression, NULL AS comment ");
}
query.append("FROM system.columns ");
List<String> predicates = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
public class ClickHouseDatabaseMetadataTest {

private ClickHouseDataSource dataSource;
private Connection connection;
private ClickHouseConnection connection;

@BeforeTest
public void setUp() throws Exception {
Expand Down Expand Up @@ -64,11 +64,14 @@ public void testMetadata() throws Exception {

@Test
public void testMetadataColumns() throws Exception {
boolean supportComment = ClickHouseVersionNumberUtil.compare(connection.getServerVersion(), "18.16") >= 0;
connection.createStatement().executeQuery(
"DROP TABLE IF EXISTS test.testMetadata");
connection.createStatement().executeQuery(
"CREATE TABLE test.testMetadata("
+ "foo Float32, bar UInt8 DEFAULT 42 COMMENT 'baz') ENGINE = TinyLog");
+ "foo Float32, bar UInt8"
+ (supportComment ? " DEFAULT 42 COMMENT 'baz'" : "")
+ ") ENGINE = TinyLog");
ResultSet columns = connection.getMetaData().getColumns(
null, "test", "testMetadata", null);
columns.next();
Expand Down Expand Up @@ -97,8 +100,10 @@ public void testMetadataColumns() throws Exception {
Assert.assertEquals(columns.getString("IS_AUTOINCREMENT"), "NO");
Assert.assertEquals(columns.getString("IS_GENERATEDCOLUMN"), "NO");
columns.next();
Assert.assertEquals(columns.getInt("COLUMN_DEF"), 42);
Assert.assertEquals(columns.getObject("REMARKS"), "baz");
if (supportComment) {
Assert.assertEquals(columns.getInt("COLUMN_DEF"), 42);
Assert.assertEquals(columns.getObject("REMARKS"), "baz");
}
}

@Test
Expand Down