feldera_types/
query.rs

1use serde::Deserialize;
2use std::fmt::{Debug, Display, Formatter, Result};
3use utoipa::ToSchema;
4
5/// URL-encoded `format` argument to the `/query` endpoint.
6#[derive(Debug, 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/// URL-encoded arguments to the `/query` endpoint.
41#[derive(Clone, Debug, PartialEq, Deserialize, ToSchema)]
42pub struct AdhocQueryArgs {
43    /// The SQL query to run.
44    pub sql: String,
45    /// In what format the data is sent to the client.
46    #[serde(default = "default_format")]
47    pub format: AdHocResultFormat,
48}