Skip to main content

uqa_client/
sql_stream_frame.rs

1//
2// Unified Query Algebra
3//
4// Copyright (c) 2023-2026 Cognica, Inc.
5//
6
7use std::collections::BTreeMap;
8use std::fmt;
9
10use serde::{Deserialize, Serialize};
11use uqa_core::Value;
12
13/// One decoded frame from the stable UQA NDJSON SQL stream.
14#[derive(Clone, Deserialize, PartialEq, Serialize)]
15#[serde(tag = "type", rename_all = "snake_case")]
16pub enum SQLStreamFrame {
17    Metadata {
18        columns: Vec<String>,
19        row_count: usize,
20        spilled_to_disk: bool,
21        request_id: String,
22    },
23    Row {
24        row: BTreeMap<String, Value>,
25    },
26    Complete {
27        row_count: usize,
28        request_id: String,
29    },
30    Error {
31        code: String,
32        message: String,
33        request_id: String,
34    },
35}
36
37impl SQLStreamFrame {
38    pub fn request_id(&self) -> Option<&str> {
39        match self {
40            Self::Metadata { request_id, .. }
41            | Self::Complete { request_id, .. }
42            | Self::Error { request_id, .. } => Some(request_id),
43            Self::Row { .. } => None,
44        }
45    }
46
47    pub const fn is_terminal(&self) -> bool {
48        matches!(self, Self::Complete { .. } | Self::Error { .. })
49    }
50}
51
52impl fmt::Debug for SQLStreamFrame {
53    fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
54        formatter.write_str("SQLStreamFrame([REDACTED])")
55    }
56}