polars_plan/plans/
anonymous_scan.rs

1use std::any::Any;
2use std::fmt::{Debug, Formatter};
3
4use polars_core::prelude::*;
5
6use crate::dsl::Expr;
7
8pub struct AnonymousScanArgs {
9    pub n_rows: Option<usize>,
10    pub with_columns: Option<Arc<[PlSmallStr]>>,
11    pub schema: SchemaRef,
12    pub output_schema: Option<SchemaRef>,
13    pub predicate: Option<Expr>,
14}
15
16pub trait AnonymousScan: Send + Sync {
17    fn as_any(&self) -> &dyn Any;
18    /// Creates a DataFrame from the supplied function & scan options.
19    fn scan(&self, scan_opts: AnonymousScanArgs) -> PolarsResult<DataFrame>;
20
21    /// Produce the next batch Polars can consume. Implement this method to get proper
22    /// streaming support.
23    fn next_batch(&self, scan_opts: AnonymousScanArgs) -> PolarsResult<Option<DataFrame>> {
24        self.scan(scan_opts).map(Some)
25    }
26
27    /// function to supply the schema.
28    /// Allows for an optional infer schema argument for data sources with dynamic schemas
29    fn schema(&self, _infer_schema_length: Option<usize>) -> PolarsResult<SchemaRef> {
30        polars_bail!(ComputeError: "must supply either a schema or a schema function");
31    }
32    /// Specify if the scan provider should allow predicate pushdowns.
33    ///
34    /// Defaults to `false`
35    fn allows_predicate_pushdown(&self) -> bool {
36        false
37    }
38    /// Specify if the scan provider should allow projection pushdowns.
39    ///
40    /// Defaults to `false`
41    fn allows_projection_pushdown(&self) -> bool {
42        false
43    }
44    /// Specify if the scan provider should allow slice pushdowns.
45    ///
46    /// Defaults to `false`
47    fn allows_slice_pushdown(&self) -> bool {
48        false
49    }
50}
51
52impl Debug for dyn AnonymousScan {
53    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
54        write!(f, "anonymous_scan")
55    }
56}