@@ -11,11 +11,12 @@ use datafusion::sql::sqlparser;
1111use log:: info;
1212use pgwire:: api:: auth:: noop:: NoopStartupHandler ;
1313use pgwire:: api:: auth:: StartupHandler ;
14+ use pgwire:: api:: cancel:: { CancelHandler , DefaultCancelHandler } ;
1415use pgwire:: api:: portal:: { Format , Portal } ;
1516use pgwire:: api:: query:: { ExtendedQueryHandler , SimpleQueryHandler } ;
1617use pgwire:: api:: results:: { FieldInfo , Response , Tag } ;
1718use pgwire:: api:: stmt:: QueryParser ;
18- use pgwire:: api:: { ClientInfo , ErrorHandler , PgWireServerHandlers , Type } ;
19+ use pgwire:: api:: { ClientInfo , ConnectionManager , ErrorHandler , PgWireServerHandlers , Type } ;
1920use pgwire:: error:: { PgWireError , PgWireResult } ;
2021use pgwire:: messages:: PgWireBackendMessage ;
2122use pgwire:: types:: format:: FormatOptions ;
@@ -29,19 +30,34 @@ use arrow_pg::datatypes::{arrow_schema_to_pg_fields, into_pg_type};
2930use datafusion_pg_catalog:: sql:: PostgresCompatibilityParser ;
3031
3132/// Simple startup handler that does no authentication
32- pub struct SimpleStartupHandler ;
33+ pub struct SimpleStartupHandler {
34+ connection_manager : Arc < ConnectionManager > ,
35+ }
3336
3437#[ async_trait:: async_trait]
35- impl NoopStartupHandler for SimpleStartupHandler { }
38+ impl NoopStartupHandler for SimpleStartupHandler {
39+ fn connection_manager ( & self ) -> Option < Arc < ConnectionManager > > {
40+ Some ( self . connection_manager . clone ( ) )
41+ }
42+ }
3643
3744pub struct HandlerFactory {
3845 pub session_service : Arc < DfSessionService > ,
46+ cancel_handler : Arc < DefaultCancelHandler > ,
47+ startup_handler : Arc < SimpleStartupHandler > ,
3948}
4049
4150impl HandlerFactory {
4251 pub fn new ( session_context : Arc < SessionContext > ) -> Self {
4352 let session_service = Arc :: new ( DfSessionService :: new ( session_context) ) ;
44- HandlerFactory { session_service }
53+ let connection_manager = Arc :: new ( ConnectionManager :: new ( ) ) ;
54+ HandlerFactory {
55+ session_service,
56+ cancel_handler : Arc :: new ( DefaultCancelHandler :: new ( connection_manager. clone ( ) ) ) ,
57+ startup_handler : Arc :: new ( SimpleStartupHandler {
58+ connection_manager : connection_manager. clone ( ) ,
59+ } ) ,
60+ }
4561 }
4662
4763 pub fn new_with_hooks (
@@ -52,7 +68,14 @@ impl HandlerFactory {
5268 session_context,
5369 query_hooks,
5470 ) ) ;
55- HandlerFactory { session_service }
71+ let connection_manager = Arc :: new ( ConnectionManager :: new ( ) ) ;
72+ HandlerFactory {
73+ session_service,
74+ cancel_handler : Arc :: new ( DefaultCancelHandler :: new ( connection_manager. clone ( ) ) ) ,
75+ startup_handler : Arc :: new ( SimpleStartupHandler {
76+ connection_manager : connection_manager. clone ( ) ,
77+ } ) ,
78+ }
5679 }
5780}
5881
@@ -66,12 +89,16 @@ impl PgWireServerHandlers for HandlerFactory {
6689 }
6790
6891 fn startup_handler ( & self ) -> Arc < impl StartupHandler > {
69- Arc :: new ( SimpleStartupHandler )
92+ self . startup_handler . clone ( )
7093 }
7194
7295 fn error_handler ( & self ) -> Arc < impl ErrorHandler > {
7396 Arc :: new ( LoggingErrorHandler )
7497 }
98+
99+ fn cancel_handler ( & self ) -> Arc < impl CancelHandler > {
100+ self . cancel_handler . clone ( )
101+ }
75102}
76103
77104struct LoggingErrorHandler ;
0 commit comments