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

clean up code and remove unnecessary dependency #1204

Merged
merged 8 commits into from
Jan 27, 2023
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ public void blocking(CompareState state, Blackhole consumer) throws Exception {
// options.put(ClickHouseClientOption.SOCKET_TIMEOUT, 0);
options.put(ClickHouseClientOption.USE_BLOCKING_QUEUE, false);
final ClickHouseConfig config = new ClickHouseConfig(options);
final ClickHousePipedOutputStream stream = ClickHouseDataStreamFactory.getInstance().createPipedOutputStream(
config, null);
final ClickHousePipedOutputStream stream = ClickHouseDataStreamFactory.getInstance()
.createPipedOutputStream(config);
CompletableFuture<Long> future = ClickHouseClient.submit(() -> {
long range = state.samples;
try (ClickHouseOutputStream out = stream) {
Expand All @@ -99,8 +99,8 @@ public void blocking(CompareState state, Blackhole consumer) throws Exception {
public void nonBlocking(CompareState state, Blackhole consumer) throws Exception {
final ClickHouseConfig config = new ClickHouseConfig(Collections
.singletonMap(ClickHouseClientOption.RESPONSE_BUFFERING, ClickHouseBufferingMode.PERFORMANCE));
final ClickHousePipedOutputStream stream = ClickHouseDataStreamFactory.getInstance().createPipedOutputStream(
config, null);
final ClickHousePipedOutputStream stream = ClickHouseDataStreamFactory.getInstance()
.createPipedOutputStream(config);
CompletableFuture<Long> future = ClickHouseClient.submit(() -> {
long range = state.samples;
try (ClickHouseOutputStream out = stream) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import com.clickhouse.client.config.ClickHouseSslMode;
import com.clickhouse.data.ClickHouseChecker;
import com.clickhouse.data.ClickHouseCompression;
import com.clickhouse.data.ClickHouseDataConfig;
import com.clickhouse.data.ClickHouseExternalTable;
import com.clickhouse.data.ClickHouseFile;
import com.clickhouse.data.ClickHouseInputStream;
Expand Down Expand Up @@ -193,9 +194,6 @@ static Process startProcess(ClickHouseRequest<?> request) {
final ClickHouseNode server = request.getServer();
final int timeout = config.getSocketTimeout();

// FIXME potential timing issue
final Optional<ClickHouseInputStream> in = request.getInputStream();

String hostDir = config.getStrOption(ClickHouseCommandLineOption.CLI_WORK_DIRECTORY);
hostDir = ClickHouseUtils.normalizeDirectory(
ClickHouseChecker.isNullOrBlank(hostDir) ? System.getProperty("java.io.tmpdir") : hostDir);
Expand Down Expand Up @@ -343,9 +341,9 @@ static Process startProcess(ClickHouseRequest<?> request) {

if (request.hasOutputStream()) {
final ClickHouseOutputStream chOutput = request.getOutputStream().get(); // NOSONAR
final ClickHousePassThruStream customStream = chOutput.getUnderlyingStream();

if (customStream.hasOutput()) {
if (chOutput.hasUnderlyingStream()) {
final ClickHousePassThruStream customStream = chOutput.getUnderlyingStream();
File f = customStream instanceof ClickHouseFile ? ((ClickHouseFile) customStream).getFile() : null;
if (f == null) {
throw new UncheckedIOException(new IOException("Output file not found in " + customStream));
Expand Down Expand Up @@ -385,14 +383,15 @@ static Process startProcess(ClickHouseRequest<?> request) {
builder.redirectOutput(f);
}
}


final Optional<ClickHouseInputStream> in = request.getInputStream();
try {
final Process process;
if (in.isPresent()) {
final ClickHouseInputStream chInput = in.get();
final ClickHousePassThruStream customStream = chInput.getUnderlyingStream();
final File inputFile;
if (customStream.hasInput()) {
if (chInput.hasUnderlyingStream()) {
final ClickHousePassThruStream customStream = chInput.getUnderlyingStream();
inputFile = customStream instanceof ClickHouseFile ? ((ClickHouseFile) customStream).getFile()
: ClickHouseFile.of(customStream.getInputStream(), config.getRequestCompressAlgorithm(),
config.getRequestCompressLevel(), config.getFormat()).getFile();
Expand Down Expand Up @@ -434,12 +433,12 @@ public ClickHouseInputStream getInputStream() throws IOException {
throw new UncheckedIOException(exp);
}
};
if (out != null && !out.getUnderlyingStream().hasOutput()) {
if (out != null && !out.hasUnderlyingStream()) {
try (OutputStream o = out) {
ClickHouseInputStream.pipe(process.getInputStream(), o, c.getWriteBufferSize());
}
return ClickHouseInputStream.wrap(null, ClickHouseInputStream.empty(), c.getReadBufferSize(),
ClickHouseCompression.NONE, -1, postCloseAction);
ClickHouseCompression.NONE, ClickHouseDataConfig.DEFAULT_READ_COMPRESS_LEVEL, postCloseAction);
} else {
return ClickHouseInputStream.of(process.getInputStream(), c.getReadBufferSize(), postCloseAction);
}
Expand Down
11 changes: 6 additions & 5 deletions clickhouse-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,12 @@
<groupId>dnsjava</groupId>
<artifactId>dnsjava</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<optional>true</optional>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
</exclusions>
</dependency>

<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ public ClickHouseInputStream send(ClickHouseConfig config, ClickHouseInputStream
}

ClickHousePipedOutputStream responeStream = ClickHouseDataStreamFactory.getInstance()
.createPipedOutputStream(ClickHouseChecker.nonNull(config, ClickHouseConfig.TYPE_NAME), null);
.createPipedOutputStream(ClickHouseChecker.nonNull(config, ClickHouseConfig.TYPE_NAME));
processRequest(config, rawRequest, responeStream);
return responeStream.getInputStream();
}
Expand Down
Loading