Skip to main content

uqa_client/
sql_execution.rs

1//
2// Unified Query Algebra
3//
4// Copyright (c) 2023-2026 Cognica, Inc.
5//
6
7use std::collections::BTreeMap;
8use std::fmt;
9use std::ops::Deref;
10
11use serde::Deserialize;
12use uqa_core::Value;
13use uqa_sql::SQLResult;
14
15/// Materialized SQL result plus the data-plane request identity.
16pub struct SQLExecution {
17    result: SQLResult,
18    request_id: String,
19}
20
21#[derive(Deserialize)]
22pub(crate) struct SQLWireResponse {
23    pub columns: Vec<String>,
24    pub rows: Vec<BTreeMap<String, Value>>,
25    pub affected_rows: u64,
26    pub request_id: String,
27}
28
29impl SQLExecution {
30    pub(crate) fn from_wire(response: SQLWireResponse) -> Self {
31        let column_types = vec![None; response.columns.len()];
32        Self {
33            result: SQLResult {
34                kind: uqa_sql::SQLResultKind::Unknown,
35                command_tag: None,
36                columns: response.columns,
37                column_types,
38                rows: response.rows,
39                positional_rows: None,
40                affected_rows: response.affected_rows,
41            },
42            request_id: response.request_id,
43        }
44    }
45
46    pub fn result(&self) -> &SQLResult {
47        &self.result
48    }
49
50    pub fn request_id(&self) -> &str {
51        &self.request_id
52    }
53
54    pub fn into_result(self) -> SQLResult {
55        self.result
56    }
57}
58
59impl Deref for SQLExecution {
60    type Target = SQLResult;
61
62    fn deref(&self) -> &Self::Target {
63        &self.result
64    }
65}
66
67impl fmt::Debug for SQLExecution {
68    fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
69        formatter
70            .debug_struct("SQLExecution")
71            .field("request_id", &self.request_id)
72            .field("result", &"[REDACTED]")
73            .finish()
74    }
75}