Skip to content

Commit 1911dbd

Browse files
authored
Merge pull request #942 from zhicwu/cli-client
Fix JDBC metadata issues
2 parents 1b7f056 + e61607f commit 1911dbd

File tree

7 files changed

+34
-17
lines changed

7 files changed

+34
-17
lines changed

.github/workflows/build.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ jobs:
8585
distribution: 'temurin'
8686
java-version: 8
8787
cache: 'maven'
88+
# or take below workaround as mentioned at https://github.com/actions/virtual-environments/issues/1499#issuecomment-689467080
89+
# -Dhttp.keepAlive=false -Dmaven.wagon.http.pool=false -Dmaven.wagon.httpconnectionManager.ttlSeconds=120
90+
- name: Check
91+
run: mvn --batch-mode --update-snapshots -Drelease -DskipTests install
8892
- name: Build
8993
run: |
9094
mvn --batch-mode --update-snapshots -Drelease -DclickhouseVersion=${{ matrix.clickhouse }} -Dprotocol=${{ matrix.protocol }} verify

clickhouse-benchmark/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
<clickhouse4j-driver.version>1.4.4</clickhouse4j-driver.version>
2121
<native-driver.version>2.6.5</native-driver.version>
2222
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
23-
<jmh.version>1.34</jmh.version>
23+
<jmh.version>1.35</jmh.version>
2424
<shade.name>benchmarks</shade.name>
2525
</properties>
2626

clickhouse-client/src/main/java/com/clickhouse/client/data/ClickHouseRowBinaryProcessor.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -547,8 +547,7 @@ protected List<ClickHouseColumn> readColumns() throws IOException {
547547
.getOption(ClickHouseClientOption.RENAME_RESPONSE_COLUMN);
548548
List<ClickHouseColumn> columns = new ArrayList<>(size);
549549
for (int i = 0; i < size; i++) {
550-
// a bit risky here - what if ClickHouse support user type?
551-
columns.add(ClickHouseColumn.of(m.rename(names[i]), input.readAsciiString()));
550+
columns.add(ClickHouseColumn.of(m.rename(names[i]), input.readUnicodeString()));
552551
}
553552

554553
return columns;

clickhouse-client/src/main/java/com/clickhouse/client/data/ClickHouseSimpleResponse.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public static ClickHouseResponse of(ClickHouseConfig config, List<ClickHouseColu
5252
public static ClickHouseResponse of(ClickHouseConfig config, List<ClickHouseColumn> columns, Object[][] values,
5353
ClickHouseResponseSummary summary) {
5454
if (columns == null || columns.isEmpty()) {
55-
return EMPTY;
55+
return ClickHouseResponse.EMPTY;
5656
}
5757

5858
int size = columns.size();

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

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
import com.clickhouse.client.ClickHouseParameterizedQuery;
2323
import com.clickhouse.client.ClickHouseUtils;
2424
import com.clickhouse.client.ClickHouseValues;
25+
import com.clickhouse.client.config.ClickHouseClientOption;
26+
import com.clickhouse.client.config.ClickHouseRenameMethod;
2527
import com.clickhouse.client.data.ClickHouseRecordTransformer;
2628
import com.clickhouse.client.data.ClickHouseSimpleResponse;
2729
import com.clickhouse.client.logging.Logger;
@@ -66,7 +68,9 @@ protected ResultSet query(String sql, ClickHouseRecordTransformer func, boolean
6668
ClickHouseStatement stmt = connection.createStatement();
6769
return new ClickHouseResultSet("", "", stmt,
6870
// load everything into memory
69-
ClickHouseSimpleResponse.of(stmt.getRequest().query(sql).execute().get(), func));
71+
ClickHouseSimpleResponse.of(stmt.getRequest()
72+
.option(ClickHouseClientOption.RENAME_RESPONSE_COLUMN, ClickHouseRenameMethod.NONE)
73+
.query(sql).execute().get(), func));
7074
} catch (InterruptedException e) {
7175
Thread.currentThread().interrupt();
7276
throw SqlExceptionUtils.forCancellation(e);
@@ -1255,19 +1259,23 @@ public ResultSet getClientInfoProperties() throws SQLException {
12551259
public ResultSet getFunctions(String catalog, String schemaPattern, String functionNamePattern)
12561260
throws SQLException {
12571261
Map<String, String> params = new HashMap<>();
1258-
params.put("filter", ClickHouseChecker.isNullOrEmpty(schemaPattern)
1259-
|| "system".contains(schemaPattern.toLowerCase(Locale.ROOT)) ? "1" : "0");
1262+
boolean systemSchema = ClickHouseChecker.isNullOrEmpty(schemaPattern);
1263+
if (!systemSchema) {
1264+
String schemaPatternLower = schemaPattern.toLowerCase(Locale.ROOT);
1265+
systemSchema = "system".contains(schemaPatternLower) || "information_schema".contains(schemaPatternLower);
1266+
}
1267+
params.put("filter", systemSchema ? "1" : "0");
12601268
params.put("pattern", ClickHouseChecker.isNullOrEmpty(functionNamePattern) ? "'%'"
12611269
: ClickHouseValues.convertToQuotedString(functionNamePattern));
12621270

12631271
String sql = ClickHouseParameterizedQuery.apply(
12641272
"select * from (select null as FUNCTION_CAT, 'system' as FUNCTION_SCHEM, name as FUNCTION_NAME,\n"
12651273
+ "concat('case-', case_insensitive ? 'in' : '', 'sensitive function', is_aggregate ? ' for aggregation' : '') as REMARKS,"
1266-
+ "1 as FUNCTION_TYPE, name as SPECIFIC_NAME from system.functions\n"
1267-
+ "where alias_to = '' and name like :pattern order by name union all\n"
1274+
+ "1 as FUNCTION_TYPE, name as SPECIFIC_NAME from system.functions where name like :pattern union all\n"
12681275
+ "select null as FUNCTION_CAT, 'system' as FUNCTION_SCHEM, name as FUNCTION_NAME,\n"
12691276
+ "'case-sensitive table function' as REMARKS, 2 as FUNCTION_TYPE, name as SPECIFIC_NAME from system.table_functions\n"
1270-
+ "order by name) where :filter",
1277+
+ "where name not in (select name from system.functions) and name like :pattern) where :filter\n"
1278+
+ "order by FUNCTION_CAT, FUNCTION_SCHEM, FUNCTION_NAME",
12711279
params);
12721280
return query(sql);
12731281
}

clickhouse-jdbc/src/main/java/com/clickhouse/jdbc/internal/ClickHouseConnectionImpl.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import com.clickhouse.client.ClickHouseValues;
4141
import com.clickhouse.client.ClickHouseVersion;
4242
import com.clickhouse.client.config.ClickHouseClientOption;
43+
import com.clickhouse.client.config.ClickHouseRenameMethod;
4344
import com.clickhouse.client.http.config.ClickHouseHttpOption;
4445
import com.clickhouse.client.logging.Logger;
4546
import com.clickhouse.client.logging.LoggerFactory;
@@ -65,7 +66,8 @@ public class ClickHouseConnectionImpl extends JdbcWrapper implements ClickHouseC
6566

6667
protected static ClickHouseRecord getServerInfo(ClickHouseNode node, ClickHouseRequest<?> request,
6768
boolean createDbIfNotExist) throws SQLException {
68-
ClickHouseRequest<?> newReq = request.copy();
69+
ClickHouseRequest<?> newReq = request.copy().option(ClickHouseClientOption.RENAME_RESPONSE_COLUMN,
70+
ClickHouseRenameMethod.NONE);
6971
if (!createDbIfNotExist) { // in case the database does not exist
7072
newReq.option(ClickHouseClientOption.DATABASE, "");
7173
}
@@ -189,6 +191,7 @@ protected List<ClickHouseColumn> getTableColumns(String dbName, String tableName
189191
builder.append('`').append(ClickHouseUtils.escape(tableName, '`')).append('`').append(" WHERE 0");
190192
List<ClickHouseColumn> list;
191193
try (ClickHouseResponse resp = clientRequest.copy().format(ClickHouseFormat.RowBinaryWithNamesAndTypes)
194+
.option(ClickHouseClientOption.RENAME_RESPONSE_COLUMN, ClickHouseRenameMethod.NONE)
192195
.query(builder.toString()).execute().get()) {
193196
list = resp.getColumns();
194197
} catch (InterruptedException e) {

clickhouse-jdbc/src/main/java/com/clickhouse/jdbc/internal/ClickHouseStatementImpl.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import com.clickhouse.client.ClickHouseResponse;
2424
import com.clickhouse.client.ClickHouseResponseSummary;
2525
import com.clickhouse.client.ClickHouseSerializer;
26+
import com.clickhouse.client.ClickHouseUtils;
2627
import com.clickhouse.client.ClickHouseValue;
2728
import com.clickhouse.client.config.ClickHouseClientOption;
2829
import com.clickhouse.client.config.ClickHouseConfigChangeListener;
@@ -123,18 +124,20 @@ protected ClickHouseResponse executeStatement(String stmt,
123124
}
124125
if (tables != null && !tables.isEmpty()) {
125126
List<ClickHouseExternalTable> list = new ArrayList<>(tables.size());
127+
char quote = '`';
126128
for (ClickHouseExternalTable t : tables) {
127129
if (t.isTempTable()) {
128130
if (!request.getSessionId().isPresent()) {
129131
request.session(UUID.randomUUID().toString());
130132
}
131-
request.query("drop temporary table if exists `" + t.getName() + "`").execute().get();
132-
request.query("create temporary table `" + t.getName() + "`(" + t.getStructure() + ")")
133-
.execute().get();
134-
request.write()
135-
.table(t.getName())
133+
String tableName = new StringBuilder().append(quote)
134+
.append(ClickHouseUtils.escape(t.getName(), quote)).append(quote).toString();
135+
request.query("drop temporary table if exists ".concat(tableName)).executeAndWait();
136+
request.query("create temporary table " + tableName + "(" + t.getStructure() + ")")
137+
.executeAndWait();
138+
request.write().table(tableName)
136139
// .format(t.getFormat() != null ? t.getFormat() : ClickHouseFormat.RowBinary)
137-
.data(t.getContent()).sendAndWait();
140+
.data(t.getContent()).send().get();
138141
} else {
139142
list.add(t);
140143
}

0 commit comments

Comments
 (0)