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}
16
17impl Display for AdHocResultFormat {
18    fn fmt(&self, f: &mut Formatter<'_>) -> Result {
19        match self {
20            AdHocResultFormat::Text => write!(f, "text"),
21            AdHocResultFormat::Json => write!(f, "json"),
22            AdHocResultFormat::Parquet => write!(f, "parquet"),
23        }
24    }
25}
26
27impl Default for AdHocResultFormat {
28    fn default() -> Self {
29        Self::Text
30    }
31}
32
33fn default_format() -> AdHocResultFormat {
34    AdHocResultFormat::default()
35}
36
37/// URL-encoded arguments to the `/query` endpoint.
38#[derive(Clone, Debug, PartialEq, Deserialize, ToSchema)]
39pub struct AdhocQueryArgs {
40    /// The SQL query to run.
41    pub sql: String,
42    /// In what format the data is sent to the client.
43    #[serde(default = "default_format")]
44    pub format: AdHocResultFormat,
45}