From 9e5013c44a4eaef6b898ba17a3c15434102ec059 Mon Sep 17 00:00:00 2001 From: Paultagoras Date: Fri, 6 Dec 2024 06:01:16 -0500 Subject: [PATCH] Adjust tests --- .../clickhouse/jdbc/metadata/DatabaseMetaData.java | 6 ++++-- .../jdbc/metadata/DatabaseMetaDataTest.java | 12 ++++++++---- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/jdbc-v2/src/main/java/com/clickhouse/jdbc/metadata/DatabaseMetaData.java b/jdbc-v2/src/main/java/com/clickhouse/jdbc/metadata/DatabaseMetaData.java index d61b93593..8cda4aac8 100644 --- a/jdbc-v2/src/main/java/com/clickhouse/jdbc/metadata/DatabaseMetaData.java +++ b/jdbc-v2/src/main/java/com/clickhouse/jdbc/metadata/DatabaseMetaData.java @@ -919,8 +919,10 @@ public ResultSet getPrimaryKeys(String catalog, String schema, String table) thr "FROM system.tables " + "ARRAY JOIN arrayZip(splitByChar(',', primary_key), arrayEnumerate(splitByChar(',', primary_key))) as c " + "WHERE system.tables.primary_key <> '' " + - "AND system.tables.database LIKE '" + (schema == null ? "%" : schema) + "' " + - "AND system.tables.name LIKE '" + (table == null ? "%" : table) + "'"; + "AND system.tables.database ILIKE '" + (schema == null ? "%" : schema) + "' " + + "AND system.tables.name ILIKE '" + (table == null ? "%" : table) + "' " + + "ORDER BY TABLE_SCHEM, TABLE_NAME, KEY_SEQ"; + log.debug("getPrimaryKeys: %s", sql); return connection.createStatement().executeQuery(sql); } catch (Exception e) { throw ExceptionUtils.toSqlState(e); diff --git a/jdbc-v2/src/test/java/com/clickhouse/jdbc/metadata/DatabaseMetaDataTest.java b/jdbc-v2/src/test/java/com/clickhouse/jdbc/metadata/DatabaseMetaDataTest.java index e3bd1929a..d2fa90b29 100644 --- a/jdbc-v2/src/test/java/com/clickhouse/jdbc/metadata/DatabaseMetaDataTest.java +++ b/jdbc-v2/src/test/java/com/clickhouse/jdbc/metadata/DatabaseMetaDataTest.java @@ -98,16 +98,20 @@ public void testGetTables() throws Exception { } } - //@Ignore("ClickHouse does not support primary keys") + @Test(groups = { "integration" }) public void testGetPrimaryKeys() throws Exception { try (Connection conn = getJdbcConnection()) { DatabaseMetaData dbmd = conn.getMetaData(); - ResultSet rs = dbmd.getPrimaryKeys(null, "system", "numbers"); + ResultSet rs = dbmd.getPrimaryKeys(null, "system", "query_log"); assertTrue(rs.next()); - assertEquals(rs.getString("TABLE_NAME"), "numbers"); - assertEquals(rs.getString("COLUMN_NAME"), "number"); + assertEquals(rs.getString("TABLE_NAME"), "query_log"); + assertEquals(rs.getString("COLUMN_NAME"), "event_date"); assertEquals(rs.getShort("KEY_SEQ"), 1); + assertTrue(rs.next()); + assertEquals(rs.getString("TABLE_NAME"), "query_log"); + assertEquals(rs.getString("COLUMN_NAME"), "event_time"); + assertEquals(rs.getShort("KEY_SEQ"), 2); assertFalse(rs.next()); } }