Skip to content

Commit

Permalink
first successfull lazy run
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 committed Oct 3, 2020
1 parent 6382812 commit 3c07015
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 9 deletions.
26 changes: 26 additions & 0 deletions polars/src/chunked_array/comparison.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ fn cmp_chunked_array_to_num<T>(
where
T: PolarsNumericType,
{
// todo! no null path
ca.into_iter().map(cmp_fn).collect()
}

Expand Down Expand Up @@ -508,6 +509,31 @@ impl Not for BooleanChunked {
}
}

pub trait CompToSeries {
fn lt_series(&self, rhs: &Series) -> BooleanChunked {
unimplemented!()
}
}

impl<T> CompToSeries for ChunkedArray<T>
where
T: PolarsNumericType,
{
fn lt_series(&self, rhs: &Series) -> BooleanChunked {
match self.unpack_series_matching_type(rhs) {
Ok(ca) => self.lt(ca),
Err(_) => match rhs.cast::<T>() {
Ok(s) => self.lt_series(&s),
Err(e) => BooleanChunked::full("lt", false, self.len()),
},
}
}
}

impl CompToSeries for BooleanChunked {}
impl CompToSeries for Utf8Chunked {}
impl CompToSeries for LargeListChunked {}

#[cfg(test)]
mod test {
use super::super::{arithmetic::test::create_two_chunked, test::get_chunked_array};
Expand Down
17 changes: 12 additions & 5 deletions polars/src/lazy/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,28 @@ impl From<DataFrame> for DataStructure {
}

impl DataStructure {
fn series(self) -> Result<Series> {
pub fn series_ref(&self) -> Result<&Series> {
if let DataStructure::Series(series) = self {
Ok(series)
} else {
Err(PolarsError::DataTypeMisMatch)
}
}

fn df(self) -> Result<DataFrame> {
pub fn df_ref(&self) -> Result<&DataFrame> {
if let DataStructure::DataFrame(df) = self {
Ok(df)
Ok(&df)
} else {
Err(PolarsError::DataTypeMisMatch)
}
}

pub fn len(&self) -> usize {
match self {
DataStructure::Series(s) => s.len(),
DataStructure::DataFrame(df) => df.height(),
}
}
}

#[cfg(test)]
Expand All @@ -57,14 +64,14 @@ mod tests {
#[test]
fn plan_builder_simple() {
let logical_plan =
LogicalPlanBuilder::scan_csv("../../data/iris.csv".into(), None, true, None)
LogicalPlanBuilder::scan_csv("../data/iris.csv".into(), None, true, None)
.filter(col("sepal.length").lt(lit(5)))
.build();

println!("{:?}", logical_plan);

let planner = SimplePlanner {};
let physical_plan = planner.create_physical_plan(&logical_plan).unwrap();
println!("{:?}", physical_plan);
println!("{:?}", physical_plan.execute());
}
}
21 changes: 18 additions & 3 deletions polars/src/lazy/physical_plan/expressions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@ impl PhysicalExpr for LiteralExpr {
}

fn evaluate(&self, ds: &DataStructure) -> Result<Series> {
unimplemented!()
match &self.0 {
// todo! implement single value chunked_arrays? Or allow comparison and arithemtic with
// ca of a single value
ScalarValue::Int32(v) => Ok(Int32Chunked::full("literal", *v, ds.len()).into_series()),
sv => panic!(format!("ScalarValue {:?} is not implemented", sv)),
}
}
}

Expand All @@ -39,7 +44,15 @@ impl PhysicalExpr for BinaryExpr {
}

fn evaluate(&self, ds: &DataStructure) -> Result<Series> {
unimplemented!()
let left = self.left.evaluate(ds)?;
let right = self.right.evaluate(ds)?;
match self.op {
Operator::Lt => {
let a = apply_method_all_series!(left, lt_series, &right);
Ok(a.into_series())
}
op => panic!(format!("Operator {:?} is not implemented", op)),
}
}
}

Expand All @@ -58,6 +71,8 @@ impl PhysicalExpr for ColumnExpr {
}

fn evaluate(&self, ds: &DataStructure) -> Result<Series> {
unimplemented!()
let df = ds.df_ref()?;
let column = df.column(&self.0)?;
Ok(column.clone())
}
}
2 changes: 1 addition & 1 deletion polars/src/prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pub use crate::{
PrimitiveChunkedBuilder, Utf8ChunkedBuilder,
},
chunkops::ChunkOps,
comparison::NumComp,
comparison::{CompToSeries, NumComp},
iterator::{IntoNoNullIterator, NumericChunkIterDispatch},
ops::{
ChunkAgg, ChunkApply, ChunkCast, ChunkCompare, ChunkFillNone, ChunkFilter, ChunkFull,
Expand Down

0 comments on commit 3c07015

Please sign in to comment.