use std::{fmt, str::FromStr};
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash)]
pub enum StatisticalAggregateExecutionMode {
DataFusionExactHostWelford,
#[default]
GpuNativeTolerant,
}
impl StatisticalAggregateExecutionMode {
pub const fn as_str(self) -> &'static str {
match self {
Self::DataFusionExactHostWelford => "datafusion_exact_host_welford",
Self::GpuNativeTolerant => "gpu_native_tolerant",
}
}
pub const fn tolerance_contract(self) -> StatisticalAggregateToleranceContract {
match self {
Self::DataFusionExactHostWelford => StatisticalAggregateToleranceContract::Exact,
Self::GpuNativeTolerant => StatisticalAggregateToleranceContract::FloatTolerant,
}
}
pub const fn is_datafusion_exact(self) -> bool {
matches!(self, Self::DataFusionExactHostWelford)
}
}
impl fmt::Display for StatisticalAggregateExecutionMode {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(self.as_str())
}
}
impl FromStr for StatisticalAggregateExecutionMode {
type Err = StatisticalAggregateExecutionModeParseError;
fn from_str(value: &str) -> Result<Self, Self::Err> {
match value.to_ascii_lowercase().as_str() {
"datafusion_exact_host_welford" | "datafusion_exact" | "exact" => Ok(Self::DataFusionExactHostWelford),
"gpu_native_tolerant" | "gpu_native" | "tolerant" => Ok(Self::GpuNativeTolerant),
other => Err(StatisticalAggregateExecutionModeParseError { value: other.to_string() }),
}
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct StatisticalAggregateExecutionModeParseError {
value: String,
}
impl fmt::Display for StatisticalAggregateExecutionModeParseError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "invalid statistical aggregate execution mode: {}", self.value)
}
}
impl std::error::Error for StatisticalAggregateExecutionModeParseError {}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum StatisticalAggregateToleranceContract {
Exact,
FloatTolerant,
}
impl StatisticalAggregateToleranceContract {
pub const fn as_str(self) -> &'static str {
match self {
Self::Exact => "exact",
Self::FloatTolerant => "float_tolerant",
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum CapabilityEnvelopeStatus {
Admitted,
Rejected,
}
impl CapabilityEnvelopeStatus {
pub(crate) const fn as_str(self) -> &'static str {
match self {
Self::Admitted => "bounded",
Self::Rejected => "unsupported_bounded",
}
}
}
impl fmt::Display for CapabilityEnvelopeStatus {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(self.as_str())
}
}