From e2aa80d40ed03e18956adf3da49db3a57f6426ee Mon Sep 17 00:00:00 2001 From: Ning Sun Date: Thu, 11 Jan 2024 15:12:07 +0800 Subject: [PATCH 1/2] feat: upgrade pgwire to 0.19 --- Cargo.lock | 5 ++--- src/servers/Cargo.toml | 2 +- src/servers/src/postgres/auth_handler.rs | 2 +- src/servers/src/postgres/handler.rs | 17 +++++++---------- src/servers/src/postgres/types.rs | 6 +++--- 5 files changed, 14 insertions(+), 18 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 29a60c4f891b..30c6fc84c13b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6112,9 +6112,9 @@ dependencies = [ [[package]] name = "pgwire" -version = "0.18.0" +version = "0.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b277432819ee6b76bf56de5e91eae578d6b332bd6f05f963ee81fc788bc886f" +checksum = "dee9e0055cad29212eded16c4b721a5fd9b81b00f0417f03bee4badc917aee7d" dependencies = [ "async-trait", "base64 0.21.5", @@ -6122,7 +6122,6 @@ dependencies = [ "chrono", "derive-new 0.6.0", "futures", - "getset", "hex", "log", "md5", diff --git a/src/servers/Cargo.toml b/src/servers/Cargo.toml index 727f4817e798..5935a069e33d 100644 --- a/src/servers/Cargo.toml +++ b/src/servers/Cargo.toml @@ -58,7 +58,7 @@ openmetrics-parser = "0.4" opensrv-mysql = { git = "https://github.com/MichaelScofield/opensrv.git", rev = "1676c1d" } opentelemetry-proto.workspace = true parking_lot = "0.12" -pgwire = "0.18" +pgwire = "0.19" pin-project = "1.0" postgres-types = { version = "0.2", features = ["with-chrono-0_4"] } pprof = { version = "0.13", features = [ diff --git a/src/servers/src/postgres/auth_handler.rs b/src/servers/src/postgres/auth_handler.rs index c795f381b5ae..3708f6f57a53 100644 --- a/src/servers/src/postgres/auth_handler.rs +++ b/src/servers/src/postgres/auth_handler.rs @@ -184,7 +184,7 @@ impl StartupHandler for PostgresServerHandler { let login_info = LoginInfo::from_client_info(client); // do authenticate - let auth_result = self.login_verifier.auth(&login_info, pwd.password()).await; + let auth_result = self.login_verifier.auth(&login_info, &pwd.password).await; if let Ok(Some(user_info)) = auth_result { self.session.set_user_info(user_info); diff --git a/src/servers/src/postgres/handler.rs b/src/servers/src/postgres/handler.rs index 5356057238a8..80818eeb91f2 100644 --- a/src/servers/src/postgres/handler.rs +++ b/src/servers/src/postgres/handler.rs @@ -71,10 +71,7 @@ fn output_to_query_response<'a>( field_format: &Format, ) -> PgWireResult> { match output { - Ok(Output::AffectedRows(rows)) => Ok(Response::Execution(Tag::new_for_execution( - "OK", - Some(rows), - ))), + Ok(Output::AffectedRows(rows)) => Ok(Response::Execution(Tag::new("OK").with_rows(rows))), Ok(Output::Stream(record_stream)) => { let schema = record_stream.schema(); recordbatches_to_query_response(record_stream, schema, field_format) @@ -211,7 +208,7 @@ impl ExtendedQueryHandler for PostgresServerHandler { .with_label_values(&[crate::metrics::METRIC_POSTGRES_EXTENDED_QUERY, db.as_str()]) .start_timer(); - let sql_plan = portal.statement().statement(); + let sql_plan = &portal.statement.statement; let output = if let Some(plan) = &sql_plan.plan { let plan = plan @@ -230,7 +227,7 @@ impl ExtendedQueryHandler for PostgresServerHandler { self.query_handler.do_query(&sql, query_ctx).await.remove(0) }; - output_to_query_response(output, portal.result_column_format()) + output_to_query_response(output, &portal.result_column_format) } async fn do_describe( @@ -243,7 +240,7 @@ impl ExtendedQueryHandler for PostgresServerHandler { { let (param_types, sql_plan, format) = match target { StatementOrPortal::Statement(stmt) => { - let sql_plan = stmt.statement(); + let sql_plan = &stmt.statement; if let Some(plan) = &sql_plan.plan { let param_types = plan .get_param_types() @@ -254,14 +251,14 @@ impl ExtendedQueryHandler for PostgresServerHandler { (Some(types), sql_plan, &Format::UnifiedBinary) } else { - let param_types = Some(stmt.parameter_types().clone()); + let param_types = Some(stmt.parameter_types.clone()); (param_types, sql_plan, &Format::UnifiedBinary) } } StatementOrPortal::Portal(portal) => ( None, - portal.statement().statement(), - portal.result_column_format(), + &portal.statement.statement, + &portal.result_column_format, ), }; diff --git a/src/servers/src/postgres/types.rs b/src/servers/src/postgres/types.rs index 514fc1d73208..d863c4d4e0a8 100644 --- a/src/servers/src/postgres/types.rs +++ b/src/servers/src/postgres/types.rs @@ -168,7 +168,7 @@ pub(super) fn type_pg_to_gt(origin: &Type) -> Result { pub(super) fn parameter_to_string(portal: &Portal, idx: usize) -> PgWireResult { // the index is managed from portal's parameters count so it's safe to // unwrap here. - let param_type = portal.statement().parameter_types().get(idx).unwrap(); + let param_type = portal.statement.parameter_types.get(idx).unwrap(); match param_type { &Type::VARCHAR | &Type::TEXT => Ok(format!( "'{}'", @@ -218,7 +218,7 @@ pub(super) fn parameter_to_string(portal: &Portal, idx: usize) -> PgWir pub(super) fn invalid_parameter_error(msg: &str, detail: Option<&str>) -> PgWireError { let mut error_info = ErrorInfo::new("ERROR".to_owned(), "22023".to_owned(), msg.to_owned()); - error_info.set_detail(detail.map(|s| s.to_owned())); + error_info.detail = detail.map(|s| s.to_owned()); PgWireError::UserError(Box::new(error_info)) } @@ -246,7 +246,7 @@ pub(super) fn parameters_to_scalar_values( let param_count = portal.parameter_len(); let mut results = Vec::with_capacity(param_count); - let client_param_types = portal.statement().parameter_types(); + let client_param_types = &portal.statement.parameter_types; let param_types = plan .get_param_types() .map_err(|e| PgWireError::ApiError(Box::new(e)))?; From 2276946ae2d75c88d11bbf66205caccc9e992fd5 Mon Sep 17 00:00:00 2001 From: Ning Sun Date: Mon, 15 Jan 2024 09:38:54 +0800 Subject: [PATCH 2/2] fix: update pgwire to 0.19.1 --- Cargo.lock | 4 ++-- src/servers/Cargo.toml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 30c6fc84c13b..1ea1ef1701a6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6112,9 +6112,9 @@ dependencies = [ [[package]] name = "pgwire" -version = "0.19.0" +version = "0.19.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dee9e0055cad29212eded16c4b721a5fd9b81b00f0417f03bee4badc917aee7d" +checksum = "17780c93587822c191c3f4d43fa5f6bc6df1e51b9f58a0be0cd1b7fd6e80d9e6" dependencies = [ "async-trait", "base64 0.21.5", diff --git a/src/servers/Cargo.toml b/src/servers/Cargo.toml index 5935a069e33d..2ee22a32f079 100644 --- a/src/servers/Cargo.toml +++ b/src/servers/Cargo.toml @@ -58,7 +58,7 @@ openmetrics-parser = "0.4" opensrv-mysql = { git = "https://github.com/MichaelScofield/opensrv.git", rev = "1676c1d" } opentelemetry-proto.workspace = true parking_lot = "0.12" -pgwire = "0.19" +pgwire = "0.19.1" pin-project = "1.0" postgres-types = { version = "0.2", features = ["with-chrono-0_4"] } pprof = { version = "0.13", features = [