Path: blob/main/crates/polars-plan/src/plans/anonymous_scan.rs
6940 views
use std::any::Any;1use std::fmt::{Debug, Formatter};23use polars_core::prelude::*;45use crate::dsl::Expr;67pub struct AnonymousScanArgs {8pub n_rows: Option<usize>,9pub with_columns: Option<Arc<[PlSmallStr]>>,10pub schema: SchemaRef,11pub output_schema: Option<SchemaRef>,12pub predicate: Option<Expr>,13}1415pub trait AnonymousScan: Send + Sync {16fn as_any(&self) -> &dyn Any;17/// Creates a DataFrame from the supplied function & scan options.18fn scan(&self, scan_opts: AnonymousScanArgs) -> PolarsResult<DataFrame>;1920/// Produce the next batch Polars can consume. Implement this method to get proper21/// streaming support.22fn next_batch(&self, scan_opts: AnonymousScanArgs) -> PolarsResult<Option<DataFrame>> {23self.scan(scan_opts).map(Some)24}2526/// function to supply the schema.27/// Allows for an optional infer schema argument for data sources with dynamic schemas28fn schema(&self, _infer_schema_length: Option<usize>) -> PolarsResult<SchemaRef> {29polars_bail!(ComputeError: "must supply either a schema or a schema function");30}31/// Specify if the scan provider should allow predicate pushdowns.32///33/// Defaults to `false`34fn allows_predicate_pushdown(&self) -> bool {35false36}37/// Specify if the scan provider should allow projection pushdowns.38///39/// Defaults to `false`40fn allows_projection_pushdown(&self) -> bool {41false42}43/// Specify if the scan provider should allow slice pushdowns.44///45/// Defaults to `false`46fn allows_slice_pushdown(&self) -> bool {47false48}49}5051impl Debug for dyn AnonymousScan {52fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {53write!(f, "anonymous_scan")54}55}565758