Skip to content

refactor: accept arc reference for serve #83

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 7, 2025
Merged
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
// ...

Expand Down
3 changes: 2 additions & 1 deletion datafusion-postgres-cli/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::ffi::OsStr;
use std::fs;
use std::sync::Arc;

use datafusion::execution::options::{
ArrowReadOptions, AvroReadOptions, CsvReadOptions, NdJsonReadOptions, ParquetReadOptions,
Expand Down Expand Up @@ -184,7 +185,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
.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))?;

Expand Down
3 changes: 1 addition & 2 deletions datafusion-postgres/src/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<SessionContext>) -> DfSessionService {
let parser = Arc::new(Parser {
session_context: session_context.clone(),
});
Expand Down
2 changes: 1 addition & 1 deletion datafusion-postgres/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<SessionContext>,
opts: &ServerOptions,
) -> Result<(), std::io::Error> {
// Create the handler factory with the session context and catalog name
Expand Down
Loading