Skip to main content

polars_io/external_reader/
mod.rs

1use polars_error::PolarsResult;
2use polars_utils::aliases::PlIndexMap;
3
4#[cfg(feature = "io_plugin_ffi")]
5pub mod ffi;
6#[cfg(feature = "python")]
7pub mod python;
8
9#[derive(Debug, Clone, PartialEq, Eq, Hash)]
10#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
11#[cfg_attr(feature = "dsl-schema", derive(schemars::JsonSchema))]
12pub enum ExternalReaderBuilder {
13    #[cfg(feature = "python")]
14    Python(python::PythonFileReaderBuilder),
15    /// A reader of an I/O plugin, called through `polars.io_plugin.file_reader.v1`.
16    #[cfg(feature = "io_plugin_ffi")]
17    #[cfg_attr(feature = "dsl-schema", schemars(skip))]
18    Ffi(ffi::FfiFileReaderBuilder),
19    /// Unimplemented. Placeholder to avoid empty enum when Python feature is
20    /// disabled.
21    Rust(()),
22}
23
24impl ExternalReaderBuilder {
25    pub fn explain_properties(&self) -> PolarsResult<PlIndexMap<String, String>> {
26        match self {
27            #[cfg(feature = "python")]
28            ExternalReaderBuilder::Python(x) => x.explain_properties(),
29            #[cfg(feature = "io_plugin_ffi")]
30            ExternalReaderBuilder::Ffi(x) => x.explain_properties(),
31            ExternalReaderBuilder::Rust(()) => unimplemented!(),
32        }
33    }
34
35    /// Whether a negative slice may be resolved from the row counts of the sources. An I/O
36    /// plugin counts with a statement of its own, so the rows may change before they are read.
37    pub fn counts_match_reads(&self) -> bool {
38        match self {
39            #[cfg(feature = "io_plugin_ffi")]
40            ExternalReaderBuilder::Ffi(_) => false,
41            _ => true,
42        }
43    }
44}