use abi_stable::StableAbi;
use datafusion_common::DataFusionError;
use datafusion_expr::interval_arithmetic::Interval;
use crate::arrow_wrappers::WrappedArray;
#[repr(C)]
#[derive(Debug, StableAbi)]
pub struct FFI_Interval {
lower: WrappedArray,
upper: WrappedArray,
}
impl TryFrom<&Interval> for FFI_Interval {
type Error = DataFusionError;
fn try_from(value: &Interval) -> Result<Self, Self::Error> {
let upper = value.upper().try_into()?;
let lower = value.lower().try_into()?;
Ok(FFI_Interval { upper, lower })
}
}
impl TryFrom<Interval> for FFI_Interval {
type Error = DataFusionError;
fn try_from(value: Interval) -> Result<Self, Self::Error> {
FFI_Interval::try_from(&value)
}
}
impl TryFrom<FFI_Interval> for Interval {
type Error = DataFusionError;
fn try_from(value: FFI_Interval) -> Result<Self, Self::Error> {
let upper = value.upper.try_into()?;
let lower = value.lower.try_into()?;
Interval::try_new(lower, upper)
}
}