use serde::{Deserialize, Serialize};
use std::fmt::{Debug, Display, Formatter, Result};
use utoipa::ToSchema;
#[derive(Debug, Deserialize, PartialEq, Clone, Copy, ToSchema)]
#[serde(rename_all = "snake_case")]
pub enum AdHocResultFormat {
Text,
Json,
Parquet,
}
impl Display for AdHocResultFormat {
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
match self {
AdHocResultFormat::Text => write!(f, "text"),
AdHocResultFormat::Json => write!(f, "json"),
AdHocResultFormat::Parquet => write!(f, "parquet"),
}
}
}
impl Default for AdHocResultFormat {
fn default() -> Self {
Self::Text
}
}
fn default_format() -> AdHocResultFormat {
AdHocResultFormat::default()
}
#[derive(Clone, Debug, PartialEq, Deserialize, ToSchema)]
pub struct AdhocQueryArgs {
pub sql: String,
#[serde(default = "default_format")]
pub format: AdHocResultFormat,
}
#[derive(Clone, Copy, Debug, Deserialize, PartialEq, Eq, PartialOrd, ToSchema, Ord)]
pub enum OutputQuery {
#[serde(rename = "table")]
Table,
#[serde(rename = "neighborhood")]
Neighborhood,
#[serde(rename = "quantiles")]
Quantiles,
}
impl Default for OutputQuery {
fn default() -> Self {
Self::Table
}
}
impl Display for OutputQuery {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
OutputQuery::Table => write!(f, "table"),
OutputQuery::Neighborhood => write!(f, "neighborhood"),
OutputQuery::Quantiles => write!(f, "quantiles"),
}
}
}
#[derive(Clone, Serialize, Deserialize, ToSchema)]
pub struct NeighborhoodQuery {
pub anchor: Option<utoipa::openapi::Object>,
pub before: u32,
pub after: u32,
}
impl Debug for NeighborhoodQuery {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "NeighborhoodQuery")
}
}