Skip to content

Commit

Permalink
refactor(rust): Move expression expansion to conversion module
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 committed May 20, 2024
1 parent f5c32f2 commit d6adfd6
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 18 deletions.
2 changes: 1 addition & 1 deletion crates/polars-plan/src/dsl/meta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::ops::BitAnd;

use super::*;
use crate::logical_plan::alp::tree_format::TreeFmtVisitor;
use crate::logical_plan::expr_expansion::is_regex_projection;
use crate::logical_plan::conversion::is_regex_projection;
use crate::logical_plan::visitor::{AexprNode, TreeWalker};

/// Specialized expressions for Categorical dtypes.
Expand Down
2 changes: 1 addition & 1 deletion crates/polars-plan/src/dsl/struct_.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::*;
use crate::logical_plan::expr_expansion::is_regex_projection;
use crate::logical_plan::conversion::is_regex_projection;

/// Specialized expressions for Struct dtypes.
pub struct StructNameSpace(pub(crate) Expr);
Expand Down
10 changes: 0 additions & 10 deletions crates/polars-plan/src/logical_plan/builder_dsl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,10 @@ use polars_io::HiveOptions;
use polars_io::RowIndex;

use crate::constants::UNLIMITED_CACHE;
use crate::logical_plan::expr_expansion::rewrite_projections;
#[cfg(feature = "python")]
use crate::prelude::python_udf::PythonFunction;
use crate::prelude::*;

pub(crate) fn prepare_projection(
exprs: Vec<Expr>,
schema: &Schema,
) -> PolarsResult<(Vec<Expr>, Schema)> {
let exprs = rewrite_projections(exprs, schema, &[])?;
let schema = expressions_to_schema(&exprs, schema, Context::Default)?;
Ok((exprs, schema))
}

pub struct DslBuilder(pub DslPlan);

impl From<DslPlan> for DslBuilder {
Expand Down
3 changes: 2 additions & 1 deletion crates/polars-plan/src/logical_plan/conversion/dsl_to_ir.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use expr_expansion::{is_regex_projection, rewrite_projections};

use super::stack_opt::ConversionOpt;
use super::*;
use crate::logical_plan::expr_expansion::{is_regex_projection, rewrite_projections};
use crate::logical_plan::projection_expr::ProjectionExprs;

fn expand_expressions(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
//! this contains code used for rewriting projections, expanding wildcards, regex selection etc.
use super::*;

pub(crate) fn prepare_projection(
exprs: Vec<Expr>,
schema: &Schema,
) -> PolarsResult<(Vec<Expr>, Schema)> {
let exprs = rewrite_projections(exprs, schema, &[])?;
let schema = expressions_to_schema(&exprs, schema, Context::Default)?;
Ok((exprs, schema))
}

/// This replaces the wildcard Expr with a Column Expr. It also removes the Exclude Expr from the
/// expression chain.
pub(super) fn replace_wildcard_with_column(expr: Expr, column_name: Arc<str>) -> Expr {
Expand Down
3 changes: 3 additions & 0 deletions crates/polars-plan/src/logical_plan/conversion/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
mod convert_utils;
mod dsl_to_ir;
mod expr_expansion;
mod expr_to_ir;
mod ir_to_dsl;
#[cfg(any(feature = "ipc", feature = "parquet", feature = "csv"))]
Expand All @@ -16,6 +17,8 @@ use polars_utils::vec::ConvertVec;
use recursive::recursive;
pub(crate) mod type_coercion;

pub(crate) use expr_expansion::{is_regex_projection, prepare_projection, rewrite_projections};

use crate::constants::get_len_name;
use crate::prelude::*;

Expand Down
2 changes: 1 addition & 1 deletion crates/polars-plan/src/logical_plan/functions/dsl.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::*;
use crate::logical_plan::expr_expansion::rewrite_projections;
use crate::logical_plan::conversion::rewrite_projections;

// Except for Opaque functions, this only has the DSL name of the function.
#[derive(Clone)]
Expand Down
5 changes: 1 addition & 4 deletions crates/polars-plan/src/logical_plan/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ use std::sync::Arc;
use polars_core::prelude::*;
use recursive::recursive;

use crate::logical_plan::DslPlan::DataFrameScan;
use crate::prelude::*;
use crate::utils::{expr_to_leaf_column_names, get_single_leaf};

pub(crate) mod aexpr;
pub(crate) mod alp;
Expand All @@ -20,7 +18,6 @@ mod builder_ir;
pub(crate) mod conversion;
#[cfg(feature = "debugging")]
pub(crate) mod debug;
pub(crate) mod expr_expansion;
pub mod expr_ir;
mod file_scan;
mod format;
Expand Down Expand Up @@ -206,7 +203,7 @@ impl Default for DslPlan {
fn default() -> Self {
let df = DataFrame::new::<Series>(vec![]).unwrap();
let schema = df.schema();
DataFrameScan {
DslPlan::DataFrameScan {
df: Arc::new(df),
schema: Arc::new(schema),
output_schema: None,
Expand Down

0 comments on commit d6adfd6

Please sign in to comment.