-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathquery_simple.rs
More file actions
57 lines (50 loc) · 1.86 KB
/
Copy pathquery_simple.rs
File metadata and controls
57 lines (50 loc) · 1.86 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
// SPDX-FileCopyrightText: 2026 Stackable GmbH
// SPDX-License-Identifier: OSL-3.0
use std::fmt::Debug;
use async_trait::async_trait;
use futures::Sink;
use pgwire::api::ClientInfo;
use pgwire::api::query::SimpleQueryHandler;
use pgwire::api::results::Response;
use pgwire::error::{PgWireError, PgWireResult};
use pgwire::messages::PgWireBackendMessage;
use crate::query_pipeline::process_query;
use crate::session::ConnectionState;
#[derive(Debug)]
pub struct GatewayQueryHandler;
#[async_trait]
impl SimpleQueryHandler for GatewayQueryHandler {
async fn do_query<C>(&self, client: &mut C, query: &str) -> PgWireResult<Vec<Response>>
where
C: ClientInfo + Sink<PgWireBackendMessage> + Unpin + Send + Sync,
C::Error: Debug,
PgWireError: From<<C as Sink<PgWireBackendMessage>>::Error>,
{
tracing::debug!(query, "Simple query received");
// Captured before borrowing session state, so the `pg_stat_ssl`
// intercept can report this connection's real TLS state.
let client_is_secure = client.is_secure();
let conn_state = client
.session_extensions()
.get::<ConnectionState>()
.ok_or_else(|| PgWireError::ApiError("Connection state not found".into()))?;
// The simple-query protocol always uses text wire format; it never
// negotiates per-column binary results.
let result = process_query(
query,
&conn_state.trino_client,
&conn_state.config,
Some(&conn_state.active_query_id),
None,
client_is_secure,
)
.await;
match &result {
Ok(responses) => {
tracing::trace!(response_count = responses.len(), "Simple query processed")
}
Err(e) => tracing::debug!(error = %e, "Simple query failed"),
}
result
}
}