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

SNOW-1452649 update dependency to httpclient library to support zstd #1783

Closed
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
4 changes: 2 additions & 2 deletions parent-pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<apache.commons.compress.version>1.21</apache.commons.compress.version>
<apache.commons.lang3.version>3.12.0</apache.commons.lang3.version>
<apache.commons.text.version>1.10.0</apache.commons.text.version>
<apache.httpclient.version>4.5.14</apache.httpclient.version>
<apache.httpclient.version>4.5.17</apache.httpclient.version>
<apache.httpcore.version>4.4.16</apache.httpcore.version>
<arrow.version>10.0.1</arrow.version>
<asm.version>9.3</asm.version>
Expand Down Expand Up @@ -318,7 +318,7 @@
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>${apache.httpclient.version}</version>
<version>4.5.17</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

import static net.snowflake.client.core.Constants.MB;

import com.github.luben.zstd.ZstdInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PushbackInputStream;
import java.net.URISyntaxException;
import java.util.Map;
import java.util.zip.GZIPInputStream;
import java.util.zip.ZipException;
import net.snowflake.client.core.ExecTimeTelemetryData;
import net.snowflake.client.core.HttpUtil;
import net.snowflake.client.log.ArgSupplier;
Expand Down Expand Up @@ -142,6 +144,23 @@ else if (context.getQrmk() != null) {
return response;
}

public static InputStream detectGzipAndGetStream(InputStream is) throws IOException {
try {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we might even not need this, as the is comes wrapped in the correct decmpressor. this is handeled at the http client level.

PushbackInputStream pb = new PushbackInputStream(is, 2);
byte[] signature = new byte[2];
int len = pb.read(signature);
pb.unread(signature, 0, len);
// https://tools.ietf.org/html/rfc1952
if (signature[0] == (byte) 0x1f && signature[1] == (byte) 0x8b) {
return new GZIPInputStream(pb);
} else {
return pb;
}
} catch (ZipException e) {
return new ZstdInputStream(is);
}
}

private InputStream detectContentEncodingAndGetInputStream(HttpResponse response, InputStream is)
throws IOException, SnowflakeSQLException {
InputStream inputStream = is; // Determine the format of the response, if it is not
Expand All @@ -151,6 +170,9 @@ private InputStream detectContentEncodingAndGetInputStream(HttpResponse response
if ("gzip".equalsIgnoreCase(encoding.getValue())) {
/* specify buffer size for GZIPInputStream */
inputStream = new GZIPInputStream(is, STREAM_BUFFER_SIZE);
} else if ("zstd".equalsIgnoreCase(encoding.getValue())) {
/* specify buffer size for GZIPInputStream */
inputStream = new ZstdInputStream(is);
} else {
throw new SnowflakeSQLException(
SqlState.INTERNAL_ERROR,
Expand All @@ -163,17 +185,4 @@ private InputStream detectContentEncodingAndGetInputStream(HttpResponse response

return inputStream;
}

public static InputStream detectGzipAndGetStream(InputStream is) throws IOException {
PushbackInputStream pb = new PushbackInputStream(is, 2);
byte[] signature = new byte[2];
int len = pb.read(signature);
pb.unread(signature, 0, len);
// https://tools.ietf.org/html/rfc1952
if (signature[0] == (byte) 0x1f && signature[1] == (byte) 0x8b) {
return new GZIPInputStream(pb);
} else {
return pb;
}
}
}
4 changes: 2 additions & 2 deletions thin_public_pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
</scm>

<properties>
<apache.httpclient.version>4.5.14</apache.httpclient.version>
<apache.httpclient.version>4.5.17</apache.httpclient.version>
<apache.httpcore.version>4.4.16</apache.httpcore.version>
<awssdk.version>1.12.501</awssdk.version>
<azure.storage.version>5.0.0</azure.storage.version>
Expand Down Expand Up @@ -239,7 +239,7 @@
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>${apache.httpclient.version}</version>
<version>4.5.17</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
Expand Down
Loading