Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[jdbc] added some tests and fixes #1966

Open
wants to merge 18 commits into
base: main
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions clickhouse-jdbc/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,7 @@
<include>org.apache.httpcomponents.core5:httpcore5-h2</include>
<include>org.lz4:lz4-pure-java</include>
<include>com.clickhouse:jdbc-v2</include>
<include>com.clickhouse:client-v2</include>
</includes>
</artifactSet>
<relocations>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -773,15 +773,22 @@ public ResultSet getTables(String catalog, String schemaPattern, String tableNam
: ClickHouseValues.convertToQuotedString(tableNamePattern));
params.put("types", builder.toString());
String sql = ClickHouseParameterizedQuery
.apply("select :catalog as TABLE_CAT, :schema as TABLE_SCHEM, t.name as TABLE_NAME, "
.apply("select " +
":catalog as TABLE_CAT, " +
":schema as TABLE_SCHEM, " +
"t.name as TABLE_NAME, "
+ "case when t.engine like '%Log' then 'LOG TABLE' "
+ "when t.engine in ('Buffer', 'Memory', 'Set') then 'MEMORY TABLE' "
+ "when t.is_temporary != 0 then 'TEMPORARY TABLE' "
+ "when t.engine like '%View' then 'VIEW' when t.engine = 'Dictionary' then 'DICTIONARY' "
+ "when t.engine like 'Async%' or t.engine like 'System%' then 'SYSTEM TABLE' "
+ "when empty(t.data_paths) then 'REMOTE TABLE' else 'TABLE' end as TABLE_TYPE, "
+ ":comment as REMARKS, null as TYPE_CAT, d.engine as TYPE_SCHEM, "
+ "t.engine as TYPE_NAME, null as SELF_REFERENCING_COL_NAME, null as REF_GENERATION\n"
+ ":comment as REMARKS, " +
"null as TYPE_CAT, " +
"d.engine as TYPE_SCHEM, "
+ "t.engine as TYPE_NAME, " +
"null as SELF_REFERENCING_COL_NAME, " +
"null as REF_GENERATION\n"
+ "from system.tables t inner join system.databases d on t.database = d.name\n"
+ "where t.database like :database and t.name like :table and TABLE_TYPE in (:types) "
+ "order by t.database, t.name", params);
Expand Down Expand Up @@ -847,14 +854,30 @@ public ResultSet getColumns(String catalog, String schemaPattern, String tableNa
params.put("defaultNonNull", String.valueOf(DatabaseMetaData.typeNoNulls));
params.put("defaultType", String.valueOf(Types.OTHER));
String sql = ClickHouseParameterizedQuery
.apply("select :catalog as TABLE_CAT, :schema as TABLE_SCHEM, table as TABLE_NAME, "
+ "name as COLUMN_NAME, toInt32(:defaultType) as DATA_TYPE, type as TYPE_NAME, toInt32(0) as COLUMN_SIZE, "
+ "0 as BUFFER_LENGTH, cast(null as Nullable(Int32)) as DECIMAL_DIGITS, 10 as NUM_PREC_RADIX, "
+ "toInt32(position(type, 'Nullable(') >= 1 ? :defaultNullable : :defaultNonNull) as NULLABLE, :comment as REMARKS, default_expression as COLUMN_DEF, "
+ "0 as SQL_DATA_TYPE, 0 as SQL_DATETIME_SUB, cast(null as Nullable(Int32)) as CHAR_OCTET_LENGTH, position as ORDINAL_POSITION, "
+ "position(type, 'Nullable(') >= 1 ? 'YES' : 'NO' as IS_NULLABLE, null as SCOPE_CATALOG, null as SCOPE_SCHEMA, null as SCOPE_TABLE, "
+ "null as SOURCE_DATA_TYPE, 'NO' as IS_AUTOINCREMENT, 'NO' as IS_GENERATEDCOLUMN from system.columns "
+ "where database like :database and table like :table and name like :column", params);
.apply("select :catalog as TABLE_CAT, " +
":schema as TABLE_SCHEM, " +
"table as TABLE_NAME, " +
"name as COLUMN_NAME, " +
"toInt32(:defaultType) as DATA_TYPE, " +
"type as TYPE_NAME, " +
"toInt32(0) as COLUMN_SIZE, "
+ "0 as BUFFER_LENGTH, " +
"cast(null as Nullable(Int32)) as DECIMAL_DIGITS, " +
"10 as NUM_PREC_RADIX, "
+ "toInt32(position(type, 'Nullable(') >= 1 ? :defaultNullable : :defaultNonNull) as NULLABLE, " +
":comment as REMARKS, " +
"default_expression as COLUMN_DEF, "
+ "0 as SQL_DATA_TYPE, " +
"0 as SQL_DATETIME_SUB, " +
"cast(null as Nullable(Int32)) as CHAR_OCTET_LENGTH, " +
"position as ORDINAL_POSITION, "
+ "position(type, 'Nullable(') >= 1 ? 'YES' : 'NO' as IS_NULLABLE, " +
"null as SCOPE_CATALOG, null as SCOPE_SCHEMA, " +
"null as SCOPE_TABLE, " +
"null as SOURCE_DATA_TYPE, " +
"'NO' as IS_AUTOINCREMENT, " +
"'NO' as IS_GENERATEDCOLUMN " +
" FROM system.columns WHERE database LIKE :database and table LIKE :table AND name LIKE :column", params);
return query(sql, (i, r) -> {
String typeName = r.getValue("TYPE_NAME").asString();
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ public class ClickHouseDriver implements java.sql.Driver {
}

public ClickHouseDriver() {
log.debug("Creating a new instance of the 'proxy' ClickHouseDriver");
// log.debug("Creating a new instance of the 'proxy' ClickHouseDriver");
log.info("ClickHouse JDBC driver version: {}", ClickHouseDriver.class.getPackage().getImplementationVersion());
urlFlagSent = false;
this.driver = getDriver(null);
}
Expand Down Expand Up @@ -50,18 +51,18 @@ public boolean isV2(String url) {
log.debug("Checking if V2 driver is requested");
boolean v2Flag = Boolean.parseBoolean(System.getProperty("clickhouse.jdbc.v2", "false"));
if (v2Flag) {
log.debug("V2 driver is requested through system property.");
log.info("V2 driver is requested through system property.");
return true;
}

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

if (url.contains("clickhouse.jdbc.v2=true")) {
log.debug("V2 driver is requested through URL.");
log.info("V2 driver is requested through URL.");
return true;
} else {
log.debug("V1 driver is requested through URL.");
log.info("V1 driver is requested through URL.");
return false;
}
}
Expand All @@ -72,12 +73,15 @@ public boolean isV2(String url) {

private java.sql.Driver getDriver(String url) {
if (urlFlagSent && driver != null) {// if the URL flag was sent, we don't need to check the URL again

return driver;
}

if (isV2(url)) {
log.info("v2 driver");
driver = new com.clickhouse.jdbc.Driver();
} else {
log.info("v1 driver");
driver = new DriverV1();
}

Expand Down
4 changes: 4 additions & 0 deletions client-v2/src/main/java/com/clickhouse/client/api/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -2117,6 +2117,10 @@ public void setDBRoles(Collection<String> dbRoles) {
this.configuration.get(ClientConfigProperties.SESSION_DB_ROLES.getKey())));
}

public void updateClientName(String name) {
this.configuration.put(ClientConfigProperties.CLIENT_NAME.getKey(), name);
}

private Collection<String> unmodifiableDbRolesView = Collections.emptyList();

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ public enum ClientConfigProperties {

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


USE_HTTP_COMPRESSION("client.use_http_compression"),

COMPRESSION_LZ4_UNCOMPRESSED_BUF_SIZE("compression.lz4.uncompressed_buffer_size"),
Expand Down
52 changes: 10 additions & 42 deletions jdbc-v2/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +45,11 @@
<groupId>org.apache.httpcomponents.client5</groupId>
<artifactId>httpclient5</artifactId>
<version>${apache.httpclient.version}</version>
<exclusions>
<exclusion>
<groupId>org.apache.httpcomponents.core5</groupId>
<artifactId>httpcore5</artifactId>
</exclusion>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents.core5</groupId>
<artifactId>httpcore5</artifactId>
<version>${apache.httpclient.version}</version>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
</dependency>
<dependency>
<groupId>org.lz4</groupId>
Expand Down Expand Up @@ -91,6 +81,7 @@
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>${slf4j.version}</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down Expand Up @@ -225,43 +216,20 @@
<artifactSet>
<includes>
<include>com.clickhouse:clickhouse-data</include>
<include>com.google.code.gson:gson</include>
<include>com.google.guava:failureaccess</include>
<include>com.google.guava:guava</include>
<include>com.google.protobuf:protobuf-java</include>
<include>com.squareup.okio:okio</include>
<include>io.opencensus:opencensus-api</include>
<include>io.opencensus:opencensus-impl</include>
<include>io.opencensus:opencensus-impl-core</include>
<include>io.perfmark:perfmark-api</include>
<include>com.clickhouse:clickhouse-client</include>
<include>com.clickhouse:client-v2</include>
<include>org.apache.commons:commons-compress</include>
<include>org.apache.httpcomponents.client5:httpclient5</include>
<include>org.apache.httpcomponents.core5:httpcore5</include>
<include>org.apache.httpcomponents.core5:httpcore5-h2</include>
<include>com.fasterxml.jackson.core:jackson-core</include>
<include>org.roaringbitmap:RoaringBitmap</include>
<include>org.ow2.asm:asm</include>
<include>org.slf4j:slf4j-api</include>
<include>org.lz4:lz4-pure-java</include>
</includes>
</artifactSet>
<relocations>
<relocation>
<pattern>com.google</pattern>
<shadedPattern>${shade.base}.google</shadedPattern>
</relocation>
<relocation>
<pattern>io.opencensus</pattern>
<shadedPattern>${shade.base}.opencensus</shadedPattern>
</relocation>
<relocation>
<pattern>io.perfmark</pattern>
<shadedPattern>${shade.base}.perfmark</shadedPattern>
</relocation>
<relocation>
<pattern>net.jpountz</pattern>
<shadedPattern>${shade.base}.jpountz</shadedPattern>
</relocation>
<relocation>
<pattern>okio</pattern>
<shadedPattern>${shade.base}.okio</shadedPattern>
</relocation>
<relocation>
<pattern>org.apache</pattern>
<shadedPattern>${shade.base}.apache</shadedPattern>
Expand Down
Loading
Loading