diff --git a/cli/src/args.rs b/cli/src/args.rs index 78600db0..fb8e4c5c 100644 --- a/cli/src/args.rs +++ b/cli/src/args.rs @@ -15,7 +15,7 @@ use std::collections::BTreeMap; use anyhow::{anyhow, Result}; -use databend_client::auth::SensitiveString; +use databend_client::SensitiveString; use percent_encoding::{percent_decode_str, utf8_percent_encode, NON_ALPHANUMERIC}; #[derive(Debug, Clone, PartialEq, Default)] diff --git a/cli/src/main.rs b/cli/src/main.rs index 0a313845..c063ba41 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -30,7 +30,7 @@ use std::{ use anyhow::{anyhow, Result}; use clap::{ArgAction, CommandFactory, Parser, ValueEnum}; -use databend_client::auth::SensitiveString; +use databend_client::SensitiveString; use log::info; use once_cell::sync::Lazy; @@ -373,7 +373,7 @@ pub async fn main() -> Result<()> { // Exit client if user login failed. if let Some(error) = err.downcast_ref::() { match error { - databend_driver::Error::Api(databend_client::error::Error::AuthFailure(_)) => { + databend_driver::Error::Api(databend_client::Error::AuthFailure(_)) => { println!("Authenticate failed wrong password user {}", user); return Ok(()); } diff --git a/cli/src/session.rs b/cli/src/session.rs index 1e710082..1701501b 100644 --- a/cli/src/session.rs +++ b/cli/src/session.rs @@ -105,9 +105,7 @@ impl Session { Ok(version) => version, Err(err) => { match err { - databend_driver::Error::Api( - databend_client::error::Error::AuthFailure(_), - ) => { + databend_driver::Error::Api(databend_client::Error::AuthFailure(_)) => { return Err(err.into()); } databend_driver::Error::Arrow(arrow::error::ArrowError::IpcError( @@ -119,7 +117,7 @@ impl Session { return Err(err.into()); } } - databend_driver::Error::Api(databend_client::error::Error::Request( + databend_driver::Error::Api(databend_client::Error::Request( ref resp_err, )) => { if resp_err.contains("error sending request for url") { diff --git a/core/src/client.rs b/core/src/client.rs index 4ac6f393..8e7f13bd 100644 --- a/core/src/client.rs +++ b/core/src/client.rs @@ -60,10 +60,10 @@ static VERSION: Lazy = Lazy::new(|| { #[derive(Clone)] pub struct APIClient { - pub cli: HttpClient, - pub scheme: String, - pub host: String, - pub port: u16, + cli: HttpClient, + scheme: String, + host: String, + port: u16, endpoint: Url, @@ -231,6 +231,14 @@ impl APIClient { Ok(client) } + pub fn host(&self) -> &str { + self.host.as_str() + } + + pub fn port(&self) -> u16 { + self.port + } + async fn build_client(&mut self, name: Option) -> Result<()> { let ua = match name { Some(n) => n, @@ -309,7 +317,7 @@ impl APIClient { uuid::Uuid::new_v4().to_string() } - pub async fn handle_session(&self, session: &Option) { + async fn handle_session(&self, session: &Option) { let session = match session { Some(session) => session, None => return, @@ -333,11 +341,11 @@ impl APIClient { pub fn set_last_node_id(&self, node_id: String) { *self.last_node_id.lock() = Some(node_id) } - pub fn last_node_id(&self) -> Option { + fn last_node_id(&self) -> Option { self.last_node_id.lock().clone() } - pub fn handle_warnings(&self, resp: &QueryResponse) { + fn handle_warnings(&self, resp: &QueryResponse) { if let Some(warnings) = &resp.warnings { for w in warnings { warn!(target: "server_warnings", "server warning: {}", w); @@ -437,7 +445,8 @@ impl APIClient { } } - pub async fn kill_query(&self, query_id: &str, kill_uri: &str) -> Result<()> { + #[allow(dead_code)] + async fn kill_query(&self, query_id: &str, kill_uri: &str) -> Result<()> { info!("kill query: {}", kill_uri); let endpoint = self.endpoint.join(kill_uri)?; let headers = self.make_headers(Some(query_id))?; @@ -451,7 +460,7 @@ impl APIClient { Ok(()) } - pub async fn wait_for_query(&self, resp: QueryResponse) -> Result { + async fn wait_for_query(&self, resp: QueryResponse) -> Result { info!("wait for query: {}", resp.id); let node_id = resp.node_id.clone(); if let Some(node_id) = self.last_node_id() { @@ -624,7 +633,7 @@ impl APIClient { Ok(()) } - pub async fn login(&mut self) -> Result<()> { + async fn login(&mut self) -> Result<()> { let endpoint = self.endpoint.join("/v1/session/login")?; let headers = self.make_headers(None)?; let body = LoginRequest::from(&*self.session_state.lock()); @@ -661,7 +670,7 @@ impl APIClient { Ok(()) } - pub fn build_log_out_request(&mut self) -> Result { + fn build_log_out_request(&mut self) -> Result { let endpoint = self.endpoint.join("/v1/session/logout")?; let session_state = self.session_state(); @@ -684,7 +693,7 @@ impl APIClient { || self.session_state.lock().need_keep_alive.unwrap_or(false) } - pub async fn refresh_session_token( + async fn refresh_session_token( &self, self_login_info: Arc>, ) -> Result<()> { diff --git a/core/src/lib.rs b/core/src/lib.rs index 30eaac7f..1600fa43 100644 --- a/core/src/lib.rs +++ b/core/src/lib.rs @@ -14,14 +14,25 @@ mod client; -pub mod auth; -pub mod error; -pub mod error_code; +mod auth; +mod error; +mod error_code; mod global_cookie_store; mod login; -pub mod presign; -pub mod request; -pub mod response; -pub mod session; -pub mod stage; +mod presign; +mod request; +mod response; + +mod session; +mod stage; + +pub use auth::SensitiveString; pub use client::APIClient; +pub use error::Error; +pub use presign::presign_download_from_stage; +pub use presign::presign_upload_to_stage; +pub use presign::PresignedResponse; +pub use response::QueryResponse; +pub use response::QueryStats; +pub use response::SchemaField; +pub use stage::StageLocation; diff --git a/driver/src/conn.rs b/driver/src/conn.rs index 4292492a..93283d4b 100644 --- a/driver/src/conn.rs +++ b/driver/src/conn.rs @@ -26,8 +26,8 @@ use url::Url; #[cfg(feature = "flight-sql")] use crate::flight_sql::FlightSQLConnection; -use databend_client::presign::{presign_download_from_stage, PresignedResponse}; -use databend_client::stage::StageLocation; +use databend_client::StageLocation; +use databend_client::{presign_download_from_stage, PresignedResponse}; use databend_driver_core::error::{Error, Result}; use databend_driver_core::rows::{Row, RowIterator, RowStatsIterator, RowWithStats, ServerStats}; use databend_driver_core::schema::{DataType, Field, NumberDataType, Schema}; diff --git a/driver/src/flight_sql.rs b/driver/src/flight_sql.rs index dfaaf5b2..d0ed0721 100644 --- a/driver/src/flight_sql.rs +++ b/driver/src/flight_sql.rs @@ -31,8 +31,8 @@ use tokio_stream::{Stream, StreamExt}; use tonic::transport::{Channel, ClientTlsConfig, Endpoint}; use url::Url; -use databend_client::auth::SensitiveString; -use databend_client::presign::{presign_upload_to_stage, PresignedResponse}; +use databend_client::SensitiveString; +use databend_client::{presign_upload_to_stage, PresignedResponse}; use databend_driver_core::error::{Error, Result}; use databend_driver_core::rows::{ Row, RowIterator, RowStatsIterator, RowWithStats, Rows, ServerStats, diff --git a/driver/src/rest_api.rs b/driver/src/rest_api.rs index da45c7fa..9a8794cf 100644 --- a/driver/src/rest_api.rs +++ b/driver/src/rest_api.rs @@ -27,9 +27,9 @@ use tokio::fs::File; use tokio::io::{AsyncReadExt, AsyncWriteExt}; use tokio_stream::Stream; -use databend_client::presign::PresignedResponse; -use databend_client::response::QueryResponse; use databend_client::APIClient; +use databend_client::PresignedResponse; +use databend_client::QueryResponse; use databend_driver_core::error::{Error, Result}; use databend_driver_core::rows::{Row, RowIterator, RowStatsIterator, RowWithStats, ServerStats}; use databend_driver_core::schema::{Schema, SchemaRef}; @@ -46,8 +46,8 @@ impl Connection for RestAPIConnection { async fn info(&self) -> ConnectionInfo { ConnectionInfo { handler: "RestAPI".to_string(), - host: self.client.host.clone(), - port: self.client.port, + host: self.client.host().to_string(), + port: self.client.port(), user: self.client.username(), database: self.client.current_database(), warehouse: self.client.current_warehouse(), diff --git a/sql/src/error.rs b/sql/src/error.rs index 295e1147..752a80ce 100644 --- a/sql/src/error.rs +++ b/sql/src/error.rs @@ -44,7 +44,7 @@ pub enum Error { IO(String), BadArgument(String), InvalidResponse(String), - Api(databend_client::error::Error), + Api(databend_client::Error), #[cfg(feature = "flight-sql")] Arrow(arrow_schema::ArrowError), Convert(ConvertError), @@ -183,8 +183,8 @@ impl From for Error { } } -impl From for Error { - fn from(e: databend_client::error::Error) -> Self { +impl From for Error { + fn from(e: databend_client::Error) -> Self { Error::Api(e) } } diff --git a/sql/src/rows.rs b/sql/src/rows.rs index b7e05730..8ded6e0d 100644 --- a/sql/src/rows.rs +++ b/sql/src/rows.rs @@ -64,8 +64,8 @@ impl ServerStats { } } -impl From for ServerStats { - fn from(stats: databend_client::response::QueryStats) -> Self { +impl From for ServerStats { + fn from(stats: databend_client::QueryStats) -> Self { let mut p = Self { total_rows: 0, total_bytes: 0, diff --git a/sql/src/schema.rs b/sql/src/schema.rs index cfe9ef21..8c408faf 100644 --- a/sql/src/schema.rs +++ b/sql/src/schema.rs @@ -33,7 +33,7 @@ pub(crate) const ARROW_EXT_TYPE_GEOMETRY: &str = "Geometry"; #[cfg(feature = "flight-sql")] pub(crate) const ARROW_EXT_TYPE_GEOGRAPHY: &str = "Geography"; -use databend_client::response::SchemaField as APISchemaField; +use databend_client::SchemaField as APISchemaField; use crate::error::{Error, Result};