forked from datafusion-contrib/datafusion-postgres
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmod.rs
More file actions
61 lines (54 loc) · 1.88 KB
/
mod.rs
File metadata and controls
61 lines (54 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
pub mod permissions;
pub mod set_show;
pub mod transactions;
use async_trait::async_trait;
use datafusion::common::ParamValues;
use datafusion::logical_expr::LogicalPlan;
use datafusion::prelude::SessionContext;
use datafusion::sql::sqlparser::ast::Statement;
use futures::Sink;
use pgwire::api::results::Response;
use pgwire::api::ClientInfo;
use pgwire::error::{PgWireError, PgWireResult};
use pgwire::messages::PgWireBackendMessage;
#[async_trait]
pub trait HookClient: ClientInfo + Send + Sync {
async fn send_message(&mut self, item: PgWireBackendMessage) -> PgWireResult<()>;
}
#[async_trait]
impl<S> HookClient for S
where
S: ClientInfo + Sink<PgWireBackendMessage> + Send + Sync + Unpin,
PgWireError: From<<S as Sink<PgWireBackendMessage>>::Error>,
{
async fn send_message(&mut self, item: PgWireBackendMessage) -> PgWireResult<()> {
use futures::SinkExt;
self.send(item).await.map_err(PgWireError::from)
}
}
#[async_trait]
pub trait QueryHook: Send + Sync {
/// called in simple query handler to return response directly
async fn handle_simple_query(
&self,
statement: &Statement,
session_context: &SessionContext,
client: &mut dyn HookClient,
) -> Option<PgWireResult<Response>>;
/// called at extended query parse phase, for generating `LogicalPlan`from statement
async fn handle_extended_parse_query(
&self,
sql: &Statement,
session_context: &SessionContext,
client: &(dyn ClientInfo + Send + Sync),
) -> Option<PgWireResult<LogicalPlan>>;
/// called at extended query execute phase, for query execution
async fn handle_extended_query(
&self,
statement: &Statement,
logical_plan: &LogicalPlan,
params: &ParamValues,
session_context: &SessionContext,
client: &mut dyn HookClient,
) -> Option<PgWireResult<Response>>;
}