diff --git a/README.md b/README.md index 70e8ec7..753dd01 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,7 @@ use datafusion::prelude::SessionContext; use datafusion_postgres::{serve, ServerOptions}; // Create datafusion SessionContext -let session_context = SessionContext::new(); +let session_context = Arc::new(SessionContext::new()); // Configure your `session_context` // ... diff --git a/datafusion-postgres-cli/src/main.rs b/datafusion-postgres-cli/src/main.rs index ae69aac..9394848 100644 --- a/datafusion-postgres-cli/src/main.rs +++ b/datafusion-postgres-cli/src/main.rs @@ -1,5 +1,6 @@ use std::ffi::OsStr; use std::fs; +use std::sync::Arc; use datafusion::execution::options::{ ArrowReadOptions, AvroReadOptions, CsvReadOptions, NdJsonReadOptions, ParquetReadOptions, @@ -184,7 +185,7 @@ async fn main() -> Result<(), Box> { .with_host(opts.host) .with_port(opts.port); - serve(session_context, &server_options) + serve(Arc::new(session_context), &server_options) .await .map_err(|e| format!("Failed to run server: {}", e))?; diff --git a/datafusion-postgres/src/handlers.rs b/datafusion-postgres/src/handlers.rs index fc3ca35..996ad34 100644 --- a/datafusion-postgres/src/handlers.rs +++ b/datafusion-postgres/src/handlers.rs @@ -61,8 +61,7 @@ pub struct DfSessionService { } impl DfSessionService { - pub fn new(session_context: SessionContext) -> DfSessionService { - let session_context = Arc::new(session_context); + pub fn new(session_context: Arc) -> DfSessionService { let parser = Arc::new(Parser { session_context: session_context.clone(), }); diff --git a/datafusion-postgres/src/lib.rs b/datafusion-postgres/src/lib.rs index 454761e..d7e5a17 100644 --- a/datafusion-postgres/src/lib.rs +++ b/datafusion-postgres/src/lib.rs @@ -37,7 +37,7 @@ impl Default for ServerOptions { /// Serve the Datafusion `SessionContext` with Postgres protocol. pub async fn serve( - session_context: SessionContext, + session_context: Arc, opts: &ServerOptions, ) -> Result<(), std::io::Error> { // Create the handler factory with the session context and catalog name