Skip to content
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
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion datafusion-postgres/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,4 @@ pgwire = { workspace = true }
datafusion = { workspace = true }
futures = "0.3"
async-trait = "0.1"
tokio = { workspace = true, features = ["sync"] }
chrono = { version = "0.4", features = ["std"] }
13 changes: 5 additions & 8 deletions datafusion-postgres/src/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ use pgwire::api::stmt::QueryParser;
use pgwire::api::stmt::StoredStatement;
use pgwire::api::{ClientInfo, PgWireHandlerFactory, Type};
use pgwire::error::{ErrorInfo, PgWireError, PgWireResult};
use tokio::sync::Mutex;

use crate::datatypes::{self, into_pg_type};

Expand Down Expand Up @@ -43,13 +42,13 @@ impl PgWireHandlerFactory for HandlerFactory {
}

pub struct DfSessionService {
session_context: Arc<Mutex<SessionContext>>,
session_context: Arc<SessionContext>,
parser: Arc<Parser>,
}

impl DfSessionService {
pub fn new(session_context: SessionContext) -> DfSessionService {
let session_context = Arc::new(Mutex::new(session_context));
let session_context = Arc::new(session_context);
let parser = Arc::new(Parser {
session_context: session_context.clone(),
});
Expand All @@ -71,7 +70,7 @@ impl SimpleQueryHandler for DfSessionService {
C: ClientInfo + Unpin + Send + Sync,
{
if query.to_uppercase().starts_with("SELECT") {
let ctx = self.session_context.lock().await;
let ctx = &self.session_context;
let df = ctx
.sql(query)
.await
Expand All @@ -90,15 +89,15 @@ impl SimpleQueryHandler for DfSessionService {
}

pub struct Parser {
session_context: Arc<Mutex<SessionContext>>,
session_context: Arc<SessionContext>,
}

#[async_trait]
impl QueryParser for Parser {
type Statement = LogicalPlan;

async fn parse_sql(&self, sql: &str, _types: &[Type]) -> PgWireResult<Self::Statement> {
let context = self.session_context.lock().await;
let context = &self.session_context;
let state = context.state();

let logical_plan = state
Expand Down Expand Up @@ -197,8 +196,6 @@ impl ExtendedQueryHandler for DfSessionService {

let dataframe = self
.session_context
.lock()
.await
.execute_logical_plan(plan)
.await
.map_err(|e| PgWireError::ApiError(Box::new(e)))?;
Expand Down