Skip to content

Commit 1a65a14

Browse files
committed
schema,catalog fixes
1 parent 90506c4 commit 1a65a14

File tree

6 files changed

+175
-50
lines changed

6 files changed

+175
-50
lines changed

clickhouse-jdbc/src/main/java/com/clickhouse/jdbc/ClickHouseDatabaseMetaData.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -773,15 +773,22 @@ public ResultSet getTables(String catalog, String schemaPattern, String tableNam
773773
: ClickHouseValues.convertToQuotedString(tableNamePattern));
774774
params.put("types", builder.toString());
775775
String sql = ClickHouseParameterizedQuery
776-
.apply("select :catalog as TABLE_CAT, :schema as TABLE_SCHEM, t.name as TABLE_NAME, "
776+
.apply("select " +
777+
":catalog as TABLE_CAT, " +
778+
":schema as TABLE_SCHEM, " +
779+
"t.name as TABLE_NAME, "
777780
+ "case when t.engine like '%Log' then 'LOG TABLE' "
778781
+ "when t.engine in ('Buffer', 'Memory', 'Set') then 'MEMORY TABLE' "
779782
+ "when t.is_temporary != 0 then 'TEMPORARY TABLE' "
780783
+ "when t.engine like '%View' then 'VIEW' when t.engine = 'Dictionary' then 'DICTIONARY' "
781784
+ "when t.engine like 'Async%' or t.engine like 'System%' then 'SYSTEM TABLE' "
782785
+ "when empty(t.data_paths) then 'REMOTE TABLE' else 'TABLE' end as TABLE_TYPE, "
783-
+ ":comment as REMARKS, null as TYPE_CAT, d.engine as TYPE_SCHEM, "
784-
+ "t.engine as TYPE_NAME, null as SELF_REFERENCING_COL_NAME, null as REF_GENERATION\n"
786+
+ ":comment as REMARKS, " +
787+
"null as TYPE_CAT, " +
788+
"d.engine as TYPE_SCHEM, "
789+
+ "t.engine as TYPE_NAME, " +
790+
"null as SELF_REFERENCING_COL_NAME, " +
791+
"null as REF_GENERATION\n"
785792
+ "from system.tables t inner join system.databases d on t.database = d.name\n"
786793
+ "where t.database like :database and t.name like :table and TABLE_TYPE in (:types) "
787794
+ "order by t.database, t.name", params);

jdbc-v2/src/main/java/com/clickhouse/jdbc/ConnectionImpl.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ public class ConnectionImpl implements Connection, JdbcV2Wrapper {
2828
private String schema;
2929
private QuerySettings defaultQuerySettings;
3030

31+
private final com.clickhouse.jdbc.metadata.DatabaseMetaData metadata;
32+
3133
public ConnectionImpl(String url, Properties info) {
3234
log.debug("Creating connection to {}", url);
3335
this.url = url;//Raw URL
@@ -49,6 +51,8 @@ public ConnectionImpl(String url, Properties info) {
4951
.setClientName(clientName)
5052
.build();
5153
this.defaultQuerySettings = new QuerySettings();
54+
55+
this.metadata = new com.clickhouse.jdbc.metadata.DatabaseMetaData(this, false);
5256
}
5357

5458
public String getUser() {
@@ -141,7 +145,7 @@ public boolean isClosed() throws SQLException {
141145
@Override
142146
public DatabaseMetaData getMetaData() throws SQLException {
143147
checkOpen();
144-
return new com.clickhouse.jdbc.metadata.DatabaseMetaData(this);
148+
return this.metadata;
145149
}
146150

147151
@Override

jdbc-v2/src/main/java/com/clickhouse/jdbc/Driver.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public boolean acceptsURL(String url) throws SQLException {
105105

106106
@Override
107107
public DriverPropertyInfo[] getPropertyInfo(String url, Properties info) throws SQLException {
108-
return new DriverPropertyInfo[0];
108+
return JdbcConfiguration.getDriverPropertyInfo(info).toArray(new DriverPropertyInfo[0]);
109109
}
110110

111111
public static int getDriverMajorVersion() {
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.clickhouse.jdbc.internal;
2+
3+
/**
4+
* JDBC driver specific properties. Do not include any ClickHouse client properties here.
5+
*/
6+
public enum DriveProperties {
7+
8+
PLACEHOLDER("placeholder", "Placeholder for unknown properties");
9+
10+
private final String key;
11+
12+
private final String description;
13+
14+
DriveProperties(String key, String description) {
15+
this.key = key;
16+
this.description = description;
17+
}
18+
19+
}

jdbc-v2/src/main/java/com/clickhouse/jdbc/internal/JdbcConfiguration.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.clickhouse.jdbc.internal;
22

3+
import com.clickhouse.client.api.ClientConfigProperties;
34
import com.clickhouse.client.api.http.ClickHouseHttpProto;
45

56
import java.net.MalformedURLException;
@@ -12,6 +13,7 @@
1213
import java.util.List;
1314
import java.util.Map;
1415
import java.util.Properties;
16+
import java.util.concurrent.ConcurrentHashMap;
1517
import java.util.stream.Collectors;
1618

1719
public class JdbcConfiguration {
@@ -25,6 +27,8 @@ public class JdbcConfiguration {
2527
final String jdbcUrl;
2628
final boolean disableFrameworkDetection;
2729

30+
private final Map<String, String> allProperties;
31+
2832
public String getPassword() {
2933
return password;
3034
}
@@ -51,6 +55,8 @@ public JdbcConfiguration(String url, Properties info) {
5155
this.user = info.getProperty("user", "default");
5256
this.password = info.getProperty("password", "");
5357
this.disableFrameworkDetection = Boolean.parseBoolean(info.getProperty("disable_frameworks_detection", "false"));
58+
this.allProperties = new ConcurrentHashMap<>();
59+
info.forEach((k, v) -> allProperties.put(k.toString(), v.toString()));
5460
}
5561

5662
public static boolean acceptsURL(String url) {
@@ -82,4 +88,20 @@ private String stripUrlPrefix(String url) {
8288
throw new IllegalArgumentException("URL is not supported.");
8389
}
8490
}
91+
92+
/**
93+
* Returns a list of driver property information.
94+
* @return a list of driver property information for the driver
95+
*/
96+
public static List<DriverPropertyInfo> getDriverPropertyInfo(Properties userProvidedValues) {
97+
98+
List<DriverPropertyInfo> listOfProperties = new ArrayList<>(ClientConfigProperties.values().length);
99+
for (ClientConfigProperties clientProp : ClientConfigProperties.values()) {
100+
Object value = userProvidedValues.getOrDefault(clientProp.getKey(), "");
101+
DriverPropertyInfo info = new DriverPropertyInfo(clientProp.getKey(), String.valueOf(value));
102+
listOfProperties.add(info);
103+
}
104+
105+
return listOfProperties;
106+
}
85107
}

0 commit comments

Comments
 (0)