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                columns: response.columns,
35                column_types,
36                rows: response.rows,
37                positional_rows: None,
38                affected_rows: response.affected_rows,
39            },
40            request_id: response.request_id,
41        }
42    }
43
44    pub fn result(&self) -> &SQLResult {
45        &self.result
46    }
47
48    pub fn request_id(&self) -> &str {
49        &self.request_id
50    }
51
52    pub fn into_result(self) -> SQLResult {
53        self.result
54    }
55}
56
57impl Deref for SQLExecution {
58    type Target = SQLResult;
59
60    fn deref(&self) -> &Self::Target {
61        &self.result
62    }
63}
64
65impl fmt::Debug for SQLExecution {
66    fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
67        formatter
68            .debug_struct("SQLExecution")
69            .field("request_id", &self.request_id)
70            .field("result", &"[REDACTED]")
71            .finish()
72    }
73}