Skip to content

Commit

Permalink
Fix build break
Browse files Browse the repository at this point in the history
  • Loading branch information
zhicwu committed Nov 28, 2021
1 parent afbb426 commit 8bd979b
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ protected String buildQueryParams(Map<String, String> params) {

StringBuilder builder = new StringBuilder();
for (Map.Entry<String, String> entry : params.entrySet()) {
builder.append(URLEncoder.encode(entry.getKey(), StandardCharsets.UTF_8)).append('=')
.append(URLEncoder.encode(entry.getValue(), StandardCharsets.UTF_8)).append('&');
builder.append(ClickHouseHttpConnection.urlEncode(entry.getKey(), StandardCharsets.UTF_8)).append('=')
.append(ClickHouseHttpConnection.urlEncode(entry.getValue(), StandardCharsets.UTF_8)).append('&');
}

if (builder.length() > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.Collections;
import java.util.LinkedHashMap;
Expand All @@ -30,9 +32,18 @@
public abstract class ClickHouseHttpConnection implements AutoCloseable {
protected static final int DEFAULT_BUFFER_SIZE = 8192;

static String urlEncode(String str, Charset charset) {
try {
return URLEncoder.encode(str, StandardCharsets.UTF_8.name());
} catch (UnsupportedEncodingException e) {
// should not happen
throw new IllegalArgumentException(e);
}
}

private static StringBuilder appendQueryParameter(StringBuilder builder, String key, String value) {
return builder.append(URLEncoder.encode(key, StandardCharsets.UTF_8)).append('=')
.append(URLEncoder.encode(value, StandardCharsets.UTF_8)).append('&');
return builder.append(urlEncode(key, StandardCharsets.UTF_8)).append('=')
.append(urlEncode(value, StandardCharsets.UTF_8)).append('&');
}

static String buildQueryParams(ClickHouseRequest<?> request) {
Expand Down Expand Up @@ -207,15 +218,15 @@ protected OutputStream getRequestOutputStream(OutputStream out) throws IOExcepti
// TODO support more algorithms
ClickHouseCompression algorithm = config.getDecompressAlgorithmForClientRequest();
switch (algorithm) {
case GZIP:
out = new GZIPOutputStream(out, (int) config.getOption(ClickHouseClientOption.MAX_COMPRESS_BLOCK_SIZE));
break;
case LZ4:
out = new ClickHouseLZ4OutputStream(out,
(int) config.getOption(ClickHouseClientOption.MAX_COMPRESS_BLOCK_SIZE));
break;
default:
throw new UnsupportedOperationException("Unsupported compression algorithm: " + algorithm);
case GZIP:
out = new GZIPOutputStream(out, (int) config.getOption(ClickHouseClientOption.MAX_COMPRESS_BLOCK_SIZE));
break;
case LZ4:
out = new ClickHouseLZ4OutputStream(out,
(int) config.getOption(ClickHouseClientOption.MAX_COMPRESS_BLOCK_SIZE));
break;
default:
throw new UnsupportedOperationException("Unsupported compression algorithm: " + algorithm);
}
return out;
}
Expand All @@ -228,14 +239,14 @@ protected InputStream getResponseInputStream(InputStream in) throws IOException
// TODO support more algorithms
ClickHouseCompression algorithm = config.getCompressAlgorithmForServerResponse();
switch (algorithm) {
case GZIP:
in = new GZIPInputStream(in);
break;
case LZ4:
in = new ClickHouseLZ4InputStream(in);
break;
default:
throw new UnsupportedOperationException("Unsupported compression algorithm: " + algorithm);
case GZIP:
in = new GZIPInputStream(in);
break;
case LZ4:
in = new ClickHouseLZ4InputStream(in);
break;
default:
throw new UnsupportedOperationException("Unsupported compression algorithm: " + algorithm);
}
return in;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,9 @@ public void testMultipleQueries() throws Exception {
try (ClickHouseClient client = ClickHouseClient.newInstance()) {
ClickHouseRequest<?> req = client.connect(server).format(ClickHouseFormat.RowBinaryWithNamesAndTypes);

ClickHouseResponse queryResp = req.copy().query("select * from system.query_log").execute().get();

try (ClickHouseResponse resp = req.copy().query("select 1").execute().get()) {
ClickHouseResponse queryResp = req.copy().query("select 1").execute().get();

try (ClickHouseResponse resp = req.copy().query("select 2").execute().get()) {
}

for (ClickHouseRecord r : queryResp.records()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import org.testng.annotations.Test;

public class ClickHouseStatementTest extends JdbcIntegrationTest {
@Test(groups = "integration")
@Test(groups = "local")
public void testLogComment() throws SQLException {
Properties props = new Properties();
props.setProperty(ClickHouseClientOption.LOG_LEADING_COMMENT.getKey(), "true");
Expand Down Expand Up @@ -60,7 +60,7 @@ public void testQuery() throws SQLException {
try (ClickHouseConnection conn = newConnection(new Properties())) {
ClickHouseStatement stmt = conn.createStatement();
stmt.setMaxRows(10);
ResultSet rs = stmt.executeQuery("select * from system.query_log");
ResultSet rs = stmt.executeQuery("select * from numbers(100)");

try (ResultSet colRs = conn.getMetaData().getColumns(null, "system", "query_log", "")) {
while (colRs.next()) {
Expand Down

0 comments on commit 8bd979b

Please sign in to comment.