vortex_datafusion/
lib.rs

1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright the Vortex contributors
3
4//! Connectors to enable [DataFusion](https://docs.rs/datafusion/latest/datafusion/) to read [`Vortex`](https://docs.rs/crate/vortex/latest) data.
5#![deny(missing_docs)]
6use std::fmt::Debug;
7
8use datafusion_common::stats::Precision as DFPrecision;
9use vortex::expr::stats::Precision;
10
11mod convert;
12mod persistent;
13pub mod vendor;
14
15pub use convert::exprs::ExpressionConvertor;
16pub use persistent::*;
17
18/// Extension trait to convert our [`Precision`](vortex::stats::Precision) to Datafusion's [`Precision`](datafusion_common::stats::Precision)
19trait PrecisionExt<T>
20where
21    T: Debug + Clone + PartialEq + Eq + PartialOrd,
22{
23    /// Convert `Precision` to the datafusion equivalent.
24    fn to_df(self) -> DFPrecision<T>;
25}
26
27impl<T> PrecisionExt<T> for Precision<T>
28where
29    T: Debug + Clone + PartialEq + Eq + PartialOrd,
30{
31    fn to_df(self) -> DFPrecision<T> {
32        match self {
33            Precision::Exact(v) => DFPrecision::Exact(v),
34            Precision::Inexact(v) => DFPrecision::Inexact(v),
35        }
36    }
37}
38
39impl<T> PrecisionExt<T> for Option<Precision<T>>
40where
41    T: Debug + Clone + PartialEq + Eq + PartialOrd,
42{
43    fn to_df(self) -> DFPrecision<T> {
44        match self {
45            Some(v) => v.to_df(),
46            None => DFPrecision::Absent,
47        }
48    }
49}