Skip to content

Commit

Permalink
refactor(rust!): Rename LogicalPlan and builders to reflect their use…
Browse files Browse the repository at this point in the history
…s better (#15712)
  • Loading branch information
ritchie46 authored Apr 17, 2024
1 parent 4c57688 commit e218203
Show file tree
Hide file tree
Showing 29 changed files with 1,141 additions and 1,133 deletions.
12 changes: 6 additions & 6 deletions crates/polars-lazy/src/dsl/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pub(crate) fn concat_impl<L: AsRef<[LazyFrame]>>(

let lf = match &mut lf.logical_plan {
// reuse the same union
LogicalPlan::Union {
DslPlan::Union {
inputs: existing_inputs,
options: opts,
} if opts == &options => {
Expand All @@ -56,7 +56,7 @@ pub(crate) fn concat_impl<L: AsRef<[LazyFrame]>>(
lps.push(lp)
}

let lp = LogicalPlan::Union {
let lp = DslPlan::Union {
inputs: lps,
options,
};
Expand All @@ -68,7 +68,7 @@ pub(crate) fn concat_impl<L: AsRef<[LazyFrame]>>(
};

if convert_supertypes {
let LogicalPlan::Union {
let DslPlan::Union {
mut inputs,
options,
} = lf.logical_plan
Expand All @@ -82,7 +82,7 @@ pub(crate) fn concat_impl<L: AsRef<[LazyFrame]>>(
changed |= schema.to_supertype(input.schema()?.as_ref().as_ref())?;
}

let mut placeholder = LogicalPlan::default();
let mut placeholder = DslPlan::default();
if changed {
let mut exprs = vec![];
for input in &mut inputs {
Expand All @@ -109,7 +109,7 @@ pub(crate) fn concat_impl<L: AsRef<[LazyFrame]>>(
std::mem::swap(&mut placeholder, input);
}
}
Ok(LazyFrame::from(LogicalPlan::Union { inputs, options }))
Ok(LazyFrame::from(DslPlan::Union { inputs, options }))
} else {
Ok(lf)
}
Expand Down Expand Up @@ -205,7 +205,7 @@ pub fn concat_lf_horizontal<L: AsRef<[LazyFrame]>>(
let options = HConcatOptions {
parallel: args.parallel,
};
let lp = LogicalPlan::HConcat {
let lp = DslPlan::HConcat {
inputs: lps,
schema: Arc::new(combined_schema),
options,
Expand Down
30 changes: 15 additions & 15 deletions crates/polars-lazy/src/frame/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ pub trait IntoLazy {
impl IntoLazy for DataFrame {
/// Convert the `DataFrame` into a `LazyFrame`
fn lazy(self) -> LazyFrame {
let lp = LogicalPlanBuilder::from_existing_df(self).build();
let lp = DslBuilder::from_existing_df(self).build();
LazyFrame {
logical_plan: lp,
opt_state: Default::default(),
Expand All @@ -70,12 +70,12 @@ impl IntoLazy for LazyFrame {
#[derive(Clone, Default)]
#[must_use]
pub struct LazyFrame {
pub logical_plan: LogicalPlan,
pub logical_plan: DslPlan,
pub(crate) opt_state: OptState,
}

impl From<LogicalPlan> for LazyFrame {
fn from(plan: LogicalPlan) -> Self {
impl From<DslPlan> for LazyFrame {
fn from(plan: DslPlan) -> Self {
Self {
logical_plan: plan,
opt_state: OptState {
Expand All @@ -96,15 +96,15 @@ impl LazyFrame {
self.logical_plan.schema().map(|schema| schema.into_owned())
}

pub(crate) fn get_plan_builder(self) -> LogicalPlanBuilder {
LogicalPlanBuilder::from(self.logical_plan)
pub(crate) fn get_plan_builder(self) -> DslBuilder {
DslBuilder::from(self.logical_plan)
}

fn get_opt_state(&self) -> OptState {
self.opt_state
}

fn from_logical_plan(logical_plan: LogicalPlan, opt_state: OptState) -> Self {
fn from_logical_plan(logical_plan: DslPlan, opt_state: OptState) -> Self {
LazyFrame {
logical_plan,
opt_state,
Expand Down Expand Up @@ -215,7 +215,7 @@ impl LazyFrame {
self.logical_plan.describe_tree_format()
}

fn optimized_plan(&self) -> PolarsResult<LogicalPlan> {
fn optimized_plan(&self) -> PolarsResult<DslPlan> {
let mut expr_arena = Arena::with_capacity(64);
let mut lp_arena = Arena::with_capacity(64);
let lp_top = self.clone().optimize_with_scratch(
Expand Down Expand Up @@ -749,7 +749,7 @@ impl LazyFrame {
ipc_options: IpcWriterOptions,
) -> PolarsResult<()> {
self.opt_state.streaming = true;
self.logical_plan = LogicalPlan::Sink {
self.logical_plan = DslPlan::Sink {
input: Arc::new(self.logical_plan),
payload: SinkType::Cloud {
uri: Arc::new(uri),
Expand Down Expand Up @@ -804,7 +804,7 @@ impl LazyFrame {
))]
fn sink(mut self, payload: SinkType, msg_alternative: &str) -> Result<(), PolarsError> {
self.opt_state.streaming = true;
self.logical_plan = LogicalPlan::Sink {
self.logical_plan = DslPlan::Sink {
input: Arc::new(self.logical_plan),
payload,
};
Expand Down Expand Up @@ -1671,7 +1671,7 @@ impl LazyFrame {
/// predicate pushdown optimization.
pub fn with_row_index(mut self, name: &str, offset: Option<IdxSize>) -> LazyFrame {
let add_row_index_in_map = match &mut self.logical_plan {
LogicalPlan::Scan {
DslPlan::Scan {
file_options: options,
file_info,
scan_type,
Expand Down Expand Up @@ -1741,7 +1741,7 @@ impl LazyFrame {
/// Utility struct for lazy group_by operation.
#[derive(Clone)]
pub struct LazyGroupBy {
pub logical_plan: LogicalPlan,
pub logical_plan: DslPlan,
opt_state: OptState,
keys: Vec<Expr>,
maintain_order: bool,
Expand Down Expand Up @@ -1785,7 +1785,7 @@ impl LazyGroupBy {
/// ```
pub fn agg<E: AsRef<[Expr]>>(self, aggs: E) -> LazyFrame {
#[cfg(feature = "dynamic_group_by")]
let lp = LogicalPlanBuilder::from(self.logical_plan)
let lp = DslBuilder::from(self.logical_plan)
.group_by(
self.keys,
aggs,
Expand All @@ -1797,7 +1797,7 @@ impl LazyGroupBy {
.build();

#[cfg(not(feature = "dynamic_group_by"))]
let lp = LogicalPlanBuilder::from(self.logical_plan)
let lp = DslBuilder::from(self.logical_plan)
.group_by(self.keys, aggs, None, self.maintain_order)
.build();
LazyFrame::from_logical_plan(lp, self.opt_state)
Expand Down Expand Up @@ -1845,7 +1845,7 @@ impl LazyGroupBy {
#[cfg(not(feature = "dynamic_group_by"))]
let options = GroupbyOptions { slice: None };

let lp = LogicalPlan::GroupBy {
let lp = DslPlan::GroupBy {
input: Arc::new(self.logical_plan),
keys: Arc::new(self.keys),
aggs: vec![],
Expand Down
2 changes: 1 addition & 1 deletion crates/polars-lazy/src/frame/python.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::prelude::*;

impl LazyFrame {
pub fn scan_from_python_function(schema: Schema, scan_fn: PyObject, pyarrow: bool) -> Self {
LogicalPlan::PythonScan {
DslPlan::PythonScan {
options: PythonOptions {
scan_fn: Some(scan_fn.into()),
schema: Arc::new(schema),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ fn get_pipeline_node(
lp_arena: &mut Arena<IR>,
mut pipelines: Vec<PipeLine>,
schema: SchemaRef,
original_lp: Option<LogicalPlan>,
original_lp: Option<DslPlan>,
) -> IR {
// create a dummy input as the map function will call the input
// so we just create a scan that returns an empty df
Expand Down
4 changes: 2 additions & 2 deletions crates/polars-lazy/src/prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ pub use polars_ops::prelude::{JoinArgs, JoinType, JoinValidation};
#[cfg(feature = "rank")]
pub use polars_ops::prelude::{RankMethod, RankOptions};
pub use polars_plan::logical_plan::{
AnonymousScan, AnonymousScanArgs, AnonymousScanOptions, Literal, LiteralValue, LogicalPlan,
Null, NULL,
AnonymousScan, AnonymousScanArgs, AnonymousScanOptions, DslPlan, Literal, LiteralValue, Null,
NULL,
};
#[cfg(feature = "csv")]
pub use polars_plan::prelude::CsvWriterOptions;
Expand Down
2 changes: 1 addition & 1 deletion crates/polars-lazy/src/scan/anonymous_scan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ impl LazyFrame {
function: Arc<dyn AnonymousScan>,
args: ScanArgsAnonymous,
) -> PolarsResult<Self> {
let mut lf: LazyFrame = LogicalPlanBuilder::anonymous_scan(
let mut lf: LazyFrame = DslBuilder::anonymous_scan(
function,
args.schema,
args.infer_schema_length,
Expand Down
2 changes: 1 addition & 1 deletion crates/polars-lazy/src/scan/csv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ impl<'a> LazyCsvReader<'a> {

impl LazyFileListReader for LazyCsvReader<'_> {
fn finish_no_glob(self) -> PolarsResult<LazyFrame> {
let mut lf: LazyFrame = LogicalPlanBuilder::scan_csv(
let mut lf: LazyFrame = DslBuilder::scan_csv(
self.path,
self.separator,
self.has_header,
Expand Down
2 changes: 1 addition & 1 deletion crates/polars-lazy/src/scan/ipc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ impl LazyFileListReader for LazyIpcReader {
memory_map: args.memory_map,
};

let mut lf: LazyFrame = LogicalPlanBuilder::scan_ipc(
let mut lf: LazyFrame = DslBuilder::scan_ipc(
paths,
options,
args.n_rows,
Expand Down
2 changes: 1 addition & 1 deletion crates/polars-lazy/src/scan/parquet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ impl LazyFileListReader for LazyParquetReader {
} else {
self.paths
};
let mut lf: LazyFrame = LogicalPlanBuilder::scan_parquet(
let mut lf: LazyFrame = DslBuilder::scan_parquet(
paths,
self.args.n_rows,
self.args.cache,
Expand Down
4 changes: 2 additions & 2 deletions crates/polars-lazy/src/tests/queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ fn test_simplify_expr() {
.unwrap();
let plan = node_to_lp(lp_top, &expr_arena, &mut lp_arena);
assert!(
matches!(plan, LogicalPlan::Select{ expr, ..} if matches!(&expr[0], Expr::BinaryExpr{left, ..} if **left == Expr::Literal(LiteralValue::Float32(2.0))))
matches!(plan, DslPlan::Select{ expr, ..} if matches!(&expr[0], Expr::BinaryExpr{left, ..} if **left == Expr::Literal(LiteralValue::Float32(2.0))))
);
}

Expand Down Expand Up @@ -649,7 +649,7 @@ fn test_type_coercion() {
.unwrap();
let lp = node_to_lp(lp_top, &expr_arena, &mut lp_arena);

if let LogicalPlan::Select { expr, .. } = lp {
if let DslPlan::Select { expr, .. } = lp {
if let Expr::BinaryExpr { left, right, .. } = &expr[0] {
assert!(matches!(&**left, Expr::Cast { .. }));
// bar is already float, does not have to be coerced
Expand Down
4 changes: 2 additions & 2 deletions crates/polars-plan/src/dot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ pub struct DotNode<'a> {
pub fmt: &'a str,
}

impl LogicalPlan {
impl DslPlan {
fn write_single_node(&self, acc_str: &mut String, node: DotNode) -> std::fmt::Result {
let fmt_node = node.fmt.replace('"', r#"\""#);
writeln!(acc_str, "graph polars_query {{\n\"[{fmt_node}]\"")?;
Expand Down Expand Up @@ -128,7 +128,7 @@ impl LogicalPlan {
prev_node: DotNode,
id_map: &mut PlHashMap<String, String>,
) -> std::fmt::Result {
use LogicalPlan::*;
use DslPlan::*;
let (mut branch, id) = id;

match self {
Expand Down
2 changes: 1 addition & 1 deletion crates/polars-plan/src/dsl/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ pub enum Expr {
output_type: GetOutput,
options: FunctionOptions,
},
SubPlan(SpecialEq<Arc<LogicalPlan>>, Vec<String>),
SubPlan(SpecialEq<Arc<DslPlan>>, Vec<String>),
/// Expressions in this node should only be expanding
/// e.g.
/// `Expr::Columns`
Expand Down
6 changes: 3 additions & 3 deletions crates/polars-plan/src/dsl/expr_dyn_fn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ impl<'a> Deserialize<'a> for SpecialEq<Series> {
}

#[cfg(feature = "serde")]
impl Serialize for SpecialEq<Arc<LogicalPlan>> {
impl Serialize for SpecialEq<Arc<DslPlan>> {
fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
where
S: Serializer,
Expand All @@ -177,12 +177,12 @@ impl Serialize for SpecialEq<Arc<LogicalPlan>> {
}

#[cfg(feature = "serde")]
impl<'a> Deserialize<'a> for SpecialEq<Arc<LogicalPlan>> {
impl<'a> Deserialize<'a> for SpecialEq<Arc<DslPlan>> {
fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
where
D: Deserializer<'a>,
{
let t = LogicalPlan::deserialize(deserializer)?;
let t = DslPlan::deserialize(deserializer)?;
Ok(SpecialEq(Arc::new(t)))
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/polars-plan/src/logical_plan/alp/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use polars_utils::unitvec;
use super::projection_expr::*;
use crate::prelude::*;

/// [`IR`] is a representation of [`LogicalPlan`] with [`Node`]s which are allocated in an [`Arena`]
/// [`IR`] is a representation of [`DslPlan`] with [`Node`]s which are allocated in an [`Arena`]
/// In this IR the logical plan has access to the full dataset.
#[derive(Clone, Debug, Default)]
pub enum IR {
Expand Down
Loading

0 comments on commit e218203

Please sign in to comment.