feldera_types/
query.rs

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