-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
All physical expressions are in a separate file.
- Loading branch information
Showing
20 changed files
with
1,052 additions
and
958 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
use crate::physical_plan::state::ExecutionState; | ||
use crate::prelude::*; | ||
use polars_core::frame::groupby::GroupTuples; | ||
use polars_core::prelude::*; | ||
use std::sync::Arc; | ||
|
||
pub struct AliasExpr { | ||
pub(crate) physical_expr: Arc<dyn PhysicalExpr>, | ||
pub(crate) name: Arc<String>, | ||
expr: Expr, | ||
} | ||
|
||
impl AliasExpr { | ||
pub fn new(physical_expr: Arc<dyn PhysicalExpr>, name: Arc<String>, expr: Expr) -> Self { | ||
Self { | ||
physical_expr, | ||
name, | ||
expr, | ||
} | ||
} | ||
} | ||
|
||
impl PhysicalExpr for AliasExpr { | ||
fn as_expression(&self) -> &Expr { | ||
&self.expr | ||
} | ||
|
||
fn evaluate(&self, df: &DataFrame, state: &ExecutionState) -> Result<Series> { | ||
let mut series = self.physical_expr.evaluate(df, state)?; | ||
series.rename(&self.name); | ||
Ok(series) | ||
} | ||
|
||
fn to_field(&self, input_schema: &Schema) -> Result<Field> { | ||
Ok(Field::new( | ||
&self.name, | ||
self.physical_expr | ||
.to_field(input_schema)? | ||
.data_type() | ||
.clone(), | ||
)) | ||
} | ||
|
||
fn as_agg_expr(&self) -> Result<&dyn PhysicalAggregation> { | ||
Ok(self) | ||
} | ||
} | ||
|
||
impl PhysicalAggregation for AliasExpr { | ||
fn aggregate( | ||
&self, | ||
df: &DataFrame, | ||
groups: &GroupTuples, | ||
state: &ExecutionState, | ||
) -> Result<Option<Series>> { | ||
let agg_expr = self.physical_expr.as_agg_expr()?; | ||
let opt_agg = agg_expr.aggregate(df, groups, state)?; | ||
Ok(opt_agg.map(|mut agg| { | ||
agg.rename(&self.name); | ||
agg | ||
})) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
use crate::physical_plan::state::ExecutionState; | ||
use crate::physical_plan::PhysicalAggregation; | ||
use crate::prelude::*; | ||
use polars_core::prelude::*; | ||
use std::sync::Arc; | ||
|
||
pub struct ApplyExpr { | ||
pub input: Arc<dyn PhysicalExpr>, | ||
pub function: NoEq<Arc<dyn SeriesUdf>>, | ||
pub output_type: Option<DataType>, | ||
pub expr: Expr, | ||
} | ||
|
||
impl ApplyExpr { | ||
pub fn new( | ||
input: Arc<dyn PhysicalExpr>, | ||
function: NoEq<Arc<dyn SeriesUdf>>, | ||
output_type: Option<DataType>, | ||
expr: Expr, | ||
) -> Self { | ||
ApplyExpr { | ||
input, | ||
function, | ||
output_type, | ||
expr, | ||
} | ||
} | ||
} | ||
|
||
impl PhysicalExpr for ApplyExpr { | ||
fn as_expression(&self) -> &Expr { | ||
&self.expr | ||
} | ||
|
||
fn evaluate(&self, df: &DataFrame, state: &ExecutionState) -> Result<Series> { | ||
let input = self.input.evaluate(df, state)?; | ||
let in_name = input.name().to_string(); | ||
let mut out = self.function.call_udf(input)?; | ||
if in_name != out.name() { | ||
out.rename(&in_name); | ||
} | ||
Ok(out) | ||
} | ||
fn to_field(&self, input_schema: &Schema) -> Result<Field> { | ||
match &self.output_type { | ||
Some(output_type) => { | ||
let input_field = self.input.to_field(input_schema)?; | ||
Ok(Field::new(input_field.name(), output_type.clone())) | ||
} | ||
None => self.input.to_field(input_schema), | ||
} | ||
} | ||
fn as_agg_expr(&self) -> Result<&dyn PhysicalAggregation> { | ||
Ok(self) | ||
} | ||
} |
Oops, something went wrong.