Skip to content

Commit

Permalink
SNOW-1452649 update dependency to httpclient library to support zstd
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-dbouassida committed Jun 6, 2024
1 parent d84639c commit b2a52a0
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 17 deletions.
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 {
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

0 comments on commit b2a52a0

Please sign in to comment.