feldera_types/
query.rs

1use serde::{Deserialize, Serialize};
2use std::fmt::{Debug, Display, Formatter, Result};
3use utoipa::ToSchema;
4
5/// The maximum size of a WebSocket frames we're sending in bytes.
6pub const MAX_WS_FRAME_SIZE: usize = 1024 * 1024 * 2;
7
8/// URL-encoded `format` argument to the `/query` endpoint.
9#[derive(Debug, Serialize, Deserialize, PartialEq, Clone, Copy, ToSchema)]
10#[serde(rename_all = "snake_case")]
11pub enum AdHocResultFormat {
12    /// Serialize results as a human-readable text table.
13    Text,
14    /// Serialize results as new-line delimited JSON records.
15    Json,
16    /// Download results in a parquet file.
17    Parquet,
18    /// Stream data in the arrow IPC format.
19    ArrowIpc,
20}
21
22impl Display for AdHocResultFormat {
23    fn fmt(&self, f: &mut Formatter<'_>) -> Result {
24        match self {
25            AdHocResultFormat::Text => write!(f, "text"),
26            AdHocResultFormat::Json => write!(f, "json"),
27            AdHocResultFormat::Parquet => write!(f, "parquet"),
28            AdHocResultFormat::ArrowIpc => write!(f, "arrow_ipc"),
29        }
30    }
31}
32
33impl Default for AdHocResultFormat {
34    fn default() -> Self {
35        Self::Text
36    }
37}
38
39fn default_format() -> AdHocResultFormat {
40    AdHocResultFormat::default()
41}
42
43/// Arguments to the `/query` endpoint.
44///
45/// The arguments can be provided in two ways:
46///
47/// - In case a normal HTTP connection is established to the endpoint,
48///   these arguments are passed as URL-encoded parameters.
49///   Note: this mode is deprecated and will be removed in the future.
50///
51/// - If a Websocket connection is opened to `/query`, the arguments are passed
52///   to the server over the websocket as a JSON encoded string.
53#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, ToSchema)]
54pub struct AdhocQueryArgs {
55    /// The SQL query to run.
56    #[serde(default)]
57    pub sql: String,
58    /// In what format the data is sent to the client.
59    #[serde(default = "default_format")]
60    pub format: AdHocResultFormat,
61}