Skip to content

Commit e8479d9

Browse files
authored
Merge pull request #1966 from ClickHouse/jdbc_testing_dbeaver
[jdbc] added some tests and fixes
2 parents 6c413e7 + 2714c11 commit e8479d9

24 files changed

+852
-362
lines changed

clickhouse-jdbc/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,7 @@
381381
<include>org.apache.httpcomponents.core5:httpcore5-h2</include>
382382
<include>org.lz4:lz4-pure-java</include>
383383
<include>com.clickhouse:jdbc-v2</include>
384+
<include>com.clickhouse:client-v2</include>
384385
</includes>
385386
</artifactSet>
386387
<relocations>

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

Lines changed: 34 additions & 11 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);
@@ -847,14 +854,30 @@ public ResultSet getColumns(String catalog, String schemaPattern, String tableNa
847854
params.put("defaultNonNull", String.valueOf(DatabaseMetaData.typeNoNulls));
848855
params.put("defaultType", String.valueOf(Types.OTHER));
849856
String sql = ClickHouseParameterizedQuery
850-
.apply("select :catalog as TABLE_CAT, :schema as TABLE_SCHEM, table as TABLE_NAME, "
851-
+ "name as COLUMN_NAME, toInt32(:defaultType) as DATA_TYPE, type as TYPE_NAME, toInt32(0) as COLUMN_SIZE, "
852-
+ "0 as BUFFER_LENGTH, cast(null as Nullable(Int32)) as DECIMAL_DIGITS, 10 as NUM_PREC_RADIX, "
853-
+ "toInt32(position(type, 'Nullable(') >= 1 ? :defaultNullable : :defaultNonNull) as NULLABLE, :comment as REMARKS, default_expression as COLUMN_DEF, "
854-
+ "0 as SQL_DATA_TYPE, 0 as SQL_DATETIME_SUB, cast(null as Nullable(Int32)) as CHAR_OCTET_LENGTH, position as ORDINAL_POSITION, "
855-
+ "position(type, 'Nullable(') >= 1 ? 'YES' : 'NO' as IS_NULLABLE, null as SCOPE_CATALOG, null as SCOPE_SCHEMA, null as SCOPE_TABLE, "
856-
+ "null as SOURCE_DATA_TYPE, 'NO' as IS_AUTOINCREMENT, 'NO' as IS_GENERATEDCOLUMN from system.columns "
857-
+ "where database like :database and table like :table and name like :column", params);
857+
.apply("select :catalog as TABLE_CAT, " +
858+
":schema as TABLE_SCHEM, " +
859+
"table as TABLE_NAME, " +
860+
"name as COLUMN_NAME, " +
861+
"toInt32(:defaultType) as DATA_TYPE, " +
862+
"type as TYPE_NAME, " +
863+
"toInt32(0) as COLUMN_SIZE, "
864+
+ "0 as BUFFER_LENGTH, " +
865+
"cast(null as Nullable(Int32)) as DECIMAL_DIGITS, " +
866+
"10 as NUM_PREC_RADIX, "
867+
+ "toInt32(position(type, 'Nullable(') >= 1 ? :defaultNullable : :defaultNonNull) as NULLABLE, " +
868+
":comment as REMARKS, " +
869+
"default_expression as COLUMN_DEF, "
870+
+ "0 as SQL_DATA_TYPE, " +
871+
"0 as SQL_DATETIME_SUB, " +
872+
"cast(null as Nullable(Int32)) as CHAR_OCTET_LENGTH, " +
873+
"position as ORDINAL_POSITION, "
874+
+ "position(type, 'Nullable(') >= 1 ? 'YES' : 'NO' as IS_NULLABLE, " +
875+
"null as SCOPE_CATALOG, null as SCOPE_SCHEMA, " +
876+
"null as SCOPE_TABLE, " +
877+
"null as SOURCE_DATA_TYPE, " +
878+
"'NO' as IS_AUTOINCREMENT, " +
879+
"'NO' as IS_GENERATEDCOLUMN " +
880+
" FROM system.columns WHERE database LIKE :database and table LIKE :table AND name LIKE :column", params);
858881
return query(sql, (i, r) -> {
859882
String typeName = r.getValue("TYPE_NAME").asString();
860883
try {

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ public class ClickHouseDriver implements java.sql.Driver {
1919
}
2020

2121
public ClickHouseDriver() {
22-
log.debug("Creating a new instance of the 'proxy' ClickHouseDriver");
22+
// log.debug("Creating a new instance of the 'proxy' ClickHouseDriver");
23+
log.info("ClickHouse JDBC driver version: {}", ClickHouseDriver.class.getPackage().getImplementationVersion());
2324
urlFlagSent = false;
2425
this.driver = getDriver(null);
2526
}
@@ -50,18 +51,18 @@ public boolean isV2(String url) {
5051
log.debug("Checking if V2 driver is requested");
5152
boolean v2Flag = Boolean.parseBoolean(System.getProperty("clickhouse.jdbc.v2", "false"));
5253
if (v2Flag) {
53-
log.debug("V2 driver is requested through system property.");
54+
log.info("V2 driver is requested through system property.");
5455
return true;
5556
}
5657

5758
if (url != null && url.contains("clickhouse.jdbc.v2")) {
5859
urlFlagSent = true;
5960

6061
if (url.contains("clickhouse.jdbc.v2=true")) {
61-
log.debug("V2 driver is requested through URL.");
62+
log.info("V2 driver is requested through URL.");
6263
return true;
6364
} else {
64-
log.debug("V1 driver is requested through URL.");
65+
log.info("V1 driver is requested through URL.");
6566
return false;
6667
}
6768
}
@@ -72,12 +73,15 @@ public boolean isV2(String url) {
7273

7374
private java.sql.Driver getDriver(String url) {
7475
if (urlFlagSent && driver != null) {// if the URL flag was sent, we don't need to check the URL again
76+
7577
return driver;
7678
}
7779

7880
if (isV2(url)) {
81+
log.info("v2 driver");
7982
driver = new com.clickhouse.jdbc.Driver();
8083
} else {
84+
log.info("v1 driver");
8185
driver = new DriverV1();
8286
}
8387

client-v2/src/main/java/com/clickhouse/client/api/Client.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2117,6 +2117,10 @@ public void setDBRoles(Collection<String> dbRoles) {
21172117
this.configuration.get(ClientConfigProperties.SESSION_DB_ROLES.getKey())));
21182118
}
21192119

2120+
public void updateClientName(String name) {
2121+
this.configuration.put(ClientConfigProperties.CLIENT_NAME.getKey(), name);
2122+
}
2123+
21202124
private Collection<String> unmodifiableDbRolesView = Collections.emptyList();
21212125

21222126
/**

client-v2/src/main/java/com/clickhouse/client/api/ClientConfigProperties.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ public enum ClientConfigProperties {
6565

6666
COMPRESS_CLIENT_REQUEST("decompress"), // actually a server setting, but has client effect too
6767

68-
6968
USE_HTTP_COMPRESSION("client.use_http_compression"),
7069

7170
COMPRESSION_LZ4_UNCOMPRESSED_BUF_SIZE("compression.lz4.uncompressed_buffer_size"),

jdbc-v2/pom.xml

Lines changed: 10 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -45,21 +45,11 @@
4545
<groupId>org.apache.httpcomponents.client5</groupId>
4646
<artifactId>httpclient5</artifactId>
4747
<version>${apache.httpclient.version}</version>
48-
<exclusions>
49-
<exclusion>
50-
<groupId>org.apache.httpcomponents.core5</groupId>
51-
<artifactId>httpcore5</artifactId>
52-
</exclusion>
53-
<exclusion>
54-
<groupId>org.slf4j</groupId>
55-
<artifactId>slf4j-api</artifactId>
56-
</exclusion>
57-
</exclusions>
5848
</dependency>
5949
<dependency>
60-
<groupId>org.apache.httpcomponents.core5</groupId>
61-
<artifactId>httpcore5</artifactId>
62-
<version>${apache.httpclient.version}</version>
50+
<groupId>org.slf4j</groupId>
51+
<artifactId>slf4j-api</artifactId>
52+
<version>${slf4j.version}</version>
6353
</dependency>
6454
<dependency>
6555
<groupId>org.lz4</groupId>
@@ -91,6 +81,7 @@
9181
<dependency>
9282
<groupId>org.slf4j</groupId>
9383
<artifactId>slf4j-simple</artifactId>
84+
<version>${slf4j.version}</version>
9485
<scope>test</scope>
9586
</dependency>
9687
<dependency>
@@ -225,43 +216,20 @@
225216
<artifactSet>
226217
<includes>
227218
<include>com.clickhouse:clickhouse-data</include>
228-
<include>com.google.code.gson:gson</include>
229-
<include>com.google.guava:failureaccess</include>
230-
<include>com.google.guava:guava</include>
231-
<include>com.google.protobuf:protobuf-java</include>
232-
<include>com.squareup.okio:okio</include>
233-
<include>io.opencensus:opencensus-api</include>
234-
<include>io.opencensus:opencensus-impl</include>
235-
<include>io.opencensus:opencensus-impl-core</include>
236-
<include>io.perfmark:perfmark-api</include>
219+
<include>com.clickhouse:clickhouse-client</include>
220+
<include>com.clickhouse:client-v2</include>
237221
<include>org.apache.commons:commons-compress</include>
238222
<include>org.apache.httpcomponents.client5:httpclient5</include>
239223
<include>org.apache.httpcomponents.core5:httpcore5</include>
240224
<include>org.apache.httpcomponents.core5:httpcore5-h2</include>
225+
<include>com.fasterxml.jackson.core:jackson-core</include>
226+
<include>org.roaringbitmap:RoaringBitmap</include>
227+
<include>org.ow2.asm:asm</include>
228+
<include>org.slf4j:slf4j-api</include>
241229
<include>org.lz4:lz4-pure-java</include>
242230
</includes>
243231
</artifactSet>
244232
<relocations>
245-
<relocation>
246-
<pattern>com.google</pattern>
247-
<shadedPattern>${shade.base}.google</shadedPattern>
248-
</relocation>
249-
<relocation>
250-
<pattern>io.opencensus</pattern>
251-
<shadedPattern>${shade.base}.opencensus</shadedPattern>
252-
</relocation>
253-
<relocation>
254-
<pattern>io.perfmark</pattern>
255-
<shadedPattern>${shade.base}.perfmark</shadedPattern>
256-
</relocation>
257-
<relocation>
258-
<pattern>net.jpountz</pattern>
259-
<shadedPattern>${shade.base}.jpountz</shadedPattern>
260-
</relocation>
261-
<relocation>
262-
<pattern>okio</pattern>
263-
<shadedPattern>${shade.base}.okio</shadedPattern>
264-
</relocation>
265233
<relocation>
266234
<pattern>org.apache</pattern>
267235
<shadedPattern>${shade.base}.apache</shadedPattern>

0 commit comments

Comments
 (0)