Skip to content
Open
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: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
/target
/Cargo.lock
/.idea/.gitignore
/.idea/modules.xml
/.idea/snowflake-rs.iml
/.idea/vcs.xml
8 changes: 0 additions & 8 deletions Cargo.toml

This file was deleted.

60 changes: 26 additions & 34 deletions snowflake-api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ authors = ["Andrew Korzhuev <[email protected]>"]
categories = ["api-bindings", "database"]
description = "Snowflake API bindings"
documentation = "http://docs.rs/sqlite-api/"
edition = "2021"
edition = "2024"
keywords = ["api", "database", "snowflake"]
license = "Apache-2.0"
name = "snowflake-api"
Expand All @@ -19,42 +19,34 @@ default = ["cert-auth"]
polars = ["dep:polars-core", "dep:polars-io"]

[dependencies]
arrow = "53"
async-trait = "0.1"
base64 = "0.22"
bytes = "1"
futures = "0.3"
log = "0.4"
regex = "1"
reqwest = { version = "0.12", default-features = false, features = [
"gzip",
"json",
"rustls-tls",
] }
reqwest-middleware = { version = "0.3", features = ["json"] }
reqwest-retry = "0.6"
serde = { version = "1", features = ["derive"] }
serde_json = "1"
snowflake-jwt = { version = "0.3", optional = true }
thiserror = "1"
url = "2"
uuid = { version = "1", features = ["v4"] }
anyhow = { workspace = true }
arrow = { workspace = true }
async-trait = { workspace = true }
base64 = { workspace = true }
bytes = { workspace = true }
clap = { workspace = true }
futures = { workspace = true }
log = { workspace = true }
regex = { workspace = true }
reqwest = { workspace = true }
reqwest-middleware = { workspace = true }
reqwest-retry = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
snowflake-jwt = { workspace = true, optional = true }
thiserror = { workspace = true }
url = { workspace = true }
uuid = { workspace = true }

# polars-support
polars-core = { version = ">=0.32", optional = true }
polars-io = { version = ">=0.32", features = [
"json",
"ipc_streaming",
], optional = true }
polars-core = { optional = true, version = "0.46.0" }
polars-io = { optional = true, version = ">=0.32", features = ["json", "ipc_streaming"] }

# put request support
glob = { version = "0.3" }
object_store = { version = "0.11", features = ["aws"] }
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }
glob = { workspace = true }
object_store = { workspace = true }
tokio = { workspace = true }
flate2 = { workspace = true }

[dev-dependencies]
anyhow = "1"
arrow = { version = "53", features = ["prettyprint"] }
clap = { version = "4", features = ["derive"] }
pretty_env_logger = "0.5"
tokio = { version = "1.35", features = ["macros", "rt-multi-thread"] }
pretty_env_logger = "0.5"
35 changes: 30 additions & 5 deletions snowflake-api/src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ use thiserror::Error;
use url::Url;
use uuid::Uuid;

use std::io::Read;
use flate2::bufread::GzDecoder;
use bytes;

#[derive(Error, Debug)]
pub enum ConnectionError {
#[error(transparent)]
Expand Down Expand Up @@ -75,6 +79,12 @@ pub struct Connection {
client: ClientWithMiddleware,
}

impl std::fmt::Debug for Connection {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("Connection").finish()
}
}

impl Connection {
pub fn new() -> Result<Self, ConnectionError> {
let client = Self::default_client_builder()?;
Expand Down Expand Up @@ -126,8 +136,8 @@ impl Connection {
) -> Result<R, ConnectionError> {
let context = query_type.query_context();

let request_id = Uuid::new_v4();
let request_guid = Uuid::new_v4();
let request_id = Uuid::now_v7();
let request_guid = Uuid::now_v7();
let client_start_time = SystemTime::now()
.duration_since(UNIX_EPOCH)
.unwrap()
Expand Down Expand Up @@ -183,7 +193,7 @@ impl Connection {
for (k, v) in headers {
header_map.insert(
HeaderName::from_bytes(k.as_bytes()).unwrap(),
HeaderValue::from_bytes(v.as_bytes()).unwrap(),
HeaderValue::from_bytes(v.as_bytes())?,
);
}
let bytes = self
Expand All @@ -193,7 +203,22 @@ impl Connection {
.send()
.await?
.bytes()
.await?;
Ok(bytes)
.await;

match bytes {
Ok(bytes) => {
// convert from gzip to Bytes
let mut gz = GzDecoder::new(&bytes[..]);
let mut decoded_bytes = Vec::new();
gz.read_to_end(&mut decoded_bytes).expect("Failed to decode bytes");
let decoded = bytes::Bytes::copy_from_slice(&decoded_bytes);

Ok(decoded)
}
Err(e) => {
Err(ConnectionError::RequestError(e))
}
}

}
}
Loading